Me gustaría saber que you are following the correct path
por invalidar las sesiones de usuario
usersSessions.forEach((session) -> {
sessionRegistry.getSessionInformation(session.getId()).expireNow();
});
Algo a tener en cuenta
SessionInformation.expireNow()
no pretende eliminar entradas de redis
base de datos, simplemente agrega el atributo caducado a la sesión como mencionaste correctamente.
¿Pero cómo esto invalida la sesión del usuario?
Aquí entra en juego ConcurrentSessionFilter donde .doFilter()
El método hace el truco de automatically logging out
Aquí está el fragmento de ConcurrentSessionFilter
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
if (session != null) {
SessionInformation info = sessionRegistry.getSessionInformation(session
.getId());
if (info != null) {
if (info.isExpired()) {
// Expired - abort processing
doLogout(request, response);
String targetUrl = determineExpiredUrl(request, info);
if (targetUrl != null) {
redirectStrategy.sendRedirect(request, response, targetUrl);
return;
}
else {
response.getWriter().print(
"This session has been expired (possibly due to multiple concurrent "
+ "logins being attempted as the same user).");
response.flushBuffer();
}
return;
}
else {
// Non-expired - update last request date/time
sessionRegistry.refreshLastRequest(info.getSessionId());
}
}
}
chain.doFilter(request, response);
}
¡Salud por eso!