簡體   English   中英

Spring Security Web檢查當前經過身份驗證的用戶是否具有角色

[英]Spring security web check if currently authenticated user has role

我如何檢查當前通過身份驗證的用戶是否具有特定角色?

我發現舊版本的春季安全的一些較老的解決方案,但在春天當前版本中它不工作,所以我在尋找像一個解決方案這樣 ,但在spring-boot-starter-security版本1.5.2

驗證權限長度是否大於0:

Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder.getContext().getAuthentication().getAuthorities() ;

然后與您的角色比較(如果他有角色)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM