【发布时间】:2015-03-07 04:45:33
【问题描述】:
嗨,在 Spring mvc 3 和 Spring Security 3 中有一个应用程序。碰巧我决定提升一个用户(我有一个包含 user、role 和 user_role 表的数据库),但是当我将新角色添加到数据库时,问题就来了,如何在不注销用户的情况下更新主要权限?寻找答案我发现了这个:
// update database with new role
//... you fill in this part
// update the current Authentication
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority> (auth.getAuthorities());
authorities.add(new GrantedAuthorityImpl('ROLE_NEWROLE'));
Authentication newAuth = new UsernamePasswordToken(auth.getPrincipal(),auth.getCredentials(),authorities)
SecurityContextHolder.getContext().setAuthentication(newAuth);
现在,这种方法看起来不错,但我的问题是,鉴于 securitycontextholder 检索与调用他的当前用户有关的信息,我如何从我的管理员帐户将上述代码应用于系统中的每个用户? 我正在使用自己的身份验证提供程序。
【问题讨论】: