Search in sources :

Example 1 with BindRequestImpl

use of org.apache.directory.api.ldap.model.message.BindRequestImpl in project graylog2-server by Graylog2.

the class LdapConnector method authenticate.

public boolean authenticate(LdapNetworkConnection connection, String principal, String credentials) throws LdapException {
    checkArgument(!isNullOrEmpty(principal), "Binding with empty principal is forbidden.");
    checkArgument(!isNullOrEmpty(credentials), "Binding with empty credentials is forbidden.");
    final BindRequestImpl bindRequest = new BindRequestImpl();
    bindRequest.setName(principal);
    bindRequest.setCredentials(credentials);
    LOG.trace("Re-binding with DN {} using password", principal);
    final BindResponse bind = connection.bind(bindRequest);
    if (!bind.getLdapResult().getResultCode().equals(ResultCodeEnum.SUCCESS)) {
        LOG.trace("Re-binding DN {} failed", principal);
        throw new RuntimeException(bind.toString());
    }
    LOG.trace("Binding DN {} did not throw, connection authenticated: {}", principal, connection.isAuthenticated());
    return connection.isAuthenticated();
}
Also used : BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 2 with BindRequestImpl

use of org.apache.directory.api.ldap.model.message.BindRequestImpl in project directory-ldap-api by apache.

the class AbstractLdapConnection method bind.

/**
 * {@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);
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 3 with BindRequestImpl

use of org.apache.directory.api.ldap.model.message.BindRequestImpl in project directory-ldap-api by apache.

the class AbstractLdapConnection method createBindRequest.

/**
 * Create a complete BindRequest ready to be sent.
 *
 * @param name The DN to bind with
 * @param credentials The user's password
 * @param saslMechanism The SASL mechanism to use
 * @param controls The controls to send
 * @return The created BindRequest
 */
protected BindRequest createBindRequest(String name, byte[] credentials, String saslMechanism, Control... controls) {
    // Set the new messageId
    BindRequest bindRequest = new BindRequestImpl();
    // Set the version
    bindRequest.setVersion3(true);
    // Set the name
    bindRequest.setName(name);
    // Set the credentials
    if (Strings.isEmpty(saslMechanism)) {
        // Simple bind
        bindRequest.setSimple(true);
        bindRequest.setCredentials(credentials);
    } else {
        // SASL bind
        bindRequest.setSimple(false);
        bindRequest.setCredentials(credentials);
        bindRequest.setSaslMechanism(saslMechanism);
    }
    // Add the controls
    if ((controls != null) && (controls.length != 0)) {
        bindRequest.addAllControls(controls);
    }
    return bindRequest;
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 4 with BindRequestImpl

use of org.apache.directory.api.ldap.model.message.BindRequestImpl in project directory-ldap-api by apache.

the class AbstractLdapConnection method bind.

/**
 * {@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);
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 5 with BindRequestImpl

use of org.apache.directory.api.ldap.model.message.BindRequestImpl in project directory-ldap-api by apache.

the class ValidatingPoolableLdapConnectionFactoryTest method testPoolWithBind.

@Test
public void testPoolWithBind() {
    PoolTester tester = new PoolTester();
    // no bind
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind()
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            connection.bind();
            verify(connection, times(1)).bind();
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // anonymousBind()
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            connection.anonymousBind();
            verify(connection, times(1)).anonymousBind();
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind( String )
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            connection.bind("");
            verify(connection, times(1)).bind("");
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // admin bind( String, String )
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            connection.bind(ADMIN_DN, ADMIN_CREDENTIALS);
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind( String, String )
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            connection.bind("", "");
            verify(connection, times(1)).bind("", "");
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind( Dn )
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            Dn dn = new Dn();
            connection.bind(dn);
            verify(connection, times(1)).bind(dn);
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind( Dn, String )
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            Dn dn = new Dn();
            connection.bind(dn, "");
            verify(connection, times(1)).bind(dn, "");
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
    // bind( BindRequest );
    tester.execute(new WithConnection() {

        @Override
        public void execute(LdapConnection connection, Counts counts) throws LdapException {
            BindRequest bindRequest = new BindRequestImpl();
            connection.bind(bindRequest);
            verify(connection, times(1)).bind(bindRequest);
            verifyAdminBind(connection, times(counts.adminBindCount));
        }
    });
}
Also used : BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl) Test(org.junit.Test)

Aggregations

BindRequestImpl (org.apache.directory.api.ldap.model.message.BindRequestImpl)11 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)9 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)5 Dn (org.apache.directory.api.ldap.model.name.Dn)4 IOException (java.io.IOException)2 DecoderException (org.apache.directory.api.asn1.DecoderException)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 Control (org.apache.directory.api.ldap.model.message.Control)2 OpaqueControl (org.apache.directory.api.ldap.model.message.controls.OpaqueControl)2 Test (org.junit.Test)2 ConnectException (java.net.ConnectException)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SaslClient (javax.security.sasl.SaslClient)1 EncoderException (org.apache.directory.api.asn1.EncoderException)1 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)1 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)1 MessageEncoderException (org.apache.directory.api.ldap.codec.api.MessageEncoderException)1 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)1