use of com.unboundid.ldap.sdk.LDAPException in project admin-console-beta by connexta.
the class TestLdapServer method loadLdifFile.
private void loadLdifFile(String ldifPath) {
try (InputStream ldifStream = getClass().getResourceAsStream(ldifPath)) {
assertThat("Cannot find LDIF test resource file", ldifStream, is(notNullValue()));
LDIFReader reader = new LDIFReader(ldifStream);
LDIFChangeRecord readEntry;
while ((readEntry = reader.readChangeRecord()) != null) {
readEntry.processChange(realServer);
}
} catch (IOException | LDIFException | LDAPException e) {
fail(e.getMessage());
}
}
use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.
the class SessionIdService method mergeWithRetry.
private void mergeWithRetry(final SessionId sessionId) {
final Pair<Date, Integer> expiration = expirationDate(sessionId.getCreationDate(), sessionId.getState());
sessionId.setExpirationDate(expiration.getFirst());
sessionId.setTtl(expiration.getSecond());
EntryPersistenceException lastException = null;
for (int i = 1; i <= MAX_MERGE_ATTEMPTS; i++) {
try {
if (appConfiguration.getSessionIdPersistInCache()) {
cacheService.put(expiration.getSecond(), sessionId.getDn(), sessionId);
} else {
persistenceEntryManager.merge(sessionId);
}
localCacheService.put(DEFAULT_LOCAL_CACHE_EXPIRATION, sessionId.getDn(), sessionId);
externalEvent(new SessionEvent(SessionEventType.UPDATED, sessionId));
return;
} catch (EntryPersistenceException ex) {
lastException = ex;
if (ex.getCause() instanceof LDAPException) {
LDAPException parentEx = ((LDAPException) ex.getCause());
log.debug("LDAP exception resultCode: '{}'", parentEx.getResultCode().intValue());
if ((parentEx.getResultCode().intValue() == ResultCode.NO_SUCH_ATTRIBUTE_INT_VALUE) || (parentEx.getResultCode().intValue() == ResultCode.ATTRIBUTE_OR_VALUE_EXISTS_INT_VALUE)) {
log.warn("Session entry update attempt '{}' was unsuccessfull", i);
continue;
}
}
throw ex;
}
}
log.error("Session entry update attempt was unsuccessfull after '{}' attempts", MAX_MERGE_ATTEMPTS);
throw lastException;
}
use of com.unboundid.ldap.sdk.LDAPException in project gitblit by gitblit.
the class LdapAuthProvider method doSearch.
private SearchResult doSearch(LdapConnection ldapConnection, String base, String filter) {
try {
SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
SearchResult result = ldapConnection.search(searchRequest);
if (result.getResultCode() != ResultCode.SUCCESS) {
return null;
}
return result;
} catch (LDAPException e) {
logger.error("Problem creating LDAP search", e);
return null;
}
}
use of com.unboundid.ldap.sdk.LDAPException in project gitblit by gitblit.
the class LdapConnection method isAuthenticated.
public boolean isAuthenticated(String userDn, String password) {
verifyCurrentBinding();
// If the currently bound DN is already the DN of the logging in user, authentication has already happened
// during the previous bind operation. We accept this and return with the current bind left in place.
// This could also be changed to always retry binding as the logging in user, to make sure that the
// connection binding has not been tampered with in between. So far I see no way how this could happen
// and thus skip the repeated binding.
// This check also makes sure that the DN in realm.ldap.bindpattern actually matches the DN that was found
// when searching the user entry.
String boundDN = currentBindRequest.getBindDN();
if (boundDN != null && boundDN.equals(userDn)) {
return true;
}
// Bind a the logging in user to check for authentication.
// Afterwards, bind as the original bound DN again, to restore the previous authorization.
boolean isAuthenticated = false;
try {
// Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
SimpleBindRequest ubr = new SimpleBindRequest(userDn, password);
conn.bind(ubr);
isAuthenticated = true;
userBindRequest = ubr;
} catch (LDAPException e) {
logger.error("Error authenticating user ({})", userDn, e);
}
try {
conn.bind(currentBindRequest);
} catch (LDAPException e) {
logger.error("Error reinstating original LDAP authorization (code {}). Team information may be inaccurate for this log in.", e.getResultCode(), e);
}
return isAuthenticated;
}
use of com.unboundid.ldap.sdk.LDAPException in project gitblit by gitblit.
the class LdapConnection method bind.
/**
* Bind using the manager credentials set in realm.ldap.username and ..password
* @return A bind result, or null if binding failed.
*/
public BindResult bind() {
BindResult result = null;
try {
result = conn.bind(managerBindRequest);
currentBindRequest = managerBindRequest;
} catch (LDAPException e) {
logger.error("Error authenticating to LDAP with manager account to search the directory.");
logger.error(" Please check your settings for realm.ldap.username and realm.ldap.password.");
logger.debug(" Received exception when binding to LDAP", e);
return null;
}
return result;
}
Aggregations