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

The following examples show how to use org.apache.directory.api.ldap.model.message.BindResponse. 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: AuthResponseTest.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(
            AuthResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).openStream(), "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = bindResponse.getLdapResult();

    assertTrue( ldapResult.getMatchedDn().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );
}
 
Example #2
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void bind() throws LdapException
{
    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg(  I18n.MSG_04112_BIND ) );
    }

    // Create the BindRequest
    BindRequest bindRequest = createBindRequest( config.getName(), Strings.getBytesUtf8( config.getCredentials() ) );

    BindResponse bindResponse = bind( bindRequest );

    processResponse( bindResponse );
}
 
Example #3
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void anonymousBind() throws LdapException
{
    if ( LOG.isDebugEnabled() )
    { 
        LOG.debug( I18n.msg( I18n.MSG_04109_ANONYMOUS_BIND ) );
    }

    // Create the BindRequest
    BindRequest bindRequest = createBindRequest( StringConstants.EMPTY, Strings.EMPTY_BYTES );

    BindResponse bindResponse = bind( bindRequest );

    processResponse( bindResponse );
}
 
Example #4
Source File: BindResponseFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the BindResponse message to a PDU.
 * <br>
 * BindResponse :
 * <pre>
 * 0x61 L1
 *  |
 *  +--&gt; LdapResult
 * [+--0x87 LL serverSaslCreds]
 * </pre>
 *
 * @param codec The LdapApiService instance
 * @param buffer The buffer where to put the PDU
 * @param message the BindResponse to encode
 */
@Override
public void encodeReverse( LdapApiService codec, Asn1Buffer buffer, Message message )
{
    int start = buffer.getPos();
    BindResponse bindResponse = ( ( BindResponse ) message );

    // The serverSASL creds, if any
    byte[] serverSaslCreds = bindResponse.getServerSaslCreds();

    if ( serverSaslCreds != null )
    {
        BerValue.encodeOctetString( buffer, ( byte ) LdapCodecConstants.SERVER_SASL_CREDENTIAL_TAG,
            serverSaslCreds );
    }

    // The LDAPResult part
    encodeLdapResultReverse( buffer, bindResponse.getLdapResult() );

    // The BindResponse Tag
    BerValue.encodeSequence( buffer, LdapCodecConstants.BIND_RESPONSE_TAG, start );
}
 
Example #5
Source File: BindResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a BindResponse with no LdapResult
 */
@Test
public void testDecodeAddResponseEmptyResult() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

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

    stream.flip();

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

    // Decode a BindResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #6
Source File: AuthResponseTest.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(
            AuthResponseTest.class.getResource( "response_with_empty_error_message.xml" ).openStream(), "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = bindResponse.getLdapResult();

    assertNull( ldapResult.getDiagnosticMessage() );
}
 
Example #7
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(),
            "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = bindResponse.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: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(),
            "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = bindResponse.getLdapResult();

    assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
}
 
Example #9
Source File: BindRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Send a SUCCESS message back to the client.
 */
private void sendBindSuccess(LdapSession ldapSession, BindRequest bindRequest, byte[] tokenBytes) {
    // Return the successful response
    BindResponse response = (BindResponse) bindRequest.getResultResponse();
    response.getLdapResult().setResultCode(ResultCodeEnum.SUCCESS);
    response.setServerSaslCreds(tokenBytes);

    if (!ldapSession.getCoreSession().isAnonymous()) {
        // If we have not been asked to authenticate as Anonymous, authenticate the user
        ldapSession.setAuthenticated();
    } else {
        // Otherwise, switch back to Anonymous
        ldapSession.setAnonymous();
    }

    // Clean the SaslProperties, we don't need them anymore
    MechanismHandler handler = (MechanismHandler) ldapSession.getSaslProperty(SaslConstants.SASL_MECH_HANDLER);

    if (handler != null) {
        handler.cleanup(ldapSession);
    }

    ldapSession.getIoSession().write(response);

    LOG.debug("Returned SUCCESS message: {}.", response);
}
 
Example #10
Source File: AuthResponseTest.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(
            AuthResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).openStream(), "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( 456, bindResponse.getMessageId() );
}
 
Example #11
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 bindRequestHandler The BindRequest message received handler
 * @param bindResponseHandler The BindResponse message sent handler
 */
public void setBindHandlers( LdapRequestHandler<BindRequest> bindRequestHandler,
    LdapResponseHandler<BindResponse> bindResponseHandler )
{
    handler.removeReceivedMessageHandler( BindRequest.class );
    this.bindRequestHandler = bindRequestHandler;
    this.bindRequestHandler.setLdapServer( this );
    handler.addReceivedMessageHandler( BindRequest.class, this.bindRequestHandler );

    handler.removeSentMessageHandler( BindResponse.class );
    this.bindResponseHandler = bindResponseHandler;
    this.bindResponseHandler.setLdapServer( this );
    handler.addSentMessageHandler( BindResponse.class, this.bindResponseHandler );
}
 
Example #12
Source File: BindRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Send a SUCCESS message back to the client.
 */
private void sendBindSuccess( LdapSession ldapSession, BindRequest bindRequest, byte[] tokenBytes )
{
    // Return the successful response
    BindResponse response = bindRequest.getResultResponse();
    response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
    response.setServerSaslCreds( tokenBytes );

    if ( !ldapSession.getCoreSession().isAnonymous() )
    {
        // If we have not been asked to authenticate as Anonymous, authenticate the user
        ldapSession.setAuthenticated();
    }
    else
    {
        // Otherwise, switch back to Anonymous
        ldapSession.setAnonymous();
    }

    // Clean the SaslProperties, we don't need them anymore
    MechanismHandler handler = ( MechanismHandler ) ldapSession.getSaslProperty( SaslConstants.SASL_MECH_HANDLER );

    if ( handler != null )
    {
        handler.cleanup( ldapSession );
    }

    ldapSession.getIoSession().write( response );

    LOG.debug( "Returned SUCCESS message: {}.", response );
}
 
Example #13
Source File: LdapDataProvider.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * Calls the PoolMgr to perform an LDAP bind for a user/password combination.  This function is valid
 * if and only if the user entity is a member of the USERS data set.
 *
 * @param connection connection to ldap server.
 * @param szUserDn   contains the LDAP dn to the user entry in String format.
 * @param password   contains the password in clear text.
 * @return bindResponse contains the result of the operation.
 * @throws LdapException in the event of LDAP error.
 */
protected BindResponse bind( LdapConnection connection, String szUserDn, String password ) throws LdapException
{
    COUNTERS.incrementBind();
    Dn userDn = new Dn( szUserDn );
    BindRequest bindReq = new BindRequestImpl();
    bindReq.setDn( userDn );
    bindReq.setCredentials( password );
    bindReq.addControl( PP_REQ_CTRL );
    return connection.bind( bindReq );
}
 
Example #14
Source File: StoreServerSASLCreds.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<BindResponse> container )
{
    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();

    // We have to handle the special case of a 0 length server
    // sasl credentials
    byte[] serverSaslCreds;

    if ( tlv.getLength() == 0 )
    {
        serverSaslCreds = Strings.EMPTY_BYTES;
    }
    else
    {
        serverSaslCreds = tlv.getValue().getData();
    }

    BindResponse response = container.getMessage();
    response.setServerSaslCreds( serverSaslCreds );

    // We can have an END transition
    container.setGrammarEndAllowed( true );

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05168_SASL_CREDENTIALS_VALUE_STORED ) );
    }
}
 
Example #15
Source File: InitBindResponse.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<BindResponse> container )
{
    // Now, we can allocate the BindResponse Object
    BindResponse bindResponse = new BindResponseImpl( container.getMessageId() );
    container.setMessage( bindResponse );
}
 
Example #16
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 bindRequestHandler The BindRequest message received handler
 * @param bindResponseHandler The BindResponse message sent handler
 */
public void setBindHandlers( LdapRequestHandler<BindRequest> bindRequestHandler,
    LdapResponseHandler<BindResponse> bindResponseHandler )
{
    handler.removeReceivedMessageHandler( BindRequest.class );
    this.bindRequestHandler = bindRequestHandler;
    this.bindRequestHandler.setLdapServer( this );
    handler.addReceivedMessageHandler( BindRequest.class, this.bindRequestHandler );

    handler.removeSentMessageHandler( BindResponse.class );
    this.bindResponseHandler = bindResponseHandler;
    this.bindResponseHandler.setLdapServer( this );
    handler.addSentMessageHandler( BindResponse.class, this.bindResponseHandler );
}
 
Example #17
Source File: ValidatingPoolableLdapConnectionFactoryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Override
public BindResponse bind( BindRequest bindRequest ) throws LdapException
{
    BindResponse response = connection.bind( bindRequest );
    bindCalled = true;
    return response;
}
 
Example #18
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Process the BindResponse received from the server
 * 
 * @param bindResponse The BindResponse to process
 * @param bindFuture The BindFuture to feed
 * @param responseId The associated request message ID
 * @throws InterruptedException If the Future is interrupted
 */
private void bindReceived( BindResponse bindResponse, BindFuture bindFuture, int responseId ) 
    throws InterruptedException
{
    // remove the listener from the listener map
    if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
    {
        authenticated.set( true );

        // Everything is fine, return the response
        if ( LOG.isDebugEnabled() )
        { 
            LOG.debug( I18n.msg( I18n.MSG_04101_BIND_SUCCESSFUL, bindResponse ) );
        }
    }
    else
    {
        // We have had an error
        if ( LOG.isDebugEnabled() )
        { 
            LOG.debug( I18n.msg( I18n.MSG_04100_BIND_FAIL, bindResponse ) );
        }
    }

    // Store the response into the future
    bindFuture.set( bindResponse );

    // Remove the future from the map
    removeFromFutureMaps( responseId );
}
 
Example #19
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Bind to the server using the SASL DIGEST-MD5 mechanism.
 *
 * @param userName The user name
 * @param credentials The user credentials
 * @return  A LdapResponse containing the result
 * @throws LdapException if some error occurred
 */
public BindResponse bindSaslDigestMd5( String userName, String credentials ) throws LdapException
{
    SaslDigestMd5Request request = new SaslDigestMd5Request();
    request.setUsername( userName );
    request.setCredentials( "secret" );

    return bind( request );
}
 
Example #20
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Bind to the server using the SASL CRAM-MD5 mechanism.
 *
 * @param userName The user name
 * @param credentials The user credentials
 * @return  A LdapResponse containing the result
 * @throws LdapException if some error occurred
 */
public BindResponse bindSaslCramMd5( String userName, String credentials ) throws LdapException
{
    SaslCramMd5Request request = new SaslCramMd5Request();
    request.setUsername( userName );
    request.setCredentials( "secret" );

    return bind( request );
}
 
Example #21
Source File: AbstractLdapConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void bind( Dn name ) throws LdapException
{
    byte[] credBytes = Strings.EMPTY_BYTES;

    BindRequest bindRequest = new BindRequestImpl();
    bindRequest.setDn( name );
    bindRequest.setCredentials( credBytes );

    BindResponse bindResponse = bind( bindRequest );

    processResponse( bindResponse );
}
 
Example #22
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 1, bindResponse.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 #23
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 1, bindResponse.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 #24
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );

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

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

    assertEquals( 2, bindResponse.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 #25
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

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

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

    assertEquals( 3, bindResponse.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 #26
Source File: AuthResponseTest.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( AuthResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(),
            "UTF-8" );

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

    BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = bindResponse.getLdapResult();

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

    assertEquals( 0, referrals.size() );
}
 
Example #27
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 AuthResponse
 */
@Test
public void testResponseWith1AuthResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_1_AuthResponse.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 BindResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #28
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 AuthResponse
 */
@Test
public void testResponseWith2AuthResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_2_AuthResponse.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 BindResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #29
Source File: Dsmlv2Engine.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Binds to the ldap server
 * 
 * @param messageId the message Id
 * @throws LdapException If we had an issue while binding
 * @throws IOException If we had an issue while transmitting the request or re ceiving the response
 */
protected void bind( int messageId ) throws LdapException, IOException
{
    if ( ( connection != null ) && connection.isAuthenticated() )
    {
        return;
    }

    if ( connection == null )
    {
        throw new IOException( I18n.err( I18n.ERR_02002_MISSING_CONNECTION_TO_BIND ) );
    }

    BindRequest bindRequest = new BindRequestImpl();
    bindRequest.setSimple( true );
    bindRequest.setCredentials( Strings.getBytesUtf8( password ) );
    bindRequest.setName( user );
    bindRequest.setVersion3( true );
    bindRequest.setMessageId( messageId );

    BindResponse bindResponse = connection.bind( bindRequest );

    if ( bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS )
    {
        if ( LOG.isWarnEnabled() )
        {
            LOG.warn( I18n.msg( I18n.MSG_02003_ERROR, bindResponse.getLdapResult().getDiagnosticMessage() ) );
        }
    }
}
 
Example #30
Source File: AbstractLdapConnection.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void bind( Dn name, String credentials ) throws LdapException
{
    byte[] credBytes = credentials == null ? Strings.EMPTY_BYTES : Strings.getBytesUtf8( credentials );

    BindRequest bindRequest = new BindRequestImpl();
    bindRequest.setDn( name );
    bindRequest.setCredentials( credBytes );

    BindResponse bindResponse = bind( bindRequest );

    processResponse( bindResponse );
}