Search in sources :

Example 16 with LDAPException

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());
    }
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDAPException(com.unboundid.ldap.sdk.LDAPException) InputStream(java.io.InputStream) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFException(com.unboundid.ldif.LDIFException) IOException(java.io.IOException)

Example 17 with LDAPException

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;
}
Also used : SessionEvent(org.gluu.oxauth.service.external.session.SessionEvent) LDAPException(com.unboundid.ldap.sdk.LDAPException) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException)

Example 18 with LDAPException

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;
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult)

Example 19 with LDAPException

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;
}
Also used : SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 20 with LDAPException

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;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) BindResult(com.unboundid.ldap.sdk.BindResult)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)59 SearchResult (com.unboundid.ldap.sdk.SearchResult)15 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)13 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)11 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)11 IOException (java.io.IOException)11 ResultCode (com.unboundid.ldap.sdk.ResultCode)9 LDIFReader (com.unboundid.ldif.LDIFReader)8 GeneralSecurityException (java.security.GeneralSecurityException)8 DN (com.unboundid.ldap.sdk.DN)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Entry (com.unboundid.ldap.sdk.Entry)5 Filter (com.unboundid.ldap.sdk.Filter)5 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)5 ArrayList (java.util.ArrayList)5 LdifDataUtility (org.gluu.persist.ldap.impl.LdifDataUtility)5 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)4