Skip to Content
0
Former Member
Jul 01, 2014 at 03:14 PM

Order of execution of filters is not working - javax.servlet.Filter, de.hybris.platform.servicelayer.web.PlatformFilterChain

334 Views

Hi,

We are encountering a strange issue with the order in which the filters are getting triggered in our web application.

We are integrating a sitemesh filter in our application and we are seeing issues with the spring security tags in the decorator pages. This is happening because the springSecurityFilterChain is executing after the sitemesh filter.

In our web.xml we have the following:

 <filter-mapping>
     <filter-name>storefrontTenantFilterChain</filter-name>
     <servlet-name>DispatcherServlet</servlet-name>
 </filter-mapping>


 <filter-mapping>
     <filter-name>sitemesh</filter-name>
     <url-pattern>/*</url-pattern>
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
     <dispatcher>INCLUDE</dispatcher>
 </filter-mapping>

where storefrontTenantFilterchain is declared as a spring delegatingFilterProxy

     <filter-name>storefrontTenantFilterChain</filter-name>
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>


bean definition:

     <constructor-arg>
         <list>
             <ref bean="storefrontSessionFilter" />
             <ref bean="springSecurityFilterChain" />                
         </list>
     </constructor-arg>


and the sitemesh filter is just a regular javax.servlet.Filter implementation

These filters should be triggering in the order in which they are declared in the web.xml

     <filter-name>filter1</filter-name>
     <url-pattern>/*</url-pattern>



     <filter-name>filter2</filter-name>
     <url-pattern>/*</url-pattern>


etc..

This is not happening. I am setting some breakpoints to track the order of execution and the sitemesh filter is executing before the fdStorefrontTenantFilterChain (the one that references the springSecurityFilterChain)

Unfortunately declaring the sitemesh filter as bean and adding this to the constructor list of the PlatformFilterChain is not an option due to some custom initialization in the public void init(FilterConfig filterConfig)

Is there something that I'm missing? I've tried many different things and the only thing that worked was using the de.hybris.platform.util.HybrisInitFilter (which is deprecated) and moving the springSecurityFilterChain to the web.xml but this is breaking some other functionality.

Thanks in advance for your response.

-tony