Search in sources :

Example 6 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class ResourceSetPermissionManager method cleanupResourceSetPermissions.

@Override
public void cleanupResourceSetPermissions(final Date now) {
    BatchOperation<ResourceSetPermission> resourceSetPermissionBatchService = new BatchOperation<ResourceSetPermission>(ldapEntryManager) {

        @Override
        protected List<ResourceSetPermission> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(staticConfiguration.getBaseDn().getClients(), ResourceSetPermission.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<ResourceSetPermission> entries) {
            for (ResourceSetPermission p : entries) {
                try {
                    ldapEntryManager.remove(p);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }

        private Filter getFilter() {
            try {
                return Filter.create(String.format("(oxAuthExpiration<=%s)", StaticUtils.encodeGeneralizedTime(now)));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthExpiration");
            }
        }
    };
    resourceSetPermissionBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) List(java.util.List) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) ResourceSetPermission(org.xdi.oxauth.model.uma.persistence.ResourceSetPermission) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 7 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class RptManager method cleanupRPTs.

@Override
public void cleanupRPTs(final Date now) {
    BatchOperation<UmaRPT> rptBatchService = new BatchOperation<UmaRPT>(ldapEntryManager) {

        @Override
        protected List<UmaRPT> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(staticConfiguration.getBaseDn().getClients(), UmaRPT.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<UmaRPT> entries) {
            for (UmaRPT p : entries) {
                try {
                    ldapEntryManager.remove(p);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }

        private Filter getFilter() {
            try {
                return Filter.create(String.format("(oxAuthExpiration<=%s)", StaticUtils.encodeGeneralizedTime(now)));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthExpiration");
            }
        }
    };
    rptBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
}
Also used : UmaRPT(org.xdi.oxauth.model.common.uma.UmaRPT) LDAPException(com.unboundid.ldap.sdk.LDAPException) AuthorizationGrantList(org.xdi.oxauth.model.common.AuthorizationGrantList) ArrayList(java.util.ArrayList) List(java.util.List) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 8 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class BaseAuthFilterService method loadEntryDN.

public String loadEntryDN(LdapEntryManager p_manager, AuthenticationFilterWithParameters authenticationFilterWithParameters, Map<String, String> normalizedAttributeValues) {
    final String filter = buildFilter(authenticationFilterWithParameters, normalizedAttributeValues);
    Filter ldapFilter;
    try {
        ldapFilter = Filter.create(filter);
    } catch (LDAPException ex) {
        log.error("Failed to create Ldap filter: '{}'", ex, filter);
        return null;
    }
    List<LdapDummyEntry> foundEntries = p_manager.findEntries(authenticationFilterWithParameters.getAuthenticationFilter().getBaseDn(), LdapDummyEntry.class, new String[0], ldapFilter);
    if (foundEntries.size() > 1) {
        log.error("Found more than one entry by filter: '{}'. Entries:\n", ldapFilter, foundEntries);
        return null;
    }
    if (!(foundEntries.size() == 1)) {
        return null;
    }
    return foundEntries.get(0).getDn();
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Filter(com.unboundid.ldap.sdk.Filter) BaseFilter(org.xdi.oxauth.model.configuration.BaseFilter) LdapDummyEntry(org.xdi.ldap.model.LdapDummyEntry)

Example 9 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class SessionStateService method mergeWithRetry.

private SessionState mergeWithRetry(final SessionState sessionState, int maxAttempts) {
    EntryPersistenceException lastException = null;
    for (int i = 1; i <= maxAttempts; i++) {
        try {
            putInCache(sessionState);
            return sessionState;
        } 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", maxAttempts);
    throw lastException;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) EmptyEntryPersistenceException(org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 10 with LDAPException

use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.

the class GrantService method cleanUp.

public void cleanUp() {
    // Cleaning oxAuthToken
    BatchOperation<TokenLdap> tokenBatchService = new BatchOperation<TokenLdap>(ldapEntryManager) {

        @Override
        protected List<TokenLdap> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), TokenLdap.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<TokenLdap> entries) {
            auditLogging(entries);
            remove(entries);
        }

        private Filter getFilter() {
            try {
                return Filter.create(String.format("(oxAuthExpiration<=%s)", StaticUtils.encodeGeneralizedTime(new Date())));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthExpiration");
            }
        }
    };
    tokenBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
    // Cleaning oxAuthGrant
    BatchOperation<Grant> grantBatchService = new BatchOperation<Grant>(ldapEntryManager) {

        @Override
        protected List<Grant> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Grant> entries) {
            removeGrants(entries);
        }

        private Filter getFilter() {
            try {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.SECOND, 60);
                return Filter.create(String.format("(&(oxAuthCreation<=%s)(|(numsubordinates=0)(hasSubordinates=FALSE)))", StaticUtils.encodeGeneralizedTime(calendar.getTime())));
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthCreation");
            }
        }
    };
    grantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
    // Cleaning old oxAuthGrant
    // Note: This block should be removed, it is used only to delete old legacy data.
    BatchOperation<Grant> oldGrantBatchService = new BatchOperation<Grant>(ldapEntryManager) {

        @Override
        protected List<Grant> getChunkOrNull(int chunkSize) {
            return ldapEntryManager.findEntries(baseDn(), Grant.class, getFilter(), SearchScope.SUB, null, this, 0, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Grant> entries) {
            removeGrants(entries);
        }

        private Filter getFilter() {
            try {
                return Filter.create("(&(!(oxAuthCreation=*))(|(numsubordinates=0)(hasSubordinates=FALSE)))");
            } catch (LDAPException e) {
                log.trace(e.getMessage(), e);
                return Filter.createPresenceFilter("oxAuthCreation");
            }
        }
    };
    oldGrantBatchService.iterateAllByChunks(CleanerTimer.BATCH_SIZE);
}
Also used : Grant(org.xdi.oxauth.model.ldap.Grant) MemcachedGrant(org.xdi.oxauth.model.common.MemcachedGrant) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) LDAPException(com.unboundid.ldap.sdk.LDAPException) Calendar(java.util.Calendar) List(java.util.List) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) TokenLdap(org.xdi.oxauth.model.ldap.TokenLdap) Date(java.util.Date)

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