Search in sources :

Example 6 with CoreTokenException

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);
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) CoreTokenField(org.forgerock.openam.tokens.CoreTokenField) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) Map(java.util.Map) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter)

Example 7 with CoreTokenException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) Token(org.forgerock.openam.cts.api.tokens.Token) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException) SAMLToken(org.forgerock.openam.cts.api.tokens.SAMLToken) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter)

Example 8 with CoreTokenException

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);
        }
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 9 with CoreTokenException

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");
}
Also used : ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.apache.commons.lang.time.StopWatch) ReaperQuery(org.forgerock.openam.cts.impl.query.reaper.ReaperQuery)

Example 10 with CoreTokenException

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;
}
Also used : CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)59 JsonValue (org.forgerock.json.JsonValue)21 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)19 Token (org.forgerock.openam.cts.api.tokens.Token)14 Test (org.testng.annotations.Test)11 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)10 ResourceException (org.forgerock.json.resource.ResourceException)9 PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)9 BadRequestException (org.forgerock.json.resource.BadRequestException)8 ArrayList (java.util.ArrayList)7 ResourceResponse (org.forgerock.json.resource.ResourceResponse)7 SSOException (com.iplanet.sso.SSOException)6 SSOToken (com.iplanet.sso.SSOToken)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 HashMap (java.util.HashMap)5 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)5 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)5 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)5 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)5 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)5