use of com.unboundid.ldap.sdk.LDAPBindException in project graylog2-server by Graylog2.
the class UnboundLDAPConnector method authenticate.
public boolean authenticate(LDAPConnection connection, String bindDn, EncryptedValue password) throws LDAPException {
checkArgument(!isNullOrEmpty(bindDn), "Binding with empty principal is forbidden.");
checkArgument(password != null, "Binding with null credentials is forbidden.");
checkArgument(password.isSet(), "Binding with empty credentials is forbidden.");
final SimpleBindRequest bindRequest = new SimpleBindRequest(bindDn, encryptedValueService.decrypt(password));
LOG.trace("Re-binding with DN <{}> using password", bindDn);
try {
final BindResult bind = connection.bind(bindRequest);
if (!bind.getResultCode().equals(ResultCode.SUCCESS)) {
LOG.trace("Re-binding DN <{}> failed", bindDn);
throw new RuntimeException(bind.toString());
}
final boolean authenticated = connection.getLastBindRequest().equals(bindRequest);
LOG.trace("Binding DN <{}> did not throw, connection authenticated: {}", bindDn, authenticated);
return authenticated;
} catch (LDAPBindException e) {
LOG.trace("Re-binding DN <{}> failed", bindDn);
return false;
}
}
Aggregations