更新時間:2022-02-08 10:31:48 來源:動力節(jié)點 瀏覽979次
Shiro 為 JSP 頁面的權(quán)限控制提供了一個 JSTL 標(biāo)簽:
1.GUEST標(biāo)簽:用戶無身份驗證信息顯示,相當(dāng)于旅游模式
<shiro:guest><br>Visitor mode, please log in: <a href="..."> login </A><br><shiro:guest>
2.用戶標(biāo)簽:用戶已經(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:用戶沒有認(rèn)證,沒有調(diào)用Subject.login
包括記住我登錄也屬于未認(rèn)證
<shiro:notAuthenticated>
沒有認(rèn)證(包括“記住我” )
</shiro:notAuthenticated>
5.principal :顯示用戶身份信息Subject.getPrincipal(),主principal,默認(rèn)為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/> ] 擁有特權(quán)用戶: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/> ] 無權(quán)限 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>
</正文>
使用用戶登錄:
使用管理員登錄:
以上就是關(guān)于“Shiro標(biāo)簽的用法示例”的介紹,大家如果想了解更多相關(guān)知識,不妨來關(guān)注一下動力節(jié)點的Shiro視頻教程,里面的課程內(nèi)容細(xì)致全面,由淺到深,適合沒有基礎(chǔ)的小白學(xué)習(xí),希望對大家能夠有所幫助。
初級 202925
初級 203221
初級 202629
初級 203743