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则调用,否则不调用。
  • 相关阅读:
    Kali学习笔记38:文件上传漏洞
    Kali学习笔记37:APPSCAN
    Kali学习笔记36:AVWS10的使用
    Kali学习笔记35:使用VBScript、PowerShell、DEBUG传输文件
    Kali学习笔记34:配置TFTP和FTP服务
    《day13--异常的进阶和包的使用》
    《java作业》
    《day12---异常》
    《AppletButtonEvent.java》
    《CheckboxDemo.java》
  • 原文地址:https://www.cnblogs.com/ranger2016/p/3952044.html
Copyright © 2011-2022 走看看