I am trying to implement a function where a admin user can terminate another user's session. I followed the official Spring Security documentation here: http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#list-authenticated-principals and started with getting all currently logged in users through sessionRegistry.getAllPrincipals(), but it always returned an empty list.
I set a breakpoint in SessionRegistryImpl.registerNewSession() and could see it did indeed get invoked and it did add the UserDetails (my own implementation with both equals() and hashCode() implemented) to the hashmap principals. But when I access sessionRegistry bean from a Spring MVC controller, the list is always empty.
My configuration looks pretty much the same as the documentation.
How to fix this? Did anyone successfully get SessionRegistry to work with Spring Security 4? I remember I made it work with Spring Security 3 by following these intructions(enter link description here)
SessionRegistry. Your controller uses a different instance as Spring Security hence it will never receive anything. Fix your configuration, make sure you aren't scanning for the components/configuraiton classes twice. - M. Deinum<context-param> <param-name>contextConfigLocation</param-name> <param-value> WEB-INF/spring/appServlet/my-servlet-context.xml </param-value> </context-param>- Stephane