當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
java实时更新权限_java – 如何使用Spring Security重新加载用户更新的权限
生活随笔
收集整理的這篇文章主要介紹了
java实时更新权限_java – 如何使用Spring Security重新加载用户更新的权限
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如果您需要動態更新登錄的用戶權限(當這些權限發生變化時,無論什么原因),無需登出并登錄,您只需要重置Spring SecurityContextHolder中的Authentication對象(安全令牌)即可.
例:
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List updatedAuthorities = new ArrayList<>(auth.getAuthorities());
updatedAuthorities.add(...); //add your role here [e.g., new SimpleGrantedAuthority("ROLE_NEW_ROLE")]
Authentication newAuth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), updatedAuthorities);
SecurityContextHolder.getContext().setAuthentication(newAuth);
總結
以上是生活随笔為你收集整理的java实时更新权限_java – 如何使用Spring Security重新加载用户更新的权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java填空题 在非静态成员方法中_Ja
- 下一篇: oracle删除orcl库_oracle