shiro標籤
有具體問題的可以參考之前的關於shiro的博文,關於shiro的博文均是一次工程的內容 !
shiro標籤:
Shiro提供了STL/">JSTL標籤用於在JSP頁面進行許可權控制:
1.guest標籤:使用者 沒有 身份 驗證 時顯示的資訊,相當於遊客模式
<shiro:guest> 遊客模式,請進行登陸:<a href="...">登陸</a> <shiro:guest>
2.user標籤:使用者 已經認 證登陸後的顯示/ 記住我
<shiro:user> 恭喜<shiro:principal/>已經成功登陸! <shiro:user>
3.authenticated標籤:使用者已經驗證通過, 不是記住我登陸的
<shiro:authenticated> 恭喜<shiro:principal/>已驗證通過 <shiro:authenticated>
4.notAuthenticated:使用者未進行身份驗證,沒有呼叫Subject.login進行登陸
包括記住我自動登陸 的也屬於未進行身份驗證
<shiro:notAuthenticated> 未身份驗證(包括"記住我") </shiro:notAuthenticated>
5.principal : 顯示使用者身份資訊 ,預設呼叫Subject.getPrincipal(),即Primary Principal
<shiro:principal property="username" />
6. hasRole標籤:如果當前Subject有角色將顯示body體內的內容
<shiro:hashRole name = "admin"> 使用者[<shiro:principal/>]擁有角色admin </shiro:hashRole>
7.hasAnyRoles標籤:如果Subject有任意一個角色(或的關係)將顯示body體裡的內容
<shiro:hasAnyRoles name = "admin,user"> 使用者[<shiro:pricipal/>]擁有角色admin 或者 user </shiro:hasAnyRoles>
8. lacksRole:如果當前 Subjec沒有角色將顯示body體內的內容
<shiro:lacksRole name = "admin"> 使用者[<shiro:pricipal/>]沒有角色admin</br> </shiro:lacksRole>
9.hashPermission:如果當前Subject有許可權將顯示body體內容
<shiro:hashPermission name = "user:create"> 使用者[<shiro:pricipal/>] 擁有許可權user:create </shiro:hashPermission>
10.lacksPermission:如果當前Subject沒有許可權將顯示body體內容
<shiro:lacksPermission name = "org:create"> 使用者[<shiro:pricipal/>] 沒有許可權org:create </shiro:lacksPermission>
在list.jsp檔案中:
<body> list. welcome:<shiro:principal></shiro:principal> <shiro:hasRole name="admin"> <a href="admin.jsp">TO Admin</a> </shiro:hasRole> <shiro:hasRole name="user"> <a href="user.jsp">TO User</a> </shiro:hasRole> <a href="shiro/logout">Logout</a> </body>
使用user登陸:
使用admin登陸: