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就不多说了.完整实例下载地址 ...
随机推荐
- 深入分析linux调度机制
一.说明 本文以linux-2.4.10 为例主要分析Linux 进程调度模块中的schedule 函数及其相关的函数.另外相关的前提知识也会说明.默认系统平台是自己的i386 架构的pc. 二.前提 ...
- UVA315 Network —— 割点
题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...
- Magic Grid ComboBox JQuery 版
在MagicCombo组件中嵌入Grid,以支持分页查找和跨页选取 1. 2. [代码][JavaScript]单选示例代码 <script type="text/jav ...
- 计算机设计思想 —— 代理(proxy)
0. 理解 两个说着不同母语国家的人想要交流通话,各人说着各自的母语显然是无法沟通的,此时需要一个翻译,一个媒介(medium).中介,或者一个代理(proxy),比如通用的国际语言英语,比如全世界人 ...
- 【Codeforces 915E】 Physical Education Lessons
[题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...
- 无参数的lambda匿名函数
lambda 语法: lambda [arg1[,arg2,arg3....argN]]:expression 1.单个参数的: g = lambda x:x*2 print g(3) 结果是6 2. ...
- 我使用过的Linux命令之hexdump - ”十六“进制查看器(转载)
转载:http://codingstandards.iteye.com/blog/805778 本文链接:http://codingstandards.iteye.com/blog/805778 ...
- RTSP协议简介(转载)
转自:http://ilinux.iteye.com/blog/505753 Real Time Streaming Protocol 或 者RTSP(实时流媒体协议),是由Real network ...
- E20180224-hm-xa
separator n. 分离器,分离装置; 防胀器; colon n. 冒号; <解>结肠; 科郎(哥斯达黎加货币单位); semicolon n. 分号;
- 洛谷 P3953 逛公园【spfa+记忆化dfs+bfs】
spfa预处理出最短路数组dis,然后反向建边bfs出ok[u]表示u能到n点 然后发现有0环的话时候有inf解的,先dfs找0环判断即可 然后dfs,设状态f[u][v]为到u点,还可以跑最短路+v ...