-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Sergey Klimenko (Migrated from SEC-1832) said:
Hi team,
I've read SEC-1643 issue and agree with resolution but the problem still exist: SessionRegistry doesn't work after server bounce because SecurityContext is restored from serialized session and SessionRegistry knows nothing about that. I'm not sure that it's good idea to implement serializable SessionRegistry (anyway, it should be part of library but not my custom implementation) class. There is no points when the registry should be stored and loaded from disk and there is no way synchronize it with original server sessions serialization.
Could you please think about any other solutions?
Probably, it should be done in SecurityContextPersistenceFilter because it manages states of security context and I see only one appropriate point where it can be done: in finally section. If after the filter execution there is no appropriate information about session in SessionRegistry it should be created. So code should be changed to something like the following code:
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
SecurityContext contextBeforeChainExecution = repo.loadContext(holder);
try {
SecurityContextHolder.setContext(contextBeforeChainExecution);
chain.doFilter(holder.getRequest(), holder.getResponse());
} finally {
SecurityContext contextAfterChainExecution = SecurityContextHolder.getContext();
// Crucial removal of SecurityContextHolder contents - do this before anything else.
SecurityContextHolder.clearContext();
repo.saveContext(contextAfterChainExecution, holder.getRequest(), holder.getResponse());
/////////////////////// NEW CODE BEGIN ///////////////////
SessionInformation info = sessionRegistry.getSessionInformation(session.getId());
if (info == null) { // not sure about contextAfterChainExecution.getAuthentication() != null
sessionRegistry.registerNewSession(session.getId(), contextAfterChainExecution.getAuthentication());
}
/////////////////////// NEW CODE END ///////////////////
request.removeAttribute(FILTER_APPLIED);
if (debug) {
logger.debug("SecurityContextHolder now cleared, as request processing completed");
}
}