簡體   English   中英

使用Spring Security檢索記錄的用戶組

[英]Retrieving logged user group(s) with Spring Security

我正在使用Spring Security來改善對Web應用程序的訪問。 一切正常,但我需要檢索包含我的用戶的用戶組。 我已經在安全性xml中實現了JdbcDaoImpl bean,並且設置了屬性groupAuthoritiesByUsernameQuery並允許按用戶組進行查詢。 因此,該應用程序登錄! 但是我不知道該如何組隊。 我需要類似的東西:SecurityContextHolder.getContext()。getGroups()...謝謝!

您可以使用以下代碼來返回GrantedAuthority列表

List<GrantedAuthority> grantedAuthorities = SecurityContextHolder.getContext()
                                            .getAuthentication()
                                            .getAuthorities()

GrantedAuthority.getAuthority()將返回您的角色。

暫無
暫無

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

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