Shiro標簽使用實例
阿新 • • 發佈:2017-11-21
please prefix 一個 tag lai efi asa pla nta
shiro.xml
/admin/repairType/index = roles["ROLE_ADMIN"]
/admin/user=roles["ROLE_ADMIN"]
/admin/complaint/list= roles["ROLE_SERVICE,ROLE_ADMIN"]
在使用Shiro標簽庫前,首先需要在JSP引入shiro標簽: <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
-
guest標簽 :驗證當前用戶是否為“訪客”,即未認證(包含未記住)的用戶
<shiro:guest> Hi there! Please
- user標簽 :認證通過或已記住的用戶
<shiro:user> Welcome back John! Not John? Click <a href="login.jsp">here<a> to login. </shiro:user>
- authenticated標簽 :已認證通過的用戶。不包含已記住的用戶,這是與user標簽的區別所在
<
- notAuthenticated標簽 :未認證通過用戶,與authenticated標簽相對應。與guest標簽的區別是,該標簽包含已記住用戶
<shiro:notAuthenticated> Please <a href="login.jsp">login</a>
- principal 標簽 :輸出當前用戶信息,通常為登錄帳號信息
Hello, <shiro:principal/>, how are you today?
- hasRole標簽 :驗證當前用戶是否屬於該角色
<shiro:hasRole name="administrator"> <a href="admin.jsp">Administer the system</a> </shiro:hasRole>
- lacksRole標簽 :與hasRole標簽邏輯相反,當用戶不屬於該角色時驗證通過
<shiro:lacksRole name="administrator"> Sorry, you are not allowed to administer the system. </shiro:lacksRole>
- hasAnyRole標簽 :驗證當前用戶是否屬於以下任意一個角色
<shiro:hasAnyRoles name="developer, project manager, administrator"> You are either a developer, project manager, or administrator. </shiro:lacksRole>
- hasPermission標簽 :驗證當前用戶是否擁有指定權限
<shiro:hasPermission name="user:create"> <a href="createUser.jsp">Create a new User</a> </shiro:hasPermission>
- lacksPermission標簽 :與hasPermission標簽邏輯相反,當前用戶沒有制定權限時,驗證通過
<shiro:hasPermission name="user:create"> <a href="createUser.jsp">Create a new User</a> </shiro:hasPermission>
Shiro標簽使用實例