更新時間:2022-02-08 10:31:48 來源:動力節(jié)點 瀏覽885次
Shiro 為 JSP 頁面的權限控制提供了一個 JSTL 標簽:
1.GUEST標簽:用戶無身份驗證信息顯示,相當于旅游模式
<shiro:guest><br>Visitor mode, please log in: <a href="..."> login </A><br><shiro:guest>
2.用戶標簽:用戶已經(jīng)識別登錄后顯示/記住我
<shiro:user><br>Congratulations <shiro: principal /> has been successfully logged in!<br><shiro:user>
3.Authenticated Tags:用戶已驗證通過,不記得我登陸
<shiro:authenticated>
恭喜<shiro:principal/>驗證
<shiro:authenticated>
4.Notauthenticated:用戶沒有認證,沒有調(diào)用Subject.login
包括記住我登錄也屬于未認證
<shiro:notAuthenticated>
沒有認證(包括“記住我” )
</shiro:notAuthenticated>
5.principal :顯示用戶身份信息Subject.getPrincipal(),主principal,默認為PRIMARY PRINCIPAL
<shiro:principal property= "用戶名" />
6.HASROLLE Tags: If the current Subject has a character will display content in a body
<shiro:hashRole name = " admin " >
user[ <shiro:principal/> ] 有一個角色 admin
</shiro:hashRole>
7.hasanyroles Tags: If Subject has anyOneCharacter(Relationship) Will display content in the body body
<shiro:hasAnyRoles name = " admin,user " >
user[ <shiro:pricipal/> ] 擁有角色 admin 或 user
</shiro:hasAnyRoles>
8.Lacksrole: If the current Subjec does not have a character, the contents of the body will be displayed.
<shiro:lacksRole name = " admin " >
user[ <shiro:pricipal/> ] 沒有角色 admin </br>
</shiro:lacksRole>
9.Hashpermission: If the currentSubjectPermissionShow body content
<shiro:hashPermission name = " user:create " >
user[ <shiro:pricipal/> ] 擁有特權用戶:Create
</shiro:hashPermission>
10.lackspermission: If the current Subject does not have permission, a body content will be displayed
<shiro:lacksPermission name = " org:create " >
user[ <shiro:pricipal/> ] 無權限 Org: CREATE
</shiro:lacksPermission>
在 list.jsp 文件中:
<正文>
列表。
歡迎:<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 " >注銷</a>
</正文>
使用用戶登錄:
使用管理員登錄:
以上就是關于“Shiro標簽的用法示例”的介紹,大家如果想了解更多相關知識,不妨來關注一下動力節(jié)點的Shiro視頻教程,里面的課程內(nèi)容細致全面,由淺到深,適合沒有基礎的小白學習,希望對大家能夠有所幫助。