Ok, so disabling authentication from authorization, as mentioned in a Samuel post, was really helpful. However, there are still a lot of errors, and I found that deauthentication is still necessary, because in spring there is no easy way to add a user to new roles. Thus, the easiest way is to force the user to log in again and let spring perform role assignment at the time of logging in.
spring , :
SecurityContextHolder.clearContext();
UserDetailsService (. ). , , openid . . , .
(), UserDetailsService, , - , :
public final class MyUserDetailsService implements UserDetailsService {
private final UsersDao usersDao;
@Autowired
public UserDetailsServiceImpl(final UsersDao usersDao) {
this.usersDao = usersDao;
}
@Override
public UserDetails loadUserByUsername(final String username) {
UserEntity user = usersDao.getUserByOpenIdIdentifier(username);
if (user == null) {
return new User(username, "", new ArrayList<GrantedAuthority>());
}
final Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
authorities.add(new SimpleGrantedAuthority(user.getUserType().toString()));
final UserDetails result = new User(username, "", authorities);
return result;
}
}