We have seen the *scary* scenario happen a couple times when testing our application. Please let me know how this could possibly be happening.
1) User 1 is logged in.
2) User 2 logs in (password has expired) forcing a change password. After which we programmatically authenticate user 2.
3) After this programmatic authentication user1 (still logged in) now becomes user 2!!
We are programmatically authenticating like this.
1) after change password
2) And then this in the controller after the prog authenticationCode:UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(user.getUsernameLookup(), password, user.getAuthorities()); Authentication authentication = authenticationManager.authenticate(result); if(authentication.getPrincipal() instanceof User) { SecurityContextHolder.getContext().setAuthentication(authentication); }
Code:request.getSession().setAttribute(HttpSessionContextIntegrationFilter.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());


