专注Java教育14年 全国咨询/投诉热线:444-1124-454
赢咖4LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 Shiro标签的用法示例

Shiro标签的用法示例

更新时间:2022-02-08 10:31:48 来源:赢咖4 浏览612次

Shiro 为 JSP 页面的权限控制提供了一个 JSTL 标签:

1.GUEST标签:用户无身份验证信息显示,相当于旅游模式

<shiro:guest><br>Visitor mode, please log in: <a href="..."> login </A><br><shiro:guest>

2.用户标签:用户已经识别登录后显示/记住我

<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:用户没有认证,没有调用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标签的用法示例”的介绍,大家如果想了解更多相关知识,不妨来关注一下赢咖4的Shiro视频教程,里面的课程内容细致全面,由浅到深,适合没有基础的小白学习,希望对大家能够有所帮助。

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>