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