0

I have started switching my application over to use Spring Security. I have a custom UserDetailsServiceImpl which is returning my custom UserDetails which contain the standard Spring stuff (roles, etc.), as well as some application specific references, IE: currentWorkspace.

I am tracking the currentWorkspace in the DB and it is loaded properly in the initial loadUserByUsername. In my Spring MVC when I change something in my UserDetails like currentWorkspace, how can I trigger a reload of the UserDetails, or modify the current Principal and push it into the session in place of the outdated one?

Is it as simple as just calling loadUserByUsername in my UserDetailsService and Spring will handle the rest? Do I have to mess around with the SecurityContextHolder.getContext().getAuthentication() and set something there? I figured this was something simple but can't figure out what to do.

Walls
  • 3,972
  • 6
  • 37
  • 52
  • http://stackoverflow.com/questions/7889660/how-to-reload-spring-security-principal-after-updating-in-hibernate – hasnae Sep 30 '16 at 16:15
  • Are you fine with reloading `UserDetails` on every HTTP request? If yes, please take a look at my solution posted in this answer: http://stackoverflow.com/questions/26393518/spring-security-logoff-a-user-while-runtime/26697333#26697333 – ksokol Oct 01 '16 at 10:02

0 Answers0