zoukankan      html  css  js  c++  java
  • Spring DelegatingFilterProxy解析

    以前DelegatingFilterProxy是在需要使用spring security 的时候在xml中配置,如下:

    <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则调用,否则不调用。
  • 相关阅读:
    input的button和submit的区别
    2016011993 顾思宇 散列函数的应用及其安全性
    结对项目作业报告——四则运算web项目
    读《构建之法》4、17章有感
    2016011993+小学四则运算练习软件项目报告
    读《构建之法》1、2、16章有感
    码出生活
    四则运算
    信息安全作业
    结对项目博客
  • 原文地址:https://www.cnblogs.com/ranger2016/p/3952044.html
Copyright © 2011-2022 走看看