实例:

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. post&get请求总结

    1.将get获取的数据,UrlDecode后返回 public static string SendGet(string url) { HttpWebRequest httpWebRequest = ...

  2. SWUST0249 (凸包面积)

    type node=record x,y:longint; end; ; var k,q,qq:longint; sum:double; f,g:..maxn] of node; m,i,j,a,b: ...

  3. Inno Setup的常用脚本

    Inno Setup的常用脚本 分类: VC++神奇理论 2012-12-06 10:07 3234人阅读 评论(2) 收藏 举报 安装不同的目录: [Files] Source: "我的程 ...

  4. 锋利的jquery学习笔记

    1.$("#tt")获取的永远都是一个jquery对象,所以要判断页面上是否存在某个对象不能像js中 if($("#tt")){ } 而是通过: ){ } ps ...

  5. Magento后台Grid删除Add New按钮

    开发过包含后台Grid及表等Magento完整模块的朋友应该知道,默认的,在Magento后台Grid右上方都会包含一个Add New按钮,用来添加新的item.但有些情况我们也可能不需要这个Add ...

  6. VundleVim的安装与使用

    git:https://github.com/VundleVim/Vundle.vim vundle是一款vim编辑器的插件管理软,用起来很方便的原因有几点: 1)只要知道插件名称,就能搜索到并下载安 ...

  7. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  8. 《JS高程》JS-Object对象整理

    继上篇<JS高程>对象&原型笔记,对JavaScript中的Object对象进行了整理,梳理一遍~ 参考文章:详解Javascript中的Object对象 ------------ ...

  9. dedecms SQL数据库连接信息注解(借鉴)

    <?php $cfg_dbhost = 'localhost'; //数据库地址,这里的localhost指的是本机$cfg_dbname = 'hunuo'; //数据库名$cfg_dbuse ...

  10. postgresql存储二进制大数据文件

    如果想把整个文件或图片存储在数据表的一个字段内,该字段可以选择二进制类型,然后将文件按二进制存储起来,文本文件也可以存在text字段内. 示例如下: 二进制类型bytea的操作(在最大值内,有内存限制 ...