spring-shiro 配置
配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- realm -->
<bean id="userRealm" class="ch.entity.user.UserRealm">
<constructor-arg index="0" name="matcher" ref="credentialsMatcher"/>
<!-- 打开缓存 -->
<property name="cachingEnabled" value="true"/> <!-- 启用身份验证缓存,即缓存AuthenticationInfo信息,默认false -->
<property name="authenticationCachingEnabled" value="true"/>
<!-- 打开授权缓存 -->
<property name="authorizationCachingEnabled" value="true"/>
<!-- 缓存AuthenticationInfo信息的缓存名称 -->
<property name="authenticationCacheName" value="authenticationCache"/>
<!-- 缓存AuthorizationInfo信息的缓存名称 -->
<property name="authorizationCacheName" value="authorizationCache"/>
</bean>
<!---cookie-->
<!-- uid(session id) 生成策略 -->
<bean id="sessionIdGenerator" class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/> <!-- 记住密码Cookie -->
<bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
<constructor-arg value="rememberMe"/>
<property name="httpOnly" value="true"/>
<property name="maxAge" value="#{7 * 24 * 60 * 60}"/>
</bean> <!-- sesisonCookie 设置 -->
<bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
<!-- cookie的名字 -->
<constructor-arg value="sessionIdCookie"/>
<property name="httpOnly" value="true"/>
<!-- 30分钟 单位是秒-->
<property name="maxAge" value="1800"/>
</bean> <!-- rememberMe管理器,cipherKey生成见{@code Base64Test.java} cookie加密的秘钥-->
<bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
<property name="cipherKey"
value="#{T(org.apache.shiro.codec.Base64).decode('5aaC5qKm5oqA5pyvAAAAAA==')}"/>
<property name="cookie" ref="rememberMeCookie"/>
</bean> <!-- 配置自定义缓存管理器,中引入redis缓存管理器或者,用Redis使用redis,用ehcache使用ehcache中 -->
<!-- 用户授权信息Cache, 采用spring-cache, 具体请查看spring-shirocache.xml -->
<bean id="shiroSpringCacheManager" class="ch.cache.shirocache.ShiroSpringCacheManager">
<property name="cacheManager" ref="cacheManager" />
</bean> <!-- 会话管理器 -->
<bean id="sessionManager" class="ch.cache.session.SessionManager">
<!-- 设置全局会话超时时间 半小时 -->
<property name="globalSessionTimeout" value="#{30 * 60 * 1000}"/>
<property name="sessionValidationInterval" value="120000"/>
<property name="sessionValidationSchedulerEnabled" value="true"/>
<property name="sessionIdCookieEnabled" value="true"/>
<property name="sessionIdCookie" ref="sessionIdCookie"/>
<property name="sessionDAO" ref="sessionDAO"/>
<!-- <property name="sessionIdCookie.name" value="TRM_JSESSIONID"/> -->
</bean> <!-- 会话DAO 用于会话的CRUD -->
<bean id="sessionDAO" class="ch.cache.session.CacheSessionDAO">
<!-- Session缓存名字,默认就是shiro-activeSessionCache -->
<property name="activeSessionsCacheName" value="activeSessionCache"/>
<property name="cacheManager" ref="shiroSpringCacheManager"/>
</bean> <!--配置安全管理器-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--设置自定义Realm-->
<property name="realm" ref="userRealm"/>
<!--将缓存管理器,交给安全管理器-->
<property name="cacheManager" ref="shiroSpringCacheManager"/>
<!-- 记住密码管理 -->
<property name="sessionManager" ref="sessionManager"/>
<property name="rememberMeManager" ref="rememberMeManager"/>
</bean> <!-- 在方法中 注入 securityManager ,进行代理控制 -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
<property name="arguments" ref="securityManager"/>
</bean> <!-- shiro密码加密配置 -->
<bean id="passwordHash" class="ch.cache.PasswordHash">
<!-- 密码加密 1次md5,增强密码可修改此处 -->
<property name="algorithmName" value="md5"/>
<property name="hashIterations" value="1"/>
</bean> <!-- 密码错误5次锁定半小时 -->
<bean id="credentialsMatcher" class="ch.cache.RetryLimitCredentialsMatcher">
<constructor-arg ref="shiroSpringCacheManager"/>
<!-- <property name="cacheManager" ref="shiroSpringCacheManager"/> -->
<property name="retryLimitCacheName" value="halfHour"/>
<property name="passwordHash" ref="passwordHash"/>
</bean> <!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 安全管理器 -->
<property name="securityManager" ref="securityManager"/>
<!-- 默认的登陆访问url -->
<property name="loginUrl" value="/views/admin/centre/login.jsp"/>
<!-- 登陆成功后跳转的url -->
<property name="successUrl" value="/views/admin/centre/main.jsp"/>
<!-- 没有权限跳转的url -->
<property name="unauthorizedUrl" value="/"/>
<property name="filterChainDefinitions">
<value>
<!--
anon 不需要认证
authc 需要认证
user 验证通过或RememberMe登录的都可以
-->
/** = anon
/views/decorator/** = anon
</value>
</property>
<property name="filters">
<map>
<entry key="user" value-ref="ajaxSessionFilter" />
</map>
</property>
</bean>
<!-- ajax session超时时处理 -->
<bean id="ajaxSessionFilter" class="ch.cache.ShiroAjaxSessionFilter"/>
<!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- 启用shrio 控制器授权注解拦截方式 -->
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean>
<!-- AOP式方法级权限检查 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true"/>
</bean>
</beans>
spring-shiro 配置的更多相关文章
- Spring+shiro配置JSP权限标签+角色标签+缓存
Spring+shiro,让shiro管理所有权限,特别是实现jsp页面中的权限点标签,每次打开页面需要读取数据库看权限,这样的方式对数据库压力太大,使用缓存就能极大减少数据库访问量. 下面记录下sh ...
- Spring Shiro配置第三方SSO客户端登录
经过实践的Shiro配置,利用 sSOInterceptor 进行sso登录拦截 配置 @Configuration public class ShiroConfiguration extends B ...
- 基于Spring框架的Shiro配置
一.在web.xml中添加shiro过滤器 <!-- Shiro filter--> <filter> <filter-name>shiroFilter</ ...
- spring与shiro配置详解
1.加入shiro相关依赖的jar包 pom.xml部分内容如下: <dependency> <groupId>org.apache.shiro</groupId> ...
- spring下配置shiro
1.web.xml中加入shiro的过滤器: <!-- Spring --> <!-- 配置Spring配置文件路径 --> <context-param> < ...
- 基于Spring框架的Shiro配置(转发:http://kdboy.iteye.com/blog/1103794)
一.在web.xml中添加shiro过滤器 <!-- Shiro filter--> <filter> <filter-name>shiroFilter</f ...
- spring整合shiro配置BUG,Tomcat启动不了:Error during artifact deployment. See server log for details
现象 spring配置shiro权限控制之后,项目无法启动 [2019-08-09 09:00:35,800] Artifact export_web_manager:war exploded: Er ...
- spring boot 之 spring security 配置
Spring Security简介 之前项目都是用shiro,但是时过境迁,spring security变得越来越流行.spring security的前身是Acegi, acegi 我也玩过,那都 ...
- (转)Springboot+shiro配置笔记+错误小结
springboot不像springmvc,它没有xml配置文件,那该如何配置shiro呢,其实也不难,用java代码+注解来解决这个问题.仅以此篇记录我对shiro的学习,如有对过客造成不便,实在抱 ...
- Spring+Shiro搭建基于Redis的分布式权限系统(有实例)
摘要: 简单介绍使用Spring+Shiro搭建基于Redis的分布式权限系统. 这篇主要介绍Shiro如何与redis结合搭建分布式权限系统,至于如何使用和配置Shiro就不多说了.完整实例下载地址 ...
随机推荐
- mysql05---游标
drop procedure p12$ //删除存储过程 //游标cursor,一条sql对应n条资源,取出资源的接口/句柄就是cursor, 一条sql产生的n条结果不是一次性全部输出,而是返回一个 ...
- Mac 中安装 Apache Ant
1.下载Apache Ant:http://ant.apache.org/bindownload.cgi 2.解压apache-ant-1.9.6-bin.zip,把解压好的apache-ant-1. ...
- VMware虚拟机安装WinXP出现错误output error file to the following location A:\GHOSTERR.TXT
我们安装Ghost版WinXP系统的时候,可能会出现一个如下图这样的错误:output error file to the following location A:\GHOSTERR.TXT. 出现 ...
- ['1' for i in range(4)]
' for i in range(4)]) 结果: [']
- STM32F4 LTDC学习
很久没有写东西了,也很久没看文档了吼吼,觉得有点无聊,找来F4看看,主要看F429.督促自己多看多记录. 首先配置同步时序先看参考手册 下面看一个实际例子,一块439的开发板 设置: LTDC_Ini ...
- asp.net MVC5 中的捆绑和更改bootstap默认的样式
在MVC5的视图中使用@Scritps.Render(),@Styles.Render() 分别可以加载样式和脚本.捆绑的和实际的路径都可以. 并且可以利用 编程的方式灵活引用css文件和脚本文件. ...
- hdu4975 A simple Gaussian elimination problem.(最大流+判环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 题意:和hdu4888基本一样( http://www.cnblogs.com/a-clown/ ...
- postgresql数据库基本信息查看
切换至postgresql数据库用户pguser 或 postgres(根据自己实际情况) 1. SELECT version(); 2.对的 2. 查看数据库大小: SELECT pg_size ...
- JDBC中的DriverManager.getConnection(url)中的参数url
1.Oracle8/8i/9i数据库(thin模式) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); ...
- php 文件锁flock解决并发
方案一:使用文件锁排它锁 flock函数用于获取文件的锁,这个锁同时只能被一个线程获取到,其它没有获取到锁的线程要么阻塞,要么获取失败 在获取到锁的时候,先查询,如果查询成功则进行操作,然后释放锁 f ...