views:

278

answers:

1

hi. I have a j2ee web application running on spring web flow using spring security. How do I change during runtime my Role saved in the session?

+1  A: 

If it's possible, it would be something like this:

SecurityContext context = SecurityContextHolder.getContext();
Object principal = context.getAuthentication().getPrincipal();
Object credentials = context.getAuthentication().getCredentials();
GrantedAuthority[] authorities = new GrantedAuthority[1];

authorities[0] = new GrantedAuthorityImpl("MY_NEW_ROLE");

Authentication auth = new UsernamePasswordAuthenticationToken(
    principal, credentials, authorities);
SecurityContextHolder.getContext().setAuthentication(auth);
rodrigoap
How do I redirect a user to another page if it is accessing a restricted page. Because currently it displays Error 404--Not Found From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:10.4.5 404 Not FoundThe server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
cedric
Did my answer help you? I answered this not related question in your new post.
rodrigoap

related questions