2012-02-23 57 views

回答

21

由於principal指的是您的UserDetails對象,如果您檢查該對象的角色存儲在public Collection<GrantedAuthority> getAuthorities() { .. }下。

這就是說,如果你只是想打印屏幕上的角色,這樣做: -

<sec:authentication property="principal.authorities"/> 
18

使用getAuthorities或編寫自己的userdetails實現並創建一個方便的方法。

或:

<sec:authorize access="hasRole('supervisor')"> 
This content will only be visible to users who have 
the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s. 
</sec:authorize> 

here

+0

如何使用getAuthorities從JSP? – Rajesh 2012-02-23 13:38:44

+0

只使用nromal bean約定: NimChimpsky 2012-02-23 13:47:29

+0

該網址現在不起作用。 – 2017-08-28 15:49:45

3
<sec:authentication property="principal.authorities" var="authorities" /> 
<c:forEach items="${authorities}" var="authority" varStatus="vs"> 
<p>${authority.authority}</p> 
</c:forEach> 
+0

有一點細節很長...... – 2016-04-09 07:06:10