有具体问题的可以参考之前的关于shiro的博文,关于shiro的博文均是一次工程的内容 

注解:

新建一个类:
此时需要有admin的权限才可以执行下面的代码
public class ShiroService {

     @RequiresRoles({"admin"})
public void testMethod(){
System.out.println("test。。。。。");
}
}

把新建的类注入到spring容器中

 <bean  class="com.MrChengs.shiro.service.ShiroService"></bean>

ShiroHandler .java中加入

@Controller
@RequestMapping("/shiro")
public class ShiroHandler { @Autowired
private ShiroService shiroService; @RequestMapping("/testMethod")
public String testMethod(){
shiroService.testMethod();
return "redirect:/list.jsp"
;
}

....
}

list.jsp中加入测试超链接

  <a href="shiro/testMethod">Test Method</a>
 
此时我们登陆admin可以成功测试
 
当我们登陆user再点击测试的时候
UnauthorizedException

 初始化资源和权限

点击看源码可知

其配置的文件的内容最终被封装成一个map

新建一个初始化文件的类:
在map的方法体里面可以写我们需要在数据库中查询等代码
LinkedHashMap一定是这个
package com.MrChengs.shiro.Factory;
import java.util.LinkedHashMap;
public class FilterChainDefinitionMapperBUilder {
public LinkedHashMap<String, String> builderFilterChainDefinitionMap(){
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
map.put("/login.jsp", "anon");
map.put("/shiro/login", "anon");
map.put("/shiro/logout", "logout");
map.put("/user.jsp", "roles[user]");
map.put("/admin.jsp", "roles[admin]");
map.put("/**", "authc");
return
map;
}
}
在application中:
把注释的地方替换成红色标准的地方
  <!--
<property name="filterChainDefinitions">
<value>
/login.jsp = anon
/shiro/login = anon
/shiro/logout = logout
/user.jsp = roles[user]
/admin.jsp = roles[admin]
# everything else requires authentication:
/** = authc
</value>
</property>
-->
<property name="filterChainDefinitionMap" ref="filterIniDef"></property>
    <!-- 配置一个bean,实际上是一个map,实例通过工厂模式的方法 -->
<bean id="filterIniDef" factory-bean="filterChainDefinitionMapperBUilder"
factory-method="builderFilterChainDefinitionMap"></bean> <bean id="filterChainDefinitionMapperBUilder" class="com.MrChengs.shiro.Factory.FilterChainDefinitionMapperBUilder"></bean>

其余不变测试时没有任何问题的!!!

 会话管理

测试如下

shiro注解,初始化资源和权限,会话管理的更多相关文章

  1. Shiro从数据表中初始化资源和权限

    之前在测试的Web工程下,我们在applicationContext.xml中配置了shiroFilter资源拦截器信息: <bean id="shiroFilter" cl ...

  2. Shiro-从数据表中初始化资源和权限

    我们在 applicationContext中配置受保护的资源和权限的关系 <property name="filterChainDefinitions"> <v ...

  3. Shiro 整合SpringMVC 并且实现权限管理

    Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Security做的功能强大 ...

  4. shiro会话管理

    Shiro提供了完整的企业级会话管理功能,不依赖于底层容器(如web容器tomcat),不管JavaSE还是JavaEE环境都可以使用,提供了会话管理.会话事件监听.会话存储/持久化.容器无关的集群. ...

  5. 第十章 会话管理——《跟我学Shiro》

    转发地址:https://www.iteye.com/blog/jinnianshilongnian-2028675 目录贴:跟我学Shiro目录贴 Shiro提供了完整的企业级会话管理功能,不依赖于 ...

  6. Spring Cloud之路:(七)SpringBoot+Shiro实现登录认证和权限管理

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sage_wang/article/details/79592269一.Shiro介绍1.Shiro是 ...

  7. Apache Shiro(五)-登录认证和权限管理ssm

    创建一个web动态项目 jar包 web.xml web.xml做了如下几件事情1. 指定spring的配置文件有两个 applicationContext.xml: 用于链接数据库的 applica ...

  8. SpringMVC整合Shiro,Shiro是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理等功能

    SpringMVC整合Shiro,Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能. 第一步:配置web.xml <!-- 配置Shiro过滤器,先让Shiro ...

  9. Shiro集成SSM基于URL权限管理(一)

    学习了shiro之后,我们就可以说尝试把shiro加入ssm中,并做一套基于URL的权限管理. 其他的准备工作就不多说了,直接动手操作,看到效果再去理解. 表结构 执行如下,数据库名字可以自行修改,不 ...

随机推荐

  1. Silverlight & Blend动画设计系列六:动画技巧(Animation Techniques)之对象与路径转化、波感特效

    当我们在进行Silverlight & Blend进行动画设计的过程中,可能需要设计出很多效果不一的图形图像出来作为动画的基本组成元素.然而在设计过程中可能会出现许多的问题,比如当前绘制了一个 ...

  2. 在ASP.NET CORE中启用favicon.ico

    在静态页面中添加网站标志只需在<head>标签中添加<link rel="shortcut icon" href="favicon.ico" ...

  3. pdf OCR

    pdf转word等其他可排版编辑格式的软件: ABBYY Finereader: 老牌OCR软件了,支持各种文字.图片.表格的识别,效率比较高,中文的识别效果也很好,公式的转换效率较差. InftyR ...

  4. docker 安装ElasticSearch head

    github官网地址 https://github.com/mobz/elasticsearch-head 拉取镜像 docker pull mobz/elasticsearch-head:5 创建容 ...

  5. AMD 规范与CMD 规范概要

    命名冲突和文件依赖,是前端开发过程中的两个经典问题.通过模块化开发来解决. AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMD CMD 规范在这 ...

  6. inline-block和float的区别,什么时候使用

    文章转载于新浪博客http://blog.sina.com.cn/s/blog_5f39af320101qckt.html 只用于学习交流 什么时候使用inline-block,什么时候使用float ...

  7. 通过JavaScript创建Qml对象

    有两种方法可以创建,都是全局对象Qt提供的方法 一:用Qt.createComponent加载一个qml文件并创建Component 二:用Qt.createQmlObject从一个qml字符串创建C ...

  8. Java—IO流 对象的序列化和反序列化

    序列化的基本操作 1.对象序列化,就是将Object转换成byte序列,反之叫对象的反序列化. 2.序列化流(ObjectOutputStream),writeObject 方法用于将对象写入输出流中 ...

  9. Windows下sc create命令行添加/创建/修改服务

    添加服务: sc create TestService binpath= "D:\TestApp\TestService.exe" 注意:所有的等号和值之间需要一个空格(等号前不要 ...

  10. 【Leetcode】【Easy】Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...