@Override
public void removeSessionInformation(String sessionId) {
Assert.hasText(sessionId, "SessionId required as per interface contract");
SessionInformation info = getSessionInformation(sessionId);
if (info == null) {
return;
}
if (log.isTraceEnabled()) {
log.debug("Removing session " + sessionId + " from set of registered sessions");
}
if (!isSuccess(client.delete(sessionId))) {
log.error(String.format("Error removing session from cache: %s", sessionId));
}
Set<String> sessionsUsedByPrincipal = (Set<String>) client.get(((User) info.getPrincipal()).getUuid());
if (sessionsUsedByPrincipal == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Removing session " + sessionId + " from principal's set of registered sessions");
}
sessionsUsedByPrincipal.remove(sessionId);
if (sessionsUsedByPrincipal.isEmpty()) {
// No need to keep object in principals Map anymore
if (log.isDebugEnabled()) {
log.debug("Removing principal " + info.getPrincipal() + " from registry");
}
client.delete(((User) info.getPrincipal()).getUuid());
} else {
client.replace(((User) info.getPrincipal()).getUuid(), 86400, sessionsUsedByPrincipal);
}
if (log.isTraceEnabled()) {
log.trace("Sessions used by '" + info.getPrincipal() + "' : " + sessionsUsedByPrincipal);
}
}