title: Spring boot security - two distinct filters
body: <p>I am trying to configure spring security with two distinct filters. 
  What i want is to have some URLs which will be processed by one filter, and some URLs which will be processed by other filter.
  This is the setup i came up with :</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled=true)
  public class SecurityConfigurationContext {
  
      @Order(1)
      @Configuration
      public static class ConfigurerAdapter1 extends WebSecurityConfigurerAdapter{
          ...
  
          @Override
          protected void configure(final HttpSecurity http) throws Exception {
              // Handlers and entry points
              http.exceptionHandling()
                  .authenticationEntryPoint(MyCustomAuthenticationEntryPoint);
  
  
              http.authorizeRequests()
                  .antMatchers(HttpMethod.GET, "/filter1-urls/*").hasRole("USER");
  
  
              http.addFilterBefore(myCustomFilter1, ChannelProcessingFilter.class);
  
              http.csrf().disable();
              http.httpBasic()
                  .and()
                  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
          }
  
          @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception {
              auth.userDetailsService(myCustomAuthenticationService)
                  .passwordEncoder(new BCryptPasswordEncoder());
          }
      }
  
      @Order(2)
      @Configuration
      public static class ConfigurerAdapter2 extends WebSecurityConfigurerAdapter{
          ...
  
          @Override
          protected void configure(final HttpSecurity http) throws Exception {
              // Handlers and entry points
              http.exceptionHandling()
                  .authenticationEntryPoint(MyCustomAuthenticationEntryPoint);
  
  
              http.authorizeRequests()
                  .antMatchers(HttpMethod.GET, "/filter2-urls/*").hasRole("SUPER_USER");
  
  
              http.addFilterBefore(myCustomFilter2, ChannelProcessingFilter.class);
  
              http.csrf().disable();
              http.httpBasic()
                  .and()
                  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
          }
  
          @Override
          protected void configure(AuthenticationManagerBuilder auth) throws Exception {
              auth.userDetailsService(myCustomAuthenticationService)
                  .passwordEncoder(new BCryptPasswordEncoder());
          }
      }
  }
  </code></pre>
  
  <p>And filters look like this :</p>
  
  <p>Filter1 :</p>
  
  <pre><code>@Component
  @Order(1)
  public final class MyCustomFilter1 implements Filter{
  
      public MyCustomFilter1() {
          super();
      }
  
      @Override
      public final void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
          // logic for processing filter1-urls
      }
  }
  </code></pre>
  
  <p>Filter2 :</p>
  
  <pre><code>@Component
  @Order(2)
  public final class MyCustomFilter2 implements Filter{
  
      public MyCustomFilter2() {
          super();
      }
  
      @Override
      public final void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
          // logic for processing filter2-urls
      }
  }
  </code></pre>
  
  <p>The problem is that both of these filters are invoked in a chain for every request. Any request i make, it first passes through one filter and then the other, rather then just through one.</p>
  
  <p>How do i fix this ?</p>
  
  <p>Thanks in advance.</p>