Search in sources :

Example 16 with BindRequest

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

the class LdapNetworkConnection method bind.

/**
 * {@inheritDoc}
 */
@Override
public void bind() throws LdapException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(I18n.msg(I18n.MSG_03213_BIND));
    }
    // Create the BindRequest
    BindRequest bindRequest = createBindRequest(config.getName(), Strings.getBytesUtf8(config.getCredentials()));
    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)

Example 17 with BindRequest

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

the class LdapNetworkConnection method anonymousBind.

/**
 * {@inheritDoc}
 */
@Override
public void anonymousBind() throws LdapException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(I18n.msg(I18n.MSG_03210_ANONYMOUS_BIND));
    }
    // Create the BindRequest
    BindRequest bindRequest = createBindRequest(StringConstants.EMPTY, Strings.EMPTY_BYTES);
    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)

Example 18 with BindRequest

use of org.apache.directory.api.ldap.model.message.BindRequest 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 19 with BindRequest

use of org.apache.directory.api.ldap.model.message.BindRequest 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 20 with BindRequest

use of org.apache.directory.api.ldap.model.message.BindRequest 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)

Aggregations

BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)45 Test (org.junit.Test)27 DecoderException (org.apache.directory.api.asn1.DecoderException)19 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)17 ByteBuffer (java.nio.ByteBuffer)16 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)16 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)15 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)15 EncoderException (org.apache.directory.api.asn1.EncoderException)12 Control (org.apache.directory.api.ldap.model.message.Control)11 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)9 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)9 BindRequestImpl (org.apache.directory.api.ldap.model.message.BindRequestImpl)9 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)7 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)4 Dn (org.apache.directory.api.ldap.model.name.Dn)4 MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)3 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)3