Spring DelegatingFilterProxy解析
2014-09-02 18:16
399 查看
以前DelegatingFilterProxy是在需要使用spring security 的时候在xml中配置,如下:
所以一直以为此类是spring security中的类,后来发现不是这样的,这个类位于spring-web包,和security没有关系。
这个类实际上就是一个Filter的委派代理类。
这样配置的意思是 spring管理的bean中有一个叫名字叫springSecurityFilterChain,然后把其注册进来。
在security的AbstractSecurityWebApplicationInitializer中是这样使用的:
这样就是把filter配置成了一个bean,并且让spring来管理器生命周期。
而DelegatingFilterProxy本身也是一个filter,>> GenericFilterBean >> Filter
其中有一个参数名是targetBeanName ,这就是需要代理的filter名称,如果这个名称为空的话,则会去找名称是:
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
所以一直以为此类是spring security中的类,后来发现不是这样的,这个类位于spring-web包,和security没有关系。
这个类实际上就是一个Filter的委派代理类。
这样配置的意思是 spring管理的bean中有一个叫名字叫springSecurityFilterChain,然后把其注册进来。
在security的AbstractSecurityWebApplicationInitializer中是这样使用的:
/** * Registers the springSecurityFilterChain * @param servletContext the {@link ServletContext} */ private void insertSpringSecurityFilterChain(ServletContext servletContext) { String filterName = DEFAULT_FILTER_NAME; DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy(filterName); String contextAttribute = getWebApplicationContextAttribute(); if(contextAttribute != null) { springSecurityFilterChain.setContextAttribute(contextAttribute); } registerFilter(servletContext, true, filterName, springSecurityFilterChain); }
这样就是把filter配置成了一个bean,并且让spring来管理器生命周期。
而DelegatingFilterProxy本身也是一个filter,>> GenericFilterBean >> Filter
其中有一个参数名是targetBeanName ,这就是需要代理的filter名称,如果这个名称为空的话,则会去找名称是:
<filter-name>springSecurityFilterChain</filter-name> 的bean. 其中有个属性targetFilterLifecycle标示是否调用代理filter的init方法。 如果为true则调用,否则不调用。
相关文章推荐
- Spring DelegatingFilterProxy
- spring DelegatingFilterProxy 过滤器 的原理及运用
- Spring-shiro源码陶冶-DelegatingFilterProxy和ShiroFilterFactoryBean
- Spring Security about DelegatingFilterProxy【转】
- spring DelegatingFilterProxy管理过滤器
- Spring之过滤器代理DelegatingFilterProxy
- Spring Web DelegatingFilterProxy和Spring Security Web Filter Chain
- Spring管理过滤器:org.springframework.web.filter.DelegatingFilterProxy
- 通过spring在filter注入bean(DelegatingFilterProxy与servlet filter)
- spring security设置(springSecurityFilterChain与DelegatingFilterProxy)
- Spring DelegatingFilterProxy
- spring DelegatingFilterProxy 过滤器 的原理及运用
- spring DelegatingFilterProxy的原理及运用
- 08、Spring_web.xml_DelegatingFilterProxy
- spring DelegatingFilterProxy管理过滤器
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-001-SpringSecurity简介(DelegatingFilterProxy、AbstractSecurityWebApplicationInitializer、WebSecurityConfigurerAdapter、@EnableWebSecurity、@EnableWebMvcS)
- spring之DelegatingFilterProxy
- org.springframework.web.filter.DelegatingFilterProxy的理解
- spring之DelegatingFilterProxy
- spring DelegatingFilterProxy 过滤器 的原理及运用