In my application, I have an admin that can delete users. so when I delete a user from the admin session I want that the deleted user should get logged out automatically. I
In addition to expiring the user as described, you may also want to remove them from the registry:
// expire and remove the user's sessions from Spring session registry List principals = sessionRegistry.getAllPrincipals(); for (Object principal : principals) { List sessions = sessionRegistry.getAllSessions(principal, true); for (SessionInformation sessionInfo : sessions) { if (authentication.getPrincipal().equals(sessionInfo.getPrincipal())) { if (!sessionInfo.isExpired()) sessionInfo.expireNow(); sessionRegistry.removeSessionInformation(sessionInfo.getSessionId()); } } }
And if using xml config to wire up your Spring Session Registry, it may look something like this: