shiro許可權驗證標籤

2022-02-26 16:16:14 字數 2894 閱讀 7149

例項:

spring-shiro.xml12

3/admin/repairtype/index = roles["role_admin"]

/admin/user=roles["role_admin"]

/admin/complaint/list= roles["role_service,role_admin"]

jsp頁面:12

3456

789<shiro:hasrolename="role_admin">

<liclass="user"><ahref="$/admin/user">使用者

<shiro:hasanyrolesname="role_admin,role_service">

<liclass="complaint"><ahref="$/admin/complaint/list">服務

<shiro:hasrolename="role_admin">

<liclass="system"><ahref="$/admin/repairtype/index">系統設定

在使用shiro標籤庫前,首先需要在jsp引入shiro標籤: 

1<%@ taglib prefix="shiro"uri=""%>

1、介紹shiro的標籤guest標籤 :驗證當前使用者是否為「訪客」,即未認證(包含未記住)的使用者。12

345

hi there!  please login or signup today!

2、user標籤 :認證通過或已記住的使用者。12

345

welcome back john!  not john? click hereto login.

3、authenticated標籤 :已認證通過的使用者。不包含已記住的使用者,這是與user標籤的區別所在。12

345

update your contact information.

4、notauthenticated標籤 :未認證通過使用者,與authenticated標籤相對應。與guest標籤的區別是,該標籤包含已記住使用者。 12

345

please login in order to update your credit card information.

5、principal 標籤 :輸出當前使用者資訊,通常為登入帳號資訊。

1hello, , how are you today?

6、hasrole標籤 :驗證當前使用者是否屬於該角色。12

345

administer the system

7、lacksrole標籤 :與hasrole標籤邏輯相反,當使用者不屬於該角色時驗證通過。12

345

sorry, you are not allowed to administer the system.

8、hasanyrole標籤 :驗證當前使用者是否屬於以下任意乙個角色。 12

345

you are either a developer, project manager, or administrator.

9、haspermission標籤 :驗證當前使用者是否擁有指定許可權。12

345

create anewuser

10、lackspermission標籤 :與haspermission標籤邏輯相反,當前使用者沒有制定許可權時,驗證通過。12

345

create anewuser

shiro許可權驗證標籤

例項 spring shiro.xml 1 2 3 admin repairtype index roles role admin admin user roles role admin admin complaint list roles role service,role admin jsp頁面...

shiro許可權驗證標籤

例項 spring shiro.xml 1 2 3 admin repairtype index roles role admin admin user roles role admin admin complaint list roles role service,role admin jsp頁面...

shiro許可權驗證標籤

例項 spring shiro.xml 1 2 3 admin repairtype index roles role admin admin user roles role admin admin complaint list roles role service,role admin jsp頁面...