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