use of org.forgerock.openam.cts.CTSPersistentStore in project OpenAM by OpenRock.
the class SessionCount method getSessionsFromRepository.
private static Map<String, Long> getSessionsFromRepository(String uuid) throws Exception {
CTSPersistentStore repo = sessionService.getRepository();
try {
// Filter and Query the CTS
TokenFilter filter = new TokenFilterBuilder().returnAttribute(SessionTokenField.SESSION_ID.getField()).returnAttribute(CoreTokenField.EXPIRY_DATE).and().withAttribute(CoreTokenField.USER_ID, uuid).build();
Collection<PartialToken> partialTokens = repo.attributeQuery(filter);
if (debug.messageEnabled()) {
debug.message(MessageFormat.format("getSessionsFromRepository query success:\n" + "Query: {0}\n" + "Count: {1}", filter, partialTokens.size()));
}
// Populate the return Map from the query results.
Map<String, Long> sessions = new HashMap<String, Long>();
for (PartialToken partialToken : partialTokens) {
// Session ID
String sessionId = partialToken.getValue(SessionTokenField.SESSION_ID.getField());
// Expiration Date converted to Unix Time
Calendar timestamp = partialToken.getValue(CoreTokenField.EXPIRY_DATE);
long unixTime = TimeUtils.toUnixTime(timestamp);
sessions.put(sessionId, unixTime);
}
if (debug.messageEnabled()) {
debug.message(MessageFormat.format("getSessionsFromRepository query results:\n" + "{0}", sessions));
}
return sessions;
} catch (Exception e) {
debug.error("SessionCount.getSessionsFromRepository: " + "Session repository is not available", e);
throw e;
}
}
Aggregations