Relogging a user in with different Spring Security Authorities programmatically

Posted by user1331982 on Stack Overflow See other posts from Stack Overflow or by user1331982
Published on 2012-04-13T16:06:40Z Indexed on 2012/04/13 23:29 UTC
Read the original article Hit count: 192

Filed under:

PreReq:
User logs in and is given roles got from the database using a custom implementation of userService. i.e.

authentication-provider user-service-ref="securityPolicyService"

The implemented method loadUserByUsername gets called and the roles are load for the user for the particular club they are logging into, Default one is loaded first time in.

The user then click on a different club from the UI and I call a method on a service that gets the new list of authorities for this club.

I then perform the following:

Object principle = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
SecureMember sm = (SecureMember) principle;
Authentication auth = 
      new UsernamePasswordAuthenticationToken(sm, null, newAuthories); <br><br>
    SecurityContextHolder.getContext().setAuthentication(auth);<br>
request.getSession(false).invalidate();

SecureMember extends User from SpringFramework.

The problem is the SecureMember authorities are never updated with the new ones.

thanks Gary

© Stack Overflow or respective owner

Related posts about spring-security