Search in sources :

Example 1 with Grant

use of org.xdi.oxauth.model.ldap.Grant 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)

Example 2 with Grant

use of org.xdi.oxauth.model.ldap.Grant in project oxAuth by GluuFederation.

the class GrantService method addGrantBranch.

private void addGrantBranch(final String p_grantId, final String p_clientId) {
    Grant grant = new Grant();
    grant.setDn(getBaseDnForGrant(p_grantId, p_clientId));
    grant.setId(p_grantId);
    grant.setCreationDate(new Date());
    ldapEntryManager.persist(grant);
}
Also used : Grant(org.xdi.oxauth.model.ldap.Grant) MemcachedGrant(org.xdi.oxauth.model.common.MemcachedGrant) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)2 MemcachedGrant (org.xdi.oxauth.model.common.MemcachedGrant)2 Grant (org.xdi.oxauth.model.ldap.Grant)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 Calendar (java.util.Calendar)1 List (java.util.List)1 BatchOperation (org.gluu.site.ldap.persistence.BatchOperation)1 TokenLdap (org.xdi.oxauth.model.ldap.TokenLdap)1