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的权限管理. 其他的准备工作就不多说了,直接动手操作,看到效果再去理解. 表结构 执行如下,数据库名字可以自行修改,不 ...
随机推荐
- Spring学习笔记:Spring动态组装打印机
一.如何开发一个打印机 1.可灵活配置使用彩色魔盒或灰色魔盒 2.可灵活配置打印页面的大小 二.打印机功能的实现依赖于魔盒和纸张 三.步骤: 1.定义墨盒和纸张的接口标准 package cn.pri ...
- 对Mybatis的初步认识
1.认识Mybatis MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索. MyBat ...
- Filter内容
1.利用Filter来过滤的时候大都是Http请求和Http响应,在doFilter()方法中,参数类是ServletRequest和ServletResponse ,使用的时候一般需要强制转换为H ...
- Oracle自定义函数&加密
在sql中频繁使用的功能(逻辑.加密等)可以写成自定义函数进行封装,之后再调用即可. CREATE OR REPLACE FUNCTION "函数名" (参数名 参数类型 参数数据 ...
- PHP三维优先级运算
昨天去某大型公司面试,做了一套面试题,整套面试题的基础要求比较高,对于js的使用有一定的要求.在本次面试中碰到PHP三维运算优先级的问题,先看题: <?php $b=20; $c=40; $a= ...
- enter键触发事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SQL COUNT DISTINCT
Create table trade ( sell_id int, --卖家 buy_id int, -- 卖家 time date --交易时间 ) sell_id, buy_id, time s ...
- Bzoj1498&1416: [NOI2006]神奇的口袋
什么鬼双倍经验题??? Sol 考虑在第\(k\)次摸到\(y\)的概率 如果上次摸到\(y\),目前有\(sum\)个球,\(y\)有\(a[y]\)个,那么概率就是\(\frac{a[y]+d}{ ...
- Bzoj3105:[CQOI2013]新Nim游戏
题面 传送门 Sol 也是拿出一些数,使剩下的异或起来不为\(0\) 而线性基内的数异或不出\(0\) 那么从大到小加到线性基内 然后中途为\(0\)了,就取走它 这样我们使最大的在线性基内,剩下的是 ...
- FCKeditor 添加行距、字体功能 (转载)
一.首先为FCKeditor添加外部插件在fckeditor/editor/plugins文件夹下建立新文件夹lineHeight,并在其中创建fckplugin.js文件,在其文件中办輸入代码:FC ...