相關SpringSecurity對於部分菜單隱藏的相關代碼

  1. <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>   
  2.   
  3. <sec:authorize ifAllGranted="ROLE_ADMIN,ROLE_USER">   
  4.   admin and user   
  5. </sec:authorize>   
  6.   
  7. <sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_USER">   
  8.   admin or user   
  9. </sec:authorize>   
  10.   
  11. <sec:authorize ifNotGranted="ROLE_ADMIN">   
  12.   not admin   
  13. </sec:authorize>   
  14.        
  15. ifAllGranted,只有當前用戶同時擁有ROLE_ADMIN和ROLE_USER兩個權限時,才能顯示標籤內部內容。   
  16. ifAnyGranted,如果當前用戶擁有ROLE_ADMIN或ROLE_USER其中一個權限時,就能顯示標籤內部內容。   
  17. ifNotGranted,如果當前用戶沒有ROLE_ADMIN時,才能顯示標籤內部內容。   
  18.   
  19. <sec:accesscontrollist domainObject="${item}" hasPermission="8,16">   
  20.       <a href="message.do?action=remove&id=${item.id}">Remove</a>   
  21. </sec:accesscontrollist>   
  22.   
  23. 我們將當前顯示的對象作爲參數傳入acl標籤,然後指定判斷的權限爲8(刪除)和16(管理),當前用戶如果擁有對這個對象的刪除和管理權限時,就會顯示對應的remove超鏈接,用戶纔可以通過此鏈接對這條記錄進行刪除操作。  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章