Announcement Announcement Module
Collapse
No announcement yet.
Filters used in security filler chain are not initialized Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filters used in security filler chain are not initialized

    Hi,

    I have the following simple scenario:

    applicationContext.xml:

    Code:
    <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
            <security:filter-chain-map path-type="ant">
                <security:filter-chain pattern="/abc/**" filters="Filter1, Filter2" />
      </security:filter-chain-map>
    </bean>
    The Filter1 and Filter2 are beans defined into application context.

    web.xml:

    Code:
     <filter>
            <filter-name>filterChainProxy</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>springFilterChainProxy</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    The problem here is that filterConfig in Filter1 and Filter2 is null;

    The interesting part is that it used to work with spring 2.5.6 and spring security 2.0.4

    After upgrade to spring 3.0.5 we have org.springframework.security.web.FilterChainProxy before it was org.springframework.security.util.FilterChainProxy

    My observations are that in org.springframework.security.util.FilterChainProxy the
    init method of FilterChainProxy was used also to initialize all filters listed in security:filter-chain but in version 3.0.5 this is not happening any more and filterConfig for Filter1 and Filter2 is always null.

    Do I need to make some additional changes in my configuration to make it work?

    Thanks in advance!

  • #2
    That's correct. FilterChainProxy doesn't invoke the filter lifecycle methods for filters declared as Spring beans. It's recommended that you implement the application context lifecycle methods as an alternative, since this is how the instances are actually managed.

    Comment


    • #3
      I'm having the same issue.

      Using <param-name>targetFilterLifecycle</param-name> does not work anymore.

      Could you give an example how to access the filterConfig?

      Comment


      • #4
        I'm not sure it is the right solution but it works for me.

        Code:
        public class FilterChainProxy extends org.springframework.security.web.FilterChainProxy {
        
            @Override
            protected void initFilterBean() throws ServletException {
                super.initFilterBean();
        
                FilterConfig fc = getFilterConfig();
                Collection<Filter> filters =  obtainAllDefinedFilters();
        
                for (Filter filter : filters) {
                    filter.init(fc);       
                }
        
         }

        Comment

        Working...
        X