Okay ... I found the solution.
Acegi securitycontext stores the user information in the ContextHolder. And you can get all the information of the authenticated user.
You can change the authorities in this way:
Code:
SecurityContext sc = SecurityContextHolder.getContext();
Authentication currentUser = sc.getAuthentication();
UserDetailsImpl userDetails = (UserDetailsImpl) currentUser.getPrincipal();
ArrayList authorities = new ArrayList(2);
authorities.add(new GrantedAuthorityImpl("DUMMY"));
userDetails.setAuthorities((GrantedAuthority[])authorities.toArray(new GrantedAuthority[]{}));
But this is only valid for the life of the current thread. If you need to make persistent this every time you invoke the above code:
Code:
SecurityContext sc = SecurityContextHolder.getContext();
Authentication currentUser = sc.getAuthentication();
UserDetailsImpl userDetails = (UserDetailsImpl) currentUser.getPrincipal();
You have to re-aunthenticate the authentication token (in my issue, an UsernamePasswordAuthenticationToken) in this way:
Code:
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(currentUser.getPrincipal(),currentUser.getCredentials(),(GrantedAuthority[])authorities.toArray(new GrantedAuthority[]{}));
sc.setAuthentication(authentication);
SecurityContextHolder.setContext(sc);
Now, the changes will be available every time you need it.