org.apache.directory.api.ldap.model.message.CompareResponse Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.message.CompareResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method uses the compare ldap func to assert audit record into the directory server's configured audit
 * logger.
 *
 * This is for one reason - to force the ldap server to maintain an audit trail on checkAccess api.
 *
 * Use proxy authz control (RFC4370) to assert the caller's id onto the record.
 *
 * @param connection is LdapConnection object used for all communication with host.
 * @param dn         contains address of distinguished name to begin ldap search
 * @param userDn     dn for user node
 * @param attribute  attribute used for compare
 * @return true if compare operation succeeds
 * @throws LdapException                thrown in the event of error in ldap client or server code.
 * @throws UnsupportedEncodingException in the event the server cannot perform the operation.
 */
protected boolean compareNode( LdapConnection connection, String dn, String userDn,
    Attribute attribute ) throws LdapException, UnsupportedEncodingException
{
    COUNTERS.incrementCompare();

    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( new Dn( dn ) );
    compareRequest.setAttributeId( attribute.getId() );
    compareRequest.setAssertionValue( attribute.getString() );

    // Assert the end user's dn onto the reqest using proxy authZ control so openldap can log who the user was (for authZ audit trail)
    ProxiedAuthz proxiedAuthzControl = new ProxiedAuthzImpl();
    proxiedAuthzControl.setAuthzId( "dn: " + userDn );
    compareRequest.addControl( proxiedAuthzControl );
    CompareResponse response = connection.compare( compareRequest );
    return response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS;
}
 
Example #2
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a Response with the (optional) requestID attribute
 */
@Test
public void testResponseWithRequestId()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( 456, compareResponse.getMessageId() );
}
 
Example #3
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a CompareResponse with no LdapResult
 */
@Test
public void testDecodeCompareResponseEmptyResult() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

    stream.put( new byte[]
        {
            0x30, 0x05,             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x6F, 0x00            // CHOICE { ..., compareResponse CompareResponse,
                                    // ...
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<CompareResponse> container = new LdapMessageContainer<>( codec );

    // Decode a CompareResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #4
Source File: InitCompareResponse.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<CompareResponse> container ) throws DecoderException
{
    // Now, we can allocate the CompareResponse Object
    CompareResponse compareResponse = new CompareResponseImpl( container.getMessageId() );
    container.setMessage( compareResponse );

    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();

    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05148_NULL_COMPARE_REQUEST );
        LOG.error( msg );
        throw new DecoderException( msg );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05169_COMPARE_RESPONSE ) );
    }
}
 
Example #5
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, Value value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );

    if ( value.isHumanReadable() )
    {
        compareRequest.setAssertionValue( value.getString() );
    }
    else
    {
        compareRequest.setAssertionValue( value.getBytes() );
    }

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #6
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = compareResponse.getLdapResult();

    assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
}
 
Example #7
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with Error Message
 */
@Test
public void testResponseWithErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = compareResponse.getLdapResult();

    assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
        .getDiagnosticMessage() );
}
 
Example #8
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with empty Error Message
 */
@Test
public void testResponseWithEmptyErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_empty_error_message.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = compareResponse.getLdapResult();

    assertNull( ldapResult.getDiagnosticMessage() );
}
 
Example #9
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with MatchedDN attribute
 */
@Test
public void testResponseWithMatchedDNAttribute()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = compareResponse.getLdapResult();

    assertTrue( ldapResult.getMatchedDn().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );
}
 
Example #10
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Process the CompareResponse received from the server
 * 
 * @param compareResponse The CompareResponse to process
 * @param compareFuture The CompareFuture to feed
 * @param responseId The associated request message ID
 * @throws InterruptedException If the Future is interrupted
 */
private void compareReceived( CompareResponse compareResponse, CompareFuture compareFuture, int responseId ) 
   throws InterruptedException
{
    // remove the listener from the listener map
    if ( LOG.isDebugEnabled() )
    {
        if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
        {
            // Everything is fine, return the response
            LOG.debug( I18n.msg( I18n.MSG_04114_COMPARE_SUCCESSFUL, compareResponse ) );
        }
        else
        {
            // We have had an error
            LOG.debug( I18n.msg( I18n.MSG_04113_COMPARE_FAILED, compareResponse ) );
        }
    }

    // Store the response into the future
    compareFuture.set( compareResponse );

    // Remove the future from the map
    removeFromFutureMaps( responseId );
}
 
Example #11
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 1 CompareResponse
 */
@Test
public void testResponseWith1CompareResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_1_CompareResponse.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 1, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof CompareResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #12
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param compareRequestHandler The CompareRequest message received handler
 * @param compareResponseHandler The CompareResponse message sent handler
 */
public void setCompareHandlers( LdapRequestHandler<CompareRequest> compareRequestHandler,
    LdapResponseHandler<CompareResponse> compareResponseHandler )
{
    handler.removeReceivedMessageHandler( CompareRequest.class );
    this.compareRequestHandler = compareRequestHandler;
    this.compareRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareRequestHandler );

    handler.removeReceivedMessageHandler( CompareResponse.class );
    this.compareResponseHandler = compareResponseHandler;
    this.compareResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( CompareResponse.class, this.compareResponseHandler );
}
 
Example #13
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param compareRequestHandler The CompareRequest message received handler
 * @param compareResponseHandler The CompareResponse message sent handler
 */
public void setCompareHandlers( LdapRequestHandler<CompareRequest> compareRequestHandler,
    LdapResponseHandler<CompareResponse> compareResponseHandler )
{
    handler.removeReceivedMessageHandler( CompareRequest.class );
    this.compareRequestHandler = compareRequestHandler;
    this.compareRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareRequestHandler );

    handler.removeReceivedMessageHandler( CompareResponse.class );
    this.compareResponseHandler = compareResponseHandler;
    this.compareResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( CompareResponse.class, this.compareResponseHandler );
}
 
Example #14
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, byte[] value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #15
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( Dn dn, String attributeName, String value ) throws LdapException
{
    CompareRequest compareRequest = new CompareRequestImpl();
    compareRequest.setName( dn );
    compareRequest.setAttributeId( attributeName );
    compareRequest.setAssertionValue( value );

    CompareResponse compareResponse = compare( compareRequest );

    return processResponse( compareResponse );
}
 
Example #16
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with an empty Referral
 */
@Test
public void testResponseWith1EmptyReferral()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput(
            CompareResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = compareResponse.getLdapResult();

    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();

    assertEquals( 0, referrals.size() );
}
 
Example #17
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 3 (optional) Control elements without value
 */
@Test
public void testResponseWith3ControlsWithoutValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = compareResponse.getControls();

    assertEquals( 3, compareResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #18
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 2 (optional) Control elements
 */
@Test
public void testResponseWith2Controls()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = compareResponse.getControls();

    assertEquals( 2, compareResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #19
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element with empty value
 */
@Test
public void testResponseWith1ControlEmptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = compareResponse.getControls();

    assertEquals( 1, compareResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example #20
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( CompareResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = compareResponse.getControls();

    assertEquals( 1, compareResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.643" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.643", control.getOid() );
    assertEquals( "Some text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example #21
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 2 CompareResponse
 */
@Test
public void testResponseWith2CompareResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_2_CompareResponse.xml" ).openStream(),
            "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 2, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof CompareResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #22
Source File: LdapConnectionWrapper.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
{
    return connection.compare( compareRequest );
}
 
Example #23
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CompareResponse compare( CompareRequest compareRequest ) throws LdapException
{
    if ( compareRequest == null )
    {
        String msg = I18n.err( I18n.ERR_04151_CANNOT_PROCESS_NULL_COMP_REQ );

        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    CompareFuture compareFuture = compareAsync( compareRequest );

    // Get the result from the future
    try
    {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        CompareResponse compareResponse = compareFuture.get( timeout, TimeUnit.MILLISECONDS );

        if ( compareResponse == null )
        {
            // We didn't received anything : this is an error
            if ( LOG.isErrorEnabled() )
            {
                LOG.error( I18n.err( I18n.ERR_04112_OP_FAILED_TIMEOUT, "Compare" ) );
            }
            
            throw new LdapException( TIME_OUT_ERROR );
        }

        if ( compareResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
        {
            // Everything is fine, return the response
            if ( LOG.isDebugEnabled() )
            { 
                LOG.debug( I18n.msg( I18n.MSG_04114_COMPARE_SUCCESSFUL, compareResponse ) );
            }
        }
        else
        {
            // We have had an error
            if ( LOG.isDebugEnabled() )
            { 
                LOG.debug( I18n.msg( I18n.MSG_04113_COMPARE_FAILED, compareResponse ) );
            }
        }

        return compareResponse;
    }
    catch ( Exception ie )
    {
        // Catch all other exceptions
        LOG.error( NO_RESPONSE_ERROR, ie );

        // Send an abandon request
        if ( !compareFuture.isCancelled() )
        {
            abandon( compareRequest.getMessageId() );
        }

        throw new LdapException( NO_RESPONSE_ERROR, ie );
    }
}
 
Example #24
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a CompareResponse
 */
@Test
public void testDecodeCompareResponseSuccess() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0E );

    stream.put( new byte[]
        {
            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x6F, 0x07,               // CHOICE { ..., compareResponse CompareResponse,
                                        // ...
                                        // CompareResponse ::= [APPLICATION 15] LDAPResult
                0x0A, 0x01, 0x00,       // LDAPResult ::= SEQUENCE {
                                        // resultCode ENUMERATED {
                                        // success (0), ...
                                        // },
                0x04, 0x00,             // matchedDN LDAPDN,
                0x04, 0x00              // errorMessage LDAPString,
                                        // referral [3] Referral OPTIONAL }
                                        // }
    } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<CompareResponse> container = new LdapMessageContainer<>( codec );

    // Decode the CompareResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded CompareResponse PDU
    CompareResponse compareResponse = container.getMessage();

    assertEquals( 1, compareResponse.getMessageId() );
    assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode() );
    assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", compareResponse.getLdapResult().getDiagnosticMessage() );

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, compareResponse );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #25
Source File: CompareResponseTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a CompareResponse with controls
 */
@Test
public void testDecodeCompareResponseSuccessWithControls() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x32 );

    stream.put( new byte[]
        {
            0x30, 0x30,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x6F, 0x07,               // CHOICE { ..., compareResponse CompareResponse,
                                        // ...
                                        // CompareResponse ::= [APPLICATION 15] LDAPResult
                0x0A, 0x01, 0x00,       // LDAPResult ::= SEQUENCE {
                                        // resultCode ENUMERATED {
                                        // success (0), ...
                                        // },
                0x04, 0x00,             // matchedDN LDAPDN,
                0x04, 0x00,             // errorMessage LDAPString,
                                        // referral [3] Referral OPTIONAL }
                                        // }
              ( byte ) 0xA0, 0x22,      // A control
                0x30, 0x20,
                  0x04, 0x17,
                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '7',
                  0x04, 0x05,           // Control value
                    0x30, 0x03,         // EntryChangeNotification ::= SEQUENCE {
                      0x0A, 0x01, 0x01  //     changeType ENUMERATED {
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<CompareResponse> container = new LdapMessageContainer<>( codec );

    // Decode the CompareResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded CompareResponse PDU
    CompareResponse compareResponse = container.getMessage();

    assertEquals( 1, compareResponse.getMessageId() );
    assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode() );
    assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", compareResponse.getLdapResult().getDiagnosticMessage() );

    // Check the Control
    Map<String, Control> controls = compareResponse.getControls();

    assertEquals( 1, controls.size() );

    Control control = controls.get( "2.16.840.1.113730.3.4.7" );
    assertEquals( "2.16.840.1.113730.3.4.7", control.getOid() );
    assertTrue( control instanceof  EntryChange);

    // Check the encoding
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, compareResponse );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
 
Example #26
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @return The MessageSent handler for the CompareResponse
 */
public LdapResponseHandler<CompareResponse> getCompareResponseHandler()
{
    return compareResponseHandler;
}
 
Example #27
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @return The MessageSent handler for the CompareResponse
 */
public LdapResponseHandler<CompareResponse> getCompareResponseHandler()
{
    return compareResponseHandler;
}
 
Example #28
Source File: LdapConnection.java    From directory-ldap-api with Apache License 2.0 2 votes vote down vote up
/**
 * Compares an entry's attribute's value with that of the given value.
 *
 * @param compareRequest the compare request which contains the target distinguished name, 
 * attribute name and value
 * @return compare operation's response
 * @throws LdapException if some error occurred
 */
CompareResponse compare( CompareRequest compareRequest ) throws LdapException;
 
Example #29
Source File: CompareResponseDsml.java    From directory-ldap-api with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new getDecoratedMessage() of CompareResponseDsml.
 *
 * @param codec The LDAP Service to use
 * @param ldapMessage the message to decorate
 */
public CompareResponseDsml( LdapApiService codec, CompareResponse ldapMessage )
{
    super( codec, ldapMessage );
}