实例:

spring-shiro.xml

				/admin/repairType/index = roles["ROLE_ADMIN"]
/admin/user=roles["ROLE_ADMIN"]
/admin/complaint/list= roles["ROLE_SERVICE,ROLE_ADMIN"]

jsp页面:

            <shiro:hasRole name="ROLE_ADMIN">
<li class="user"><a href="${ctx}/admin/user">用户</a></li>
</shiro:hasRole>
<shiro:hasAnyRoles name="ROLE_ADMIN,ROLE_SERVICE">
<li class="complaint"><a href="${ctx}/admin/complaint/list">服务</a></li>
</shiro:hasAnyRoles>
<shiro:hasRole name="ROLE_ADMIN">
<li class="system"><a href="${ctx}/admin/repairType/index">系统设置</a></li>
</shiro:hasRole>

  

在使用Shiro标签库前,首先需要在JSP引入shiro标签:

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

  

1、介绍Shiro的标签guest标签 :验证当前用户是否为“访客”,即未认证(包含未记住)的用户。

<shiro:guest>  

Hi there!  Please <a href="login.jsp">Login</a> or <a href="signup.jsp">Signup</a> today!  

</shiro:guest>

  

2、user标签 :认证通过或已记住的用户。

<shiro:user>  

    Welcome back John!  Not John? Click <a href="login.jsp">here<a> to login.  

</shiro:user>

  

3、authenticated标签 :已认证通过的用户。不包含已记住的用户,这是与user标签的区别所在。

<shiro:authenticated>  

    <a href="updateAccount.jsp">Update your contact information</a>.  

</shiro:authenticated>

  

4、notAuthenticated标签 :未认证通过用户,与authenticated标签相对应。与guest标签的区别是,该标签包含已记住用户。

<shiro:notAuthenticated>  

    Please <a href="login.jsp">login</a> in order to update your credit card information.  

</shiro:notAuthenticated>

  

5、principal 标签 :输出当前用户信息,通常为登录帐号信息。

Hello, <shiro:principal/>, how are you today?

  

6、hasRole标签 :验证当前用户是否属于该角色。

<shiro:hasRole name="administrator">  

    <a href="admin.jsp">Administer the system</a>  

</shiro:hasRole>

  

7、lacksRole标签 :与hasRole标签逻辑相反,当用户不属于该角色时验证通过。

<shiro:lacksRole name="administrator">  

    Sorry, you are not allowed to administer the system.  

</shiro:lacksRole>

  

8、hasAnyRole标签 :验证当前用户是否属于以下任意一个角色。

<shiro:hasAnyRoles name="developer, project manager, administrator">  

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

</shiro:lacksRole>

  

9、hasPermission标签 :验证当前用户是否拥有指定权限。

<shiro:hasPermission name="user:create">  

    <a href="createUser.jsp">Create a new User</a>  

</shiro:hasPermission>

10、lacksPermission标签 :与hasPermission标签逻辑相反,当前用户没有制定权限时,验证通过。

<shiro:hasPermission name="user:create">  

    <a href="createUser.jsp">Create a new User</a>  

</shiro:hasPermission>

  

  

shiro权限验证标签的更多相关文章

  1. Shiro权限验证代码记录,正确找到shiro框架在什么地方做了权限识别

    权限验证方式的验证代码: org.apache.shiro.web.servlet.AdviceFilter这个类是所有shiro框架提供的默认权限验证实例类的父类 验证代码: public void ...

  2. Shiro权限验证说明

    1.简介 shiro是一个安全框架,是Apache的一个子项目.shiro提供了:认证.授权.加密.会话管理.与web集成.缓存等模块. 1.1.模块介绍 Authentication:用户身份识别, ...

  3. SpringBoot整合Apache Shiro权限验证框架

    比较常见的权限框架有两种,一种是Spring Security,另一种是Apache Shiro,两种框架各有优劣,个人感觉Shiro更容易使用,更加灵活,也更符合RABC规则,而且是java官方更推 ...

  4. 关于postman与shiro权限验证问题

    作为一个java的开发小白 , 写完一个web方法测试是必不可少的 , 只有测试号没问题的方法给别人时 ,别人才不知道你是小白 , 要不然很尴尬的 .新手入坑的测试工具是postman .这个工具用起 ...

  5. 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)

    前言: shiro因为其简单.可靠.实现方便而成为现在最常用的安全框架,那么这篇文章除了会用简洁明了的方式讲一下基于spring的shiro详细配置和登录注销功能使用之外,也会根据惯例在文章最后总结一 ...

  6. Shiro 权限标签

    Shiro 权限标签: 导入标签库: <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" ...

  7. 自定义shiro实现权限验证方法isAccessAllowed

    由于Shiro filterChainDefinitions中 roles默认是and, admin= user,roles[system,general] 比如:roles[system,gener ...

  8. shiro登陆权限验证

    一>引入shirojar包 <!-- shiro登陆权限控制 -->        <dependency>            <groupId>org. ...

  9. shiro权限管理框架与springmvc整合

    shiro是apache下的一个项目,和spring security类似,用于用户权限的管理‘ 但从易用性和学习成本上考虑,shiro更具优势,同时shiro支持和很多接口集成 用户及权限管理是众多 ...

随机推荐

  1. Redis - list类型操作

    list类型操作 设置操作:lpush:    lpush key value            在list左侧插入value rpush:    rpush key value          ...

  2. (Your)((Term)((Project)))

    Description You have typed the report of your term project in your personal computer. There are seve ...

  3. GIT之二 基础篇(2)

    远程仓库的使用 要参与任何一个 Git 项目的协作,必须要了解该如何管理远程仓库.远程仓库是指托管在网络上的项目仓库,可能会有好多个,其中有些你只能读,另外有些可以写.同他人协作开发某个项目时,需要管 ...

  4. Web Browser使用技巧

    无论是在桌面级开发中,还是在手机端开发中,WebBrowser都是一个经常会用到的控件.Windows Phone中的WebBrowser虽然远远没有桌面版那么强大,但依然足够应付常规用途.本文就来介 ...

  5. 搭建 hexo,在执行 hexo deploy 后,出现 error deployer not found:github 的错误

    hexo 更新到3.0之后,deploy的type 的github需要改成git 改了之后执行npm install hexo-deployer-git --save 然后再部署试试 官网说明: ht ...

  6. Windows上的文件合并命令

    从Linux转到Windowns后,发现很多好用的shell命令都没有了,但实际情况是Windows一样有DOS时代的命令窗口,在CLI年代用DOS的人也要干活. 比如,今天想将几个单独的sql文件整 ...

  7. map的相关

    private static final Map<String, String> flagMap = new HashMap<String, String>(); static ...

  8. 图像特征提取三大法宝:HOG特征,LBP特征,Haar特征(转载)

    (一)HOG特征 1.HOG特征: 方向梯度直方图(Histogram of Oriented Gradient, HOG)特征是一种在计算机视觉和图像处理中用来进行物体检测的特征描述子.它通过计算和 ...

  9. codeforces 192 D

    link: http://codeforces.com/contest/330/problem/D The discription looks so long, but the problem is ...

  10. Vigenère 密码NOIP 2012 提高组 第一天 第一题

    题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南 ...