2012-02-23 38 views

Trả lời

21

Kể từ principal đề cập đến đối tượng UserDetails của bạn, nếu bạn kiểm tra đối tượng đó, vai trò được lưu trữ dưới public Collection<GrantedAuthority> getAuthorities() { .. }.

Điều đó nói rằng, nếu bạn chỉ muốn in các vai trò trên màn hình, làm như sau: -

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

Sử dụng getAuthorities hoặc viết triển khai của riêng bạn của userdetails và tạo ra một phương pháp thuận tiện.

hay:

<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> 

từ here.

+0

làm thế nào để sử dụng getAuthorities từ jsp? – Rajesh

+0

chỉ cần sử dụng quy ước đậu nromal: NimChimpsky

+0

Url không hoạt động ngay bây giờ. –

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

Một số chi tiết nhỏ đi một chặng đường dài ... –

Các vấn đề liên quan