shiro集成spring&工作流程&DelegatingFilterProxy
1.集成Spring
参考文献:

新建web工程:


ehcache-core来自Hibernate
wen.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>shiro-</display-name> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>user.jsp</welcome-file>
</welcome-file-list> <!-- 1.配置shiroFilter -->
<!-- 参考官方文档 -->
DelegatingFilterProxy实际上是Filter的一个带啦对象,默认情况下,spring会到IOC容器中查找和filter-name对应的filter bean ,也可以通过targetBeanName
的初始化参数来配置filter的bean的id
<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>
</filter-mapping> </web-app>
spring-servlet.xml
<context:component-scan base-package="com.MrChengs.shiro"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:default-servlet-handler/>
ehcache.xml来自

applicationContext.xml
<!--
1.配置SecurityManager
-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="cacheManager" ref="cacheManager"/>
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. --> <property name="realm" ref="jdbcRealm"/>
</bean> <!--
2. 配置CacheManager
2.1需要加入ehcache的jar和配置文件
-->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!-- Set a net.sf.ehcache.CacheManager instance here if you already have one. If not, a new one
will be creaed with a default config:
<property name="cacheManager" ref="ehCacheManager"/> -->
<!-- If you don't have a pre-built net.sf.ehcache.CacheManager instance to inject, but you want
a specific Ehcache configuration to be used, specify that here. If you don't, a default
will be used.: --> <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/>
</bean> <!--
3.配置Realm
3.1直接实现Realm接口的bean
-->
<bean id="jdbcRealm" class="com.MrChengs.shiro.realms.ShiroRealm"> </bean> <!--
4.生命周期的LifecycleBeanPostProcessor,可以自动来调用在springIOC容器中shiro bean的生命周期的方法
-->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after
the lifecycleBeanProcessor has run: -->
<!--
5.启用IOC容器中shiro注解,但是必须在配置了lifecycleBeanProcessor之后才可以使用
-->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor"/>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"/>
</bean> <!--
6.配置ShiroFilterFactoryBean
id必须和web.xml文件中的DelegatingFilterProxy,的filter-name一致
若不一致,则会抛异常org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' is defined
因为Shiro会在IOC容器中查找和<filter-name>和
-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/> <!-- 登陆页面 -->
<property name="loginUrl" value="/login.jsp"/>
<!-- 登陆成功页面 -->
<property name="successUrl" value="/list.jsp"/>
<!-- 没有权限的页面 -->
<property name="unauthorizedUrl" value="/unauthor.jsp"/>
<!-- The 'filters' property is not necessary since any declared javax.servlet.Filter bean
defined will be automatically acquired and available via its beanName in chain
definitions, but you can perform overrides or parent/child consolidated configuration
here if you like: -->
<!-- <property name="filters">
<util:map>
<entry key="aName" value-ref="someFilterPojo"/>
</util:map>
</property> -- <!--
配置那些页面需要受保护,以及访问这些页面需要的的权限 1)anon 可以被匿名访问
2)authc 必须认证即登陆后才可以访问的页面
-->
<property name="filterChainDefinitions">
<value>
/login.jsp = anon # everything else requires authentication:
/** = authc
</value>
</property>
</bean>
2.工作流程


其他均会报错!!!
shiro集成spring&工作流程&DelegatingFilterProxy的更多相关文章
- Java框架之SpringMVC 05-拦截器-异常映射-Spring工作流程
SpringMVC 拦截器 Spring MVC也可以使用拦截器对请求进行拦截处理,可以自定义拦截器来实现特定的功能,自定义的拦截器可以实现HandlerInterceptor接口中的三个方法,也可以 ...
- Shiro集成Spring
本篇博客主要讲述的是两者的集成.不涉及到各自的详细细节和功能. 因为官方给出的文档不够具体,对新手而言通过官方文档还不可以非常快的搭建出SpringShiro的webproject.本博客将通过实际的 ...
- shiro 集成spring 配置 学习记录(一)
首先当然是项目中需要增加shiro的架包依赖: <!-- shiro --> <dependency> <groupId>org.apache.shiro</ ...
- shiro学习(四、shiro集成spring+springmvc)
依赖:spring-context,spring-MVC,shiro-core,shiro-spring,shiro-web 实话实说:web.xml,spring,springmvc配置文件好难 大 ...
- shiro 集成spring 使用 redis作为缓存 学习记录(六)
1.在applicationContext-redis.xml配置文件中增加如下: 申明一个cacheManager对象 用来注入到 shiro的 securityManager 属性 cac ...
- Shiro 集成Spring 使用 redis时 使用redisTemplate替代jedisPool(五)
1.添加依赖架包: <dependency> <groupId>org.springframework.data</groupId> <artifactId& ...
- Apache Shiro 集成Spring(二)
1.依赖: <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-cor ...
- Spring 工作流程简单介绍
Spring Web MVC 处理Http请求的大致过程: 一旦Http请求到来,DispatcherSevlet将负责将请求分发. DispatcherServlet可以认为是Spring提供的前端 ...
- springmvc工作流程
Spring MVC工作流程图 图一 图二 Spring工作流程描述 1. 用户向服务器发送请求,请求被Spring 前端控制Servelt DispatcherServle ...
随机推荐
- 从零开始制作H5人脸融合小游戏
去年的建军节,一个展示军装照的H5人脸融合游戏火遍朋友圈,带来很好的传播效果.最近欧冠决赛要来了,公司决定做一个寻找和你最像的欧冠球星的H5游戏,那么该怎么做呢?认真分析了一下,这个游戏其实用到的技术 ...
- (转)The remote certificate is invalid according to the validation procedure
If you get “The remote certificate is invalid according to the validation procedure” exception while ...
- JS实现队列
JS实现队列: 队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表.进行插入操作的端称为队尾 ...
- 超时重试(一)ajax
我们使用jquery的ajax,超时重试可以采用两种方式,一种是配置ajax的timeout的参数,另一种就是以setTimeout定时器的方式实现: 1)timeout参数配置方式 var xhr ...
- mysql表情存储报错问题
mysql采用utf-8字符编码,但在移动端使用输入法的表情并存储数据库的时候,出现错误. java.sql.SQLException: Incorrect string value: '\xF0\x ...
- Hadoop 完全分布式部署(三节点)
用来测试,我在VMware下用Centos7搭起一个三节点的Hadoop完全分布式集群.其中NameNode和DataNode在同一台机器上,如果有条件建议大家把NameNode单独放在一台机器上,因 ...
- 修改phpmyadmin不能导入大文件的限制
情景:我需要导入一张1.03GB的数据表,但是phpmyadmin导入文件默认为不能超过2M.因此需要修改phpmyadmin导入文件的大小限制. 1.phpmyadmin的导入也就是php完成文件上 ...
- 移动web开发都会遇到的坑(会持续更新)
1.自适应第一招 <meta name="viewport" content="width=device-width,initial-scale=1.0,user- ...
- 理解JS表达式
表达式:是由运算元和运算符(可选)构成,并产生运算结果的语法结构. 基本表达式 以下在ES5中被称为基本表达式(Primary Expression) this.null.arguments等内置的关 ...
- JS函数动作分层结构详解及Document.getElementById 释义 js及cs数据类型区别 事件 函数 变量 script标签 var function
html +css 静态页面 js 动态 交互 原理: js就是修改样式, 比如弹出一个对话框. 弹出的过程就是这个框由disable 变成display:enable. 又或者当鼠标指向 ...