use of io.apiman.gateway.engine.components.ldap.result.LdapResultCode in project apiman by apiman.
the class LDAPIdentityValidator method handleLdapSearch.
private void handleLdapSearch(final ILdapClientConnection connection, List<ILdapSearchEntry> searchEntries, LDAPIdentitySource config, LdapConfigBean ldapConfigBean, ILdapComponent ldapComponent, IPolicyContext context, String username, String password, final IAsyncResultHandler<Boolean> handler) {
if (searchEntries.size() > 1) {
// $NON-NLS-1$
NamingException ex = new NamingException("Found multiple entries for the same username: " + username);
handler.handle(AsyncResultImpl.<Boolean>create(ex));
} else if (searchEntries.isEmpty()) {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
} else {
// Just one result
// First entry
String userDn = searchEntries.get(0).getDn();
if (userDn != null) {
ldapConfigBean.setBindDn(userDn);
ldapConfigBean.setBindPassword(password);
bind(config, ldapConfigBean, ldapComponent, context, new IAsyncResultHandler<ILdapResult>() {
@Override
public void handle(IAsyncResult<ILdapResult> result) {
if (result.isError()) {
if (result.getError() instanceof LdapException) {
LdapException ex = (LdapException) result.getError();
if (ex.getResultCode().isAuthFailure()) {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
} else {
handler.handle(AsyncResultImpl.<Boolean>create(ex));
}
connection.close(ex);
} else {
handler.handle(AsyncResultImpl.<Boolean>create(result.getError()));
connection.close();
}
} else {
LdapResultCode resultCode = result.getResult().getResultCode();
if (LdapResultCode.isSuccess(resultCode)) {
handler.handle(AsyncResultImpl.create(Boolean.TRUE));
} else {
// TODO handle errors better?
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
}
connection.close();
}
}
});
} else {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
}
}
}
Aggregations