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();
}
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);
}
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;
}
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);
}
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));
}
});
}
Aggregations