title: Execute servlet filters before the Spring Security filter chain
body: <p>I'm introducing Spring Web Security in an already existing website. Now there has occured a problem:</p>
  
  <p>I want my custom filters to be executed in the Tomcat filter chain <strong>before</strong> the Spring Security filter chain. I don't want them to be a part of this Spring Security filter chain. </p>
  
  <p>All I have found is a solution in Spring Boot (see <a href="http://mtyurt.net/2015/07/15/spring-how-to-insert-a-filter-before-springsecurityfilterchain/" rel="nofollow noreferrer">"Spring - How to insert a filter before SpringSecurityFilterChain"</a>) - but I'm not using Spring Boot.</p>
  
  <p><br>
  <strong>Update 22.11.2016:</strong><br><br>
  Here is a part of my <code>web.xml</code> - only the custom filter is added here:<br></p>
  
  <pre><code>&lt;filter-mapping&gt;
      &lt;filter-name&gt;MyFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>The Spring Security filter chain is added by defining an AbstractSecurityWebApplicationInitializer:<br></p>
  
  <pre><code>public class MySecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
      ...
  }
  </code></pre>
  
  <p><br>
  The outcome: The Spring security filters go first and only after this my custom filter.<br><br>
  How to swap this?</p>