2012-02-23 78 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

相关问题