Search in sources :

Example 11 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.

the class CtsPersistenceOperationsDelegate method listDurationOfTokens.

/**
     * Gathers list of the durations of tokens in epoch'd seconds
     *
     * @param tokenType The type of token for which we are gathering results
     * @return A collection of longs, each of which represents the duration of a token inside the CTS
     * @throws CoreTokenException
     */
public Collection<Long> listDurationOfTokens(TokenType tokenType) throws CoreTokenException {
    final Collection<Long> results = new ArrayList<Long>();
    final long unixTime = TimeUtils.currentUnixTime();
    final TokenFilter filter = new TokenFilterBuilder().returnAttribute(CoreTokenField.CREATE_TIMESTAMP).and().withAttribute(CoreTokenField.TOKEN_TYPE, tokenType).build();
    for (PartialToken token : store.attributeQuery(filter)) {
        Calendar timestamp = token.getValue(CoreTokenField.CREATE_TIMESTAMP);
        results.add(unixTime - TimeUtils.toUnixTime(timestamp));
    }
    return results;
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) TokenFilterBuilder(org.forgerock.openam.cts.api.filter.TokenFilterBuilder) TokenFilter(org.forgerock.openam.cts.api.filter.TokenFilter)

Example 12 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.

the class CoreTokenAdapter method attributeQuery.

/**
     * Queries the persistence layer using the given TokenFilter which must have the required
     * 'return attributes' defined within it. The results of this query will consist of PartialTokens
     * that match the requested CoreTokenFields.
     *
     * @see TokenFilter#addReturnAttribute(org.forgerock.openam.tokens.CoreTokenField)
     * @see org.forgerock.openam.tokens.CoreTokenField
     *
     * @param filter Non null TokenFilter with return attributes defined.
     * @return Non null, but possibly empty results.
     * @throws CoreTokenException If there was an error performing the query.
     * @throws IllegalArgumentException If the filter did not define any Return Fields.
     */
public Collection<PartialToken> attributeQuery(final TokenFilter filter) throws CoreTokenException, IllegalArgumentException {
    ResultHandler<Collection<PartialToken>, CoreTokenException> handler = handlerFactory.getPartialQueryHandler();
    try {
        attributeQueryWithHandler(filter, handler);
        Collection<PartialToken> partialTokens = handler.getResults();
        Collection<PartialToken> results = new ArrayList<PartialToken>();
        if (filter.getReturnFields().contains(CoreTokenField.BLOB)) {
            for (PartialToken p : partialTokens) {
                try {
                    byte[] value = p.getValue(CoreTokenField.BLOB);
                    results.add(new PartialToken(p, CoreTokenField.BLOB, strategy.reverse(value)));
                } catch (TokenStrategyFailedException e) {
                    throw new CoreTokenException("Failed to reverse Blob strategy", e);
                }
            }
        } else {
            results = partialTokens;
        }
        debug("AttributeQuery: returned {0} Partial Tokens: {1}", results.size(), filter);
        return results;
    } catch (CoreTokenException e) {
        throw new QueryFailedException(filter, e);
    }
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TokenStrategyFailedException(org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)

Example 13 with PartialToken

use of org.forgerock.openam.sm.datalayer.api.query.PartialToken in project OpenAM by OpenRock.

the class CTSTokenPersistenceImpl method listTokens.

@Override
public List<STSIssuedTokenState> listTokens(QueryFilter<CoreTokenField> queryFilter) throws CTSTokenPersistenceException {
    Collection<PartialToken> partialTokens;
    try {
        partialTokens = ctsPersistentStore.attributeQuery(buildTokenFilter(queryFilter));
    } catch (CoreTokenException e) {
        throw new CTSTokenPersistenceException(ResourceException.INTERNAL_ERROR, e.getMessage(), e);
    }
    List<STSIssuedTokenState> issuedTokens = new ArrayList<>(partialTokens.size());
    for (PartialToken partialToken : partialTokens) {
        issuedTokens.add(marshalIssuedTokenState(partialToken));
    }
    return issuedTokens;
}
Also used : PartialToken(org.forgerock.openam.sm.datalayer.api.query.PartialToken) ArrayList(java.util.ArrayList) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) STSIssuedTokenState(org.forgerock.openam.sts.user.invocation.STSIssuedTokenState) CTSTokenPersistenceException(org.forgerock.openam.sts.CTSTokenPersistenceException)

Aggregations

PartialToken (org.forgerock.openam.sm.datalayer.api.query.PartialToken)13 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 TokenFilter (org.forgerock.openam.cts.api.filter.TokenFilter)5 TokenFilterBuilder (org.forgerock.openam.cts.api.filter.TokenFilterBuilder)5 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)5 CoreTokenField (org.forgerock.openam.tokens.CoreTokenField)4 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 ResultHandler (org.forgerock.openam.sm.datalayer.api.ResultHandler)2 SessionException (com.iplanet.dpro.session.SessionException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CTSPersistentStore (org.forgerock.openam.cts.CTSPersistentStore)1 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)1 TokenStrategyFailedException (org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException)1 QueryBuilder (org.forgerock.openam.sm.datalayer.api.query.QueryBuilder)1 CTSTokenPersistenceException (org.forgerock.openam.sts.CTSTokenPersistenceException)1 STSIssuedTokenState (org.forgerock.openam.sts.user.invocation.STSIssuedTokenState)1 Connection (org.forgerock.opendj.ldap.Connection)1