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