1.导入spring与shiro的jar包

2.在web.xml 文件中配置shiro的shiroFilter

<filter>
  <filter-name>shiroFilter</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
  <!-- 表示bean的生命周期由servlet管理 -->
  <param-name>targetFilterLifecycle</param-name>
  <param-value>true</param-value>
</init-param>
<init-param>
  <param-name>targetBeanName</param-name>
  <param-value>shiroFilter</param-value>
</init-param>
</filter>
<filter-mapping>
  <filter-name>shiroFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

3.在applicationContext.xml 文件中配置SecurityManager和Realm

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  <property name="securityManager" ref="securityManager"/>
  <property name="loginUrl" value="/login.jsp"/>
  <property name="unauthorizedUrl" value="/login.jsp"/>
  <!-- shiro 的过滤器执行链 -->
  <property name="filterChainDefinitions">
    <value>
      /login.jsp = anon
      /user/login.do = anon
      /user/logout.do = logout
      /** = authc
    </value>
  </property>
</bean>

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="userRealm"/>
    <property name="sessionManager" ref="sessionManager"/>

      <property name="rememberMeManager" ref="rememberMeManager"/>
</bean>

<bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
  <property name="cookie" ref="rememberMeCookie"/>
</bean>

<bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">

  <!-- 设置cookie的存活时间  -->
  <property name="maxAge" value="604800"/>

  <!-- 设置cookie的名称 -->
  <property name="name" value="rememberMe"/>

</bean>

<bean id="userRealm" class="com.edu.aynu.oalist.beans.Relam">
</bean>
<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
  <property name="globalSessionTimeout" value="300000"/>
  <property name="deleteInvalidSession" value="true"></property>
</bean>

转载于:https://www.cnblogs.com/mm163/p/10200850.html

shiro 与spring的集成相关推荐

  1. Java-Shiro(三):Shiro与Spring MVC集成

    新建Java Daynamic Web项目 导入Spring.SpringMVC依赖包: 导入Spring & Spring MVC包(导入如下所有开发包): Spring AOP依赖扩展包: ...

  2. Shiro与Spring集成时,Shiro权限注解@RequiresRoles等不生效的解决方案

    2019独角兽企业重金招聘Python工程师标准>>> Shiro与Spring集成时,Shiro权限注解@RequiresRoles等不生效, 这个问题着实整了好久,网上各种解决方 ...

  3. Spring Boot教程(十六):Spring Boot集成shiro

    Apache Shiro™是一个功能强大且易于使用的Java安全框架,可执行身份验证,授权,加密和会话管理.借助Shiro易于理解的API,您可以快速轻松地保护任何应用程序 - 从最小的移动应用程序到 ...

  4. 解决Spring Boot集成Shiro,配置类使用Autowired无法注入Bean问题

    为什么80%的码农都做不了架构师?>>>    如题,最近使用spring boot集成shiro,在shiroFilter要使用数据库动态给URL赋权限的时候,发现 @Autowi ...

  5. 有手就行的 Spring Boot 集成 Shiro

    前言   Apache Shiro 是 Java 的一个安全框架.目前,使用 Apache Shiro 的人越来越多,因为它相当简单,对比 Spring Security,可能没有 Spring Se ...

  6. 单点登录(shiro与Spring Security OAuth 2.0的集成)

    单点登录(shiro与Spring Security OAuth 2.0的集成) shiro项目采用ruoyi,OAuth采用pig 若依:https://gitee.com/y_project/Ru ...

  7. 【开发技术】2万字分析shiro、spring security两大安全框架,spring session,OAuth2 入门级教程

    SpringBoot 内容管理 Shiro 创建demo 用户[用户包括token ,角色,权限] :fist_oncoming: Shiro配置 配置5个基本对象 + 3额外对象 路径匹配有先后 : ...

  8. Shiro和Spring Security对比

    原文地址:Shiro和Spring Security对比_shiro和springsecurity对比_liyuejin的博客-CSDN博客 一.Shiro简介 Apache Shiro是Java的一 ...

  9. shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决

    shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决 from :http://blog.csdn.net/babys/article/ ...

最新文章

  1. 被批伪开源!刚刚融资6千万美元的Redis怎么了?
  2. springboot和flowable modeler整合
  3. UCloud想吃科创板的“第一个螃蟹”
  4. 飞桨模型保存_史上最全解读|飞桨模型库重大升级,主流算法模型全覆盖
  5. socket 编程入门教程(一)TCP server 端:7、接收与发送
  6. 计算机优秀大学生,应届计算机业优秀大学生的自我鉴定
  7. css中的外边距合并时垂直方向上的普通流相邻元素间
  8. 从零开始研发GPS接收机连载——3、用HackRF软件无线电平台作为GPS模拟器
  9. HTML里css画蝴蝶,纯css3制作煽动翅膀的蝴蝶的示例
  10. AndroidUI:Android的Holo Theme
  11. VUE—下载安装并使用mint ui(图文详情)
  12. 【葡萄城报表】还在为画“类Word文档报表”而发愁吗?
  13. 【大话数据结构C语言】56 二叉排序树的查找、插入和删除
  14. java马斯京根法计算汇流系数P
  15. 国标28181:什么是SDP协议
  16. ubuntu 12.04 ATI 驱动
  17. UVA 1455 Kingdom 线段树+并查集
  18. 东北天(ENU)和北东地(NED)
  19. 郑州师范学院计算机实验室,郑州师范学院---VR虚拟仿真实验中心
  20. 表格数据深度学习框架-DeepTables

热门文章

  1. [Udacity] Machine Learning tools
  2. lazyload 加载
  3. mysql restart fail_mysql突然挂掉,重启失败,求助
  4. Linux的yum命令及基本用法
  5. 如何进行日志采集设定和时间同步
  6. 世上可有后悔药?服务器里建快照
  7. 今日恐慌与贪婪指数为70 贪婪程度有所缓解
  8. 数据:以太坊2.0合约余额新增1.52万ETH
  9. 开放式可编程保险市场Tidal Finance完成由KR1领投的195万美元种子轮融资
  10. SAP License:OAYZ中的使用年限无法更改