<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"><!-- 配置shiro的过滤器工厂类,id- shiroFilter要和我们在web.xml中配置的过滤器一致 --><bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"><!-- 调用我们配置的权限管理器 --><property name="securityManager" ref="securityManager" /><!-- 配置我们的登录请求地址 --><property name="loginUrl" value="/login.jsp" /><!-- 配置我们在登录页登录成功后的跳转地址 ,登录成功后的处理逻辑在LoginController里硬编码为home.jsp--><property name="successUrl" value="/WEB-INF/jsp/home.jsp" /><!-- 如果您请求的资源不再您的权限范围,则跳转到/403请求地址 --><property name="unauthorizedUrl" value="/unauthorized" /><property name="filters"><util:map><entry key="logout" value-ref="logoutFilter" /></util:map></property><!-- 权限配置 --><property name="filterChainDefinitions"><value><!-- anon表示此地址不需要任何权限即可访问 -->/login/**    =anon/js/**       =anon/css/**      =anon/img/**      =anon/image/**    =anon/logout/**   =logout<!--所有的请求(除去配置的静态资源请求或请求地址为anon的请求)都要通过登录验证,如果未登录则跳到/login -->/** = authc</value></property></bean><bean id="logoutFilter" class="org.apache.shiro.web.filter.authc.LogoutFilter"><property name="redirectUrl" value="/login.jsp" /></bean><!-- 会话ID生成器 --><bean id="sessionIdGenerator"class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator" /><!-- 会话Cookie模板 关闭浏览器立即失效 --><bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie"><constructor-arg value="sid" /><property name="httpOnly" value="true" /><property name="maxAge" value="-1" /></bean><!-- 会话DAO --><bean id="sessionDAO"class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"><property name="sessionIdGenerator" ref="sessionIdGenerator" /></bean><!-- 会话验证调度器,每30分钟执行一次验证 ,设定会话超时及保存 --><bean name="sessionValidationScheduler"class="org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler"><property name="interval" value="1800000" /><property name="sessionManager" ref="sessionManager" /></bean><!-- 会话管理器 --><bean id="sessionManager"class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"><!-- 全局会话超时时间(单位毫秒),默认30分钟 --><property name="globalSessionTimeout" value="1800000" /><property name="deleteInvalidSessions" value="true" /><property name="sessionValidationSchedulerEnabled" value="true" /><property name="sessionValidationScheduler" ref="sessionValidationScheduler" /><property name="sessionDAO" ref="sessionDAO" /><property name="sessionIdCookieEnabled" value="true" /><property name="sessionIdCookie" ref="sessionIdCookie" /><property name="sessionIdUrlRewritingEnabled" value="false" /></bean><!-- 注册自定义的Realm--><bean id="adminRealm" class="com.shiro.AdminRealm"/><bean id="memberRealm" class="com.shiro.MemberRealm"/><bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" /><!-- 安全管理器 --><bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"><!-- 可以配置多个Realm,其实会把realms属性赋值给ModularRealmAuthenticator的realms属性 --><property name="realms"><list><ref bean="memberRealm" /><ref bean="adminRealm"/></list></property><property name="authenticator" ref="authenticator"></property><!-- 使用下面配置的缓存管理器 --><property name="cacheManager" ref="cacheManager" /><property name="sessionManager" ref="sessionManager" /></bean><!-- 配置使用自定义认证器,可以实现多Realm认证,并且可以指定特定Realm处理特定类型的验证 --><bean id="authenticator" class="com.ang.elearning.shiro.CustomizedModularRealmAuthenticator"><!-- 配置认证策略,只要有一个Realm认证成功即可,并且返回所有认证成功信息 --><property name="authenticationStrategy"><bean class="org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy"></bean></property></bean><!-- 相当于调用SecurityUtils.setSecurityManager(securityManager) --><beanclass="org.springframework.beans.factory.config.MethodInvokingFactoryBean"><property name="staticMethod"value="org.apache.shiro.SecurityUtils.setSecurityManager" /><property name="arguments" ref="securityManager" /></bean><!-- 开启shiro注解-1--><bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"depends-on="lifecycleBeanPostProcessor"><property name="proxyTargetClass" value="true" /></bean><!-- 开启shiro注解-2--><bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"><property name="securityManager" ref="securityManager"/></bean><!-- 保证实现了Shiro内部lifecycle函数的bean执行 --><bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" /><!-- shiro start --><!-- shiro为集成springMvc 拦截异常,使用注解时无权限的跳转 --><beanclass="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"><property name="exceptionMappings"><props><!-- 这里你可以根据需要定义N多个错误异常转发 --><prop key="org.apache.shiro.authz.UnauthorizedException">redirect:/unauthorized</prop><prop key="org.apache.shiro.authz.UnauthenticatedException">redirect:/unauthorized</prop><prop key="java.lang.IllegalArgumentException">/page/error</prop>  <!-- 参数错误(bizError.jsp) --><prop key="java.lang.Exception">page/error</prop>  <!-- 其他错误为'未定义错误'(unknowError.jsp) --></props></property></bean><!-- shiro end --></beans> 

转载于:https://www.cnblogs.com/YLQBL/p/8241231.html

shiro配置参考(一)相关推荐

  1. RHEL/CentOS通用性能优化、安全配置参考

    RHEL/CentOS通用性能优化.安全配置参考 本文的配置参数是笔者在实际生产环境中反复实践总结的结果,完全适用绝大多数通用的高负载.安全性要求的网络服务器环境.故可以放心使用. 若有异议,欢迎联系 ...

  2. 【Android 安装包优化】动态库打包配置 ( “armeabi-v7a“, “arm64-v8a“, “x86“, “x86_64“ APK 打包 CPU 指令集配置 | NDK 完整配置参考 )

    文章目录 一.动态库打包配置 二.NDK 完整配置参考 三.参考资料 一.动态库打包配置 在 build.gradle 构建脚本中 , 配置 ndk 编译的动态库 CPU 架构类型 ; 在 " ...

  3. 案例代码:springboot+shiro配置同一用户多设备登录最大会话数

    另一链接: springboot+springsecurity配置登录后踢出前一个登录用户 1.自定义登陆过滤器类: /*** 登录帐号控制过滤器* */ public class KickoutSe ...

  4. springboot使用shiro配置多个过滤器和session同步案例

    文章目录 知识点介绍 验证码过滤器 登录账号控制过滤器 自定义访问控制过滤器 同步Sesion到数据库 退出过滤器 定期session验证任务调度器 shiro配置类 自定义Session类(继承 S ...

  5. 基于Spring框架的Shiro配置

    http://kdboy.iteye.com/blog/1103794 一.在web.xml中添加shiro过滤器 Xml代码   <!-- Shiro filter--> <fil ...

  6. dubbo配置参考手册

    配置参考手册 <dubbo:service/> <dubbo:reference/> <dubbo:protocol/> <dubbo:registry/&g ...

  7. CSE 支持spring 4/5 以及spring boot 1/2 maven组件依赖关系配置参考

    [摘要] 本文介绍了CSE如何使用Spring 4或者Spring 5,以及在Spring Boot 1和Spring Boot 2中如何集成CSE,重点介绍了CSE提供的maven管理器,以及如何使 ...

  8. shiro框架---shiro配置介绍(一)

    接上一篇文章shiro框架-通过系统介绍shiro框架中的实现逻辑   项目已分享到GitHub上,如果需要的可以看下,springboot+shiro项目Git下载地址. shiro在springb ...

  9. MYSQL使用MHA实现主从复制高可用、Galera Cluster介绍、压力测试、my.cnf配置参考

    MHA介绍 MHA: Master High Availability,对主节点进行监控,可实现自动故障转移至其它从节点:通过提升某一从节点为新的主节点,基于主从复制实现,还需要客户端配合实现,目前M ...

最新文章

  1. 心酸科研路:3年前CVPR论文,仅被引用11次,如今成就黑洞照片!
  2. 修改数组的值和多维数组排序
  3. 《Effective-Ruby》读书笔记
  4. OpenStack(二)——Keystone组件
  5. 机器学习(part1)--机器学习第一课
  6. was中java目录_was8.5选择安装选项,安装应用程序的目录填写自定义目录,应用部署成功后访问不了页面?...
  7. vue 给iframe设置src_vue组件中使用iframe元素
  8. 操作系统(12)-【Linux】索引式文件系统
  9. 车仪表台上的装饰_给车“纹身”贴这些的注意,有人挨罚啦!扣不扣分?!看这里...
  10. vrrp 理论和配置
  11. 30 道 MySQL 面试题全放送!
  12. php自己编译扩展,Linux编译PHP添加扩展库的方法
  13. null可以转换成任意非基本类型(int/short/long/float/boolean/byte/double/char以外)
  14. a^x ≡1(mod n) Ord_n(a)=x什么意思
  15. 没有电脑基础能学计算机专业吗,没有绘画基础想学电脑绘画该怎么学?
  16. 3D游戏学习 案例游戏设计分析——英雄联盟设计浅析
  17. Shadow DOM的样式ShadowRoot
  18. 数字类型与列表——python
  19. 微信小程序开发——动画效果
  20. 通信专业考研就业专栏

热门文章

  1. 微信访问H5,闪退问题
  2. 在DWZ框架中整合kindeditor复文本框控件
  3. HttpClient之GET请求
  4. 使用Visual Studio将Objective-C编译C++
  5. 类的成员函数指针和mem_fun适配器的用法
  6. TechEmpower最新一轮的性能测试出炉,ASP.NET Core依旧表现不俗
  7. MSBuild + MSILInect实现编译时AOP-改变前后对比
  8. 关于键盘上方创建返回按钮
  9. IBM db2安装好了以后,启动不了服务
  10. 自定义Seekbar拖动条式样