首先当然是项目中需要增加shiro的架包依赖:

 <!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

1、shiro 总体来说就是过滤器的集合,首先在项目的web.xml里增加shiro的filter配置:如下

 <!--Shiro过滤器-->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

2、在项目的resource目录下 新增shiro的配置xml文件如:applicationContext-shiro.xml:

1)、增加 securityManager  的初始化;

2)、增加  shiroFilter  的配置, 注意 此配置文件中的bean  过滤器的 id  必须是 web.xml中的 filter-name值

3)、增加自定义的realm实现

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <description>Shiro安全配置</description> <!--此Bean 只是增加登录时的验证码处理,不是shiro必须的配置-->
<bean class="com.itzixi.web.utils.ItzixiCaptcha">
<property name="cacheManager" ref="shiroEhcacheManager"/>
<!-- 复用半小时缓存 -->
<property name="cacheName" value="itzixiCaptcha"/>
</bean> <!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="shiroDbRealm"></property>
</bean> <!-- 用户授权信息Cache, 采用EhCache -->
<bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile" value="classpath:shiro/ehcache-shiro.xml"/>
</bean> <!-- 项目自定义的Realm -->
<bean id="shiroDbRealm" class="com.itzixi.web.shiro.ShiroDBRealm">
</bean> <!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 安全管理器 -->
<property name="securityManager" ref="securityManager"/>
<!-- 默认的登陆访问url -->
<property name="loginUrl" value="/login.action"/>
<!-- 登陆成功后跳转的url -->
<property name="successUrl" value="/index.action"/>
<!-- 登录成功以后,没有权限访问的页面,会跳转到该url -->
<property name="unauthorizedUrl" value="/unauth.action"/> <property name="filterChainDefinitions">
<value>
<!--
anon 不需要认证
authc 需要认证
user 验证通过或RememberMe登录的都可以
-->
/** = authc
</value>
</property>
</bean>
</beans>

经过如上的配置 基本完成了shiro初始化集成。

shiro 集成spring 配置 学习记录(一)的更多相关文章

  1. shiro 权限集成 sessionManager 配置 学习记录(三)

    1.shiro配置文件增加sessionManager管理 <!-- 6.shiro结合Session会话管理器 start --> <bean id="sessionMa ...

  2. shiro 权限集成Ehcache 配置 学习记录(二)

    1.加入依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-eh ...

  3. Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客

    ==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...

  4. 我的Spring Boot学习记录(二):Tomcat Server以及Spring MVC的上下文问题

    Spring Boot版本: 2.0.0.RELEASE 这里需要引入依赖 spring-boot-starter-web 这里有可能有个人的误解,请抱着怀疑态度看. 建议: 感觉自己也会被绕晕,所以 ...

  5. Spring Boot学习记录(二)–thymeleaf模板

    自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...

  6. shiro集成spring&工作流程&DelegatingFilterProxy

    1.集成Spring 参考文献: 新建web工程: ehcache-core来自Hibernate wen.xml <?xml version="1.0" encoding= ...

  7. 【转载】Spring boot学习记录(一)-入门篇

    前言:本系列文章非本人原创,转自:http://tengj.top/2017/04/24/springboot0/ 正文 首先声明,Spring Boot不是一门新技术.从本质上来说,Spring B ...

  8. shiro 集成spring 使用 redis作为缓存 学习记录(六)

    1.在applicationContext-redis.xml配置文件中增加如下: 申明一个cacheManager对象 用来注入到  shiro的   securityManager 属性  cac ...

  9. 我的Spring Boot学习记录(一):自动配置的大致调用过程

    1. 背景 Spring Boot通过包管理工具引入starter包就可以轻松使用,省去了配置的繁琐工作,这里简要的通过个人的理解说下Spring Boot启动过程中如何去自动加载配置. 本文中使用的 ...

随机推荐

  1. Android 系统四大组件

    Android 系统四大组件分别是活动(Activity).服务(Service).广播接收器(Broadcast Receiver)和内容提供器(Content Provider). 活动是所有 A ...

  2. Sublime + python2.7 + opencv (轻量级开发环境)

    工具: 1. Python2.7,安装完成 2. 相应版本的cv2.pyd,放入到…\Python27\Lib\site-packages\下 3. 下载Sublime Text 3,破解它,网上搜个 ...

  3. 使用GDI+保存带Alpha通道的图像(续)

    之前结合网上的一些代码及ATL::CImage的实现,自己写了一个将HBITMAP以PNG格式保存到文件到函数.见上一篇日记. 不过,后来换了个环境又发现了问题,昨天和今天上午把<Windows ...

  4. AbstractQueuedSynchronizer原理分析

    AbstractQueuedSynchronized 以下简称AQS,是用来构建锁或者其他同步组件的基础框架. 在AQS中,为锁的获取和释放提供了一些模板方法,而实现锁的类(AQS的子类)需要实现这些 ...

  5. ROS的ovpn设置

    转摘至www.80uncle.com 先下载Win下的openvpn客户端http://openvpn.se/download.html 我的证书是用这个客户端做的openvpn-2.0.9-gui- ...

  6. 《Java核心技术》 -- 读书笔记 ② - 类 | 对象 | 接口

    对象vs对象变量 “对象” 描述的是一个类的具体实例,他被java虚拟机分配在 "堆" (Heap)中. “对象变量” 为一个对象的引用(对象变量的值=记载着具体对象的位置/地址) ...

  7. document.getElementById/Name/TagName

    document.getElementById 1.getElementById 作用:一般页面里ID是唯一的,用于准备定位一个元素 语法: document.getElementById(id) 参 ...

  8. Java复习——网络编程

    Java从最开始就是支持网络编程的,也正是网络使Java得到发展繁荣.在这里我记录一下如何使用Java进行网络编程,什么是Socket以及Java实现TCP,UDP的编程模型. InetAddress ...

  9. spring boot + slf4j + log4j配置

    https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#boot-features-logging ht ...

  10. 汇编调用C程序

    本程序用keil5实现. keil4会将C程序的地址设为0x00000000,即一开始就运行C程序了,参数都还没设置好.这个错误我也没深究,因为我自己装的是keil5. 首先需要在汇编代码中给C程序指 ...