shiro注解,初始化资源和权限,会话管理
有具体问题的可以参考之前的关于shiro的博文,关于shiro的博文均是一次工程的内容
注解:

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>
初始化资源和权限
点击看源码可知

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

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;
}
}
<!--
<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注解,初始化资源和权限,会话管理的更多相关文章
- Shiro从数据表中初始化资源和权限
之前在测试的Web工程下,我们在applicationContext.xml中配置了shiroFilter资源拦截器信息: <bean id="shiroFilter" cl ...
- Shiro-从数据表中初始化资源和权限
我们在 applicationContext中配置受保护的资源和权限的关系 <property name="filterChainDefinitions"> <v ...
- Shiro 整合SpringMVC 并且实现权限管理
Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Security做的功能强大 ...
- shiro会话管理
Shiro提供了完整的企业级会话管理功能,不依赖于底层容器(如web容器tomcat),不管JavaSE还是JavaEE环境都可以使用,提供了会话管理.会话事件监听.会话存储/持久化.容器无关的集群. ...
- 第十章 会话管理——《跟我学Shiro》
转发地址:https://www.iteye.com/blog/jinnianshilongnian-2028675 目录贴:跟我学Shiro目录贴 Shiro提供了完整的企业级会话管理功能,不依赖于 ...
- Spring Cloud之路:(七)SpringBoot+Shiro实现登录认证和权限管理
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sage_wang/article/details/79592269一.Shiro介绍1.Shiro是 ...
- Apache Shiro(五)-登录认证和权限管理ssm
创建一个web动态项目 jar包 web.xml web.xml做了如下几件事情1. 指定spring的配置文件有两个 applicationContext.xml: 用于链接数据库的 applica ...
- SpringMVC整合Shiro,Shiro是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理等功能
SpringMVC整合Shiro,Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能. 第一步:配置web.xml <!-- 配置Shiro过滤器,先让Shiro ...
- Shiro集成SSM基于URL权限管理(一)
学习了shiro之后,我们就可以说尝试把shiro加入ssm中,并做一套基于URL的权限管理. 其他的准备工作就不多说了,直接动手操作,看到效果再去理解. 表结构 执行如下,数据库名字可以自行修改,不 ...
随机推荐
- RPA流程自动化-UIPath简介
UiPath简介 转自: http://www.cnblogs.com/mxue/p/UiPath_To147_Road.html 最近RPA比较火,UiPath工具排名前几位并且免费试用,很多朋友们 ...
- 【转】Encrypt ConnectionString in Web.Config 【加密ASP.NET web.config数据库链接字串】
原文链接:https://www.codeproject.com/Tips/795135/Encrypt-ConnectionString-in-Web-Config web.config中一般会存放 ...
- .net IoC 之 Spring.Net 适合刚开始使用
Spring.Net包括控制反转(IoC) 和面向切面(AOP),这篇文章主要说下IoC方面的入门. 一.首先建立一个MVC项目名称叫SpringDemo,然后用NuGet下载spring(我用的是S ...
- JRebel&XRebel
介绍==>>>> JRebel&XRebel官网 https://zeroturnaround.com/HotSwap和JRebel原理 http://www.holl ...
- 最新版PMBOK项目管理的五大过程组和十大知识领域
PMBOK五大过程组是:启动过程.规划过程.执行过程.监控过程.收尾过程. 各用一句话概括项目管理知识体系五大过程组: 1.启动过程组:作用是设定项目目标,让项目团队有事可做: 2.规划过程组:作用是 ...
- 基于Maven的Spring + Spring MVC + Mybatis的环境搭建
基于Maven的Spring + Spring MVC + Mybatis的环境搭建项目开发,先将环境先搭建起来.上次做了一个Spring + Spring MVC + Mybatis + Log4J ...
- MySQL在DOS界面对database和table增删改查
昨天新接触MySQL,学习了一些内容,今天过来复习一下.(吐槽一下:安装个MySQL耗费老子半天时间!!) 学习了一下,大概知道了对数据库基本的增删改查,增add,删drop,改alter,查show ...
- 解决Maven 报 Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 2.1.0.RELEASE. 的错误
最近在搭建公司的基础框架,业务需求用到elasticsearch,所以需要整合到基础框架里,供各业务线使用同时也便于管理,但在整合的过程中,出现了莫名的问题,同时maven的提示也不够明确. 我的版本 ...
- qt 创建资源文件
我们编写的gui可能需要一些额外的资源(比如贴图用的图片),可用资源文件统一管理.以下以图片为例. 用qt creator 打开工程,为工程新建资源文件: 命名为“项目名.prc”,(此处为“cloc ...
- Java基础之this关键字的作用
this关键字主要存在三种应用 1.this调用本类中的属性,也就是说调用类中的成员变量: 2.this调用本类中的其他方法: 3.this调用本类中的其他构造方法,调用时要放在构造方法的首行,否则会 ...