use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CTSPersistentStoreImpl method delete.
@Override
public int delete(Map<CoreTokenField, Object> query) throws DeleteFailedException {
TokenFilterBuilder.FilterAttributeBuilder builder = new TokenFilterBuilder().returnAttribute(CoreTokenField.TOKEN_ID).and();
for (Map.Entry<CoreTokenField, Object> entry : query.entrySet()) {
CoreTokenField key = entry.getKey();
Object value = entry.getValue();
builder = builder.withAttribute(key, value);
}
TokenFilter filter = builder.build();
Collection<String> failures = new ArrayList<String>();
try {
Collection<PartialToken> partialTokens = attributeQuery(filter);
debug("Found {0} partial Tokens for deletion", Integer.toString(partialTokens.size()));
for (PartialToken token : partialTokens) {
String tokenId = token.getValue(CoreTokenField.TOKEN_ID);
try {
delete(tokenId);
} catch (CoreTokenException e) {
failures.add(tokenId);
}
}
if (!failures.isEmpty()) {
error("Failed to delete {0} tokens.\n{1}", Integer.toString(failures.size()), StringUtils.join(failures, ","));
}
return partialTokens.size() - failures.size();
} catch (CoreTokenException e) {
throw new DeleteFailedException("Failed to delete Tokens", e);
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class SAML2CTSPersistentStore method retrieveSAML2TokensWithSecondaryKey.
/**
*{@inheritDoc}
*/
@Override
public List<Object> retrieveSAML2TokensWithSecondaryKey(String secondaryKey) throws SAML2TokenRepositoryException {
secondaryKey = tokenIdFactory.toSAMLSecondaryTokenId(secondaryKey);
try {
TokenFilter filter = new TokenFilterBuilder().withAttribute(SAMLTokenField.SECONDARY_KEY.getField(), secondaryKey).build();
Collection<Token> tokens = persistentStore.query(filter);
List<Object> results = new ArrayList<Object>(tokens.size());
for (Token token : tokens) {
SAMLToken samlToken = tokenAdapter.fromToken(token);
results.add(samlToken.getToken());
}
return results;
} catch (CoreTokenException e) {
debug.error("SAML2CTSPersistentStore.retrieveSAML2TokensWithSecondaryKey(): failed to retrieve SAML2 " + "tokens using secondary key:" + secondaryKey, e);
throw new SAML2TokenRepositoryException(e.getMessage(), e);
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class DeleteOnQueryResultHandler method processResults.
@Override
public void processResults(Collection<PartialToken> results) {
String tokenId = null;
for (PartialToken result : results) {
try {
tokenId = result.getValue(CoreTokenField.TOKEN_ID);
taskDispatcher.delete(tokenId, resultHandlerFactory.getDeleteHandler());
} catch (CoreTokenException ex) {
debug.error(String.format("Unable to submit delete task for token ID {0}", tokenId), ex);
}
}
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class CTSReaper method run.
/**
* Performs the query against the directory by selecting the Token IDs for all Tokens
* that have expired. These Token IDs are then scheduled for deletion. The task will
* not complete until all of the delete operations have returned.
*/
public void run() {
debug("Reaper starting");
// Timers for debugging
StopWatch query = new StopWatch();
StopWatch waiting = new StopWatch();
// Latches will track deletion of each page of results
List<CountDownLatch> latches = new ArrayList<CountDownLatch>();
ReaperQuery reaperQuery = queryFactory.getQuery();
try {
long total = 0;
query.start();
for (Collection<String> ids = reaperQuery.nextPage(); ids != null; ids = reaperQuery.nextPage()) {
// If the thread has been interrupted, exit all processing.
if (Thread.interrupted()) {
Thread.currentThread().interrupt();
debug("Interrupted, returning");
return;
}
total += ids.size();
debug("Queried {0} tokens", Long.toString(total));
// Latch will track the deletions of the page
latches.add(tokenDeletion.deleteBatch(ids));
}
query.stop();
waiting.start();
debug("Expired Token Query Time: {0}ms", Long.toString(query.getTime()));
// Wait stage
for (CountDownLatch latch : latches) {
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
waiting.stop();
monitoringStore.addReaperRun(query.getStartTime(), query.getTime() + waiting.getTime(), total);
debug("Worker threads Time: {0}ms", Long.toString(waiting.getTime()));
} catch (CoreTokenException e) {
debug.error("CTS Reaper failed", e);
}
debug("Reaper complete");
}
use of org.forgerock.openam.cts.exceptions.CoreTokenException in project OpenAM by OpenRock.
the class TokenDeletion method deleteBatch.
/**
* Performs a delete against a batch of Token IDs in the search results.
*
* This function will defer to the {@link TaskDispatcher} for deletion requests.
*
* @param tokens The Token ID's to delete.
*
* @return CountDownLatch A CountDownLatch which can be blocked on to ensure that
* the delete tasks have been completed.
*
* @throws CoreTokenException If there was any problem queuing the delete operation.
*/
public CountDownLatch deleteBatch(Collection<String> tokens) throws CoreTokenException {
CountDownLatch latch = new CountDownLatch(tokens.size());
ResultHandler<String, CoreTokenException> handler = new CountdownHandler(latch);
for (String token : tokens) {
queue.delete(token, handler);
}
return latch;
}
Aggregations