Search in sources :

Example 1 with BatchOperation

use of org.gluu.site.ldap.persistence.BatchOperation 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 2 with BatchOperation

use of org.gluu.site.ldap.persistence.BatchOperation 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 3 with BatchOperation

use of org.gluu.site.ldap.persistence.BatchOperation in project oxAuth by GluuFederation.

the class CleanerTimer method processU2fDeviceRegistrations.

private void processU2fDeviceRegistrations() {
    log.debug("Start U2F request clean up");
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.SECOND, -90);
    final Date expirationDate = calendar.getTime();
    BatchOperation<DeviceRegistration> deviceRegistrationBatchService = new BatchOperation<DeviceRegistration>(ldapEntryManager) {

        @Override
        protected List<DeviceRegistration> getChunkOrNull(int chunkSize) {
            return deviceRegistrationService.getExpiredDeviceRegistrations(this, expirationDate);
        }

        @Override
        protected void performAction(List<DeviceRegistration> entries) {
            for (DeviceRegistration deviceRegistration : entries) {
                try {
                    log.debug("Removing DeviceRegistration: {}, Creation date: {}", deviceRegistration.getId(), deviceRegistration.getCreationDate());
                    deviceRegistrationService.removeUserDeviceRegistration(deviceRegistration);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    deviceRegistrationBatchService.iterateAllByChunks(BATCH_SIZE);
    log.debug("End U2F request clean up");
}
Also used : DeviceRegistration(org.xdi.oxauth.model.fido.u2f.DeviceRegistration) AuthorizationGrantList(org.xdi.oxauth.model.common.AuthorizationGrantList) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation)

Example 4 with BatchOperation

use of org.gluu.site.ldap.persistence.BatchOperation in project oxAuth by GluuFederation.

the class CleanerTimer method processU2fRequests.

private void processU2fRequests() {
    log.debug("Start U2F request clean up");
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.SECOND, -90);
    final Date expirationDate = calendar.getTime();
    BatchOperation<RequestMessageLdap> requestMessageLdapBatchService = new BatchOperation<RequestMessageLdap>(ldapEntryManager) {

        @Override
        protected List<RequestMessageLdap> getChunkOrNull(int chunkSize) {
            return u2fRequestService.getExpiredRequestMessages(this, expirationDate);
        }

        @Override
        protected void performAction(List<RequestMessageLdap> entries) {
            for (RequestMessageLdap requestMessageLdap : entries) {
                try {
                    log.debug("Removing RequestMessageLdap: {}, Creation date: {}", requestMessageLdap.getRequestId(), requestMessageLdap.getCreationDate());
                    u2fRequestService.removeRequestMessage(requestMessageLdap);
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    requestMessageLdapBatchService.iterateAllByChunks(BATCH_SIZE);
    log.debug("End U2F request clean up");
}
Also used : AuthorizationGrantList(org.xdi.oxauth.model.common.AuthorizationGrantList) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) RequestMessageLdap(org.xdi.oxauth.model.fido.u2f.RequestMessageLdap)

Example 5 with BatchOperation

use of org.gluu.site.ldap.persistence.BatchOperation 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

BatchOperation (org.gluu.site.ldap.persistence.BatchOperation)8 List (java.util.List)5 AuthorizationGrantList (org.xdi.oxauth.model.common.AuthorizationGrantList)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)2 Filter (com.unboundid.ldap.sdk.Filter)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 LdapEntryManager (org.gluu.site.ldap.persistence.LdapEntryManager)1 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)1 CustomAttribute (org.xdi.ldap.model.CustomAttribute)1 SimpleBranch (org.xdi.ldap.model.SimpleBranch)1 MetricEntry (org.xdi.model.metric.ldap.MetricEntry)1 MemcachedGrant (org.xdi.oxauth.model.common.MemcachedGrant)1 UmaRPT (org.xdi.oxauth.model.common.uma.UmaRPT)1 DeviceRegistration (org.xdi.oxauth.model.fido.u2f.DeviceRegistration)1 RequestMessageLdap (org.xdi.oxauth.model.fido.u2f.RequestMessageLdap)1