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);
}
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);
}
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");
}
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");
}
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);
}
Aggregations