title: Spring boot + OAuth2 security & request filter
body: <p>I have implemented Spring boot based REST API with OAuth2 for authentication. I had  to validate all request using <code>OAuth2AuthenticationProcessingFilter</code> to check Authorization header token bearer &amp; validate it. Also, before validating request using OAuth filter, i need to have custom filter for "ALL" request to check few mandatory request header param.</p>
  
  <p>Internally if any exception occurs <code>/error</code> is redirected &amp; this doesn't need to go through <code>OAuth2AuthenticationProcessingFilter</code>, this request can be skipped. </p>
  
  <pre><code>http.authorizeRequests().antMatchers("/error").permitAll().anyRequest().authenticated();
     // both configuration validates even "ERROR" request.
  http.antMatcher("/**").authorizeRequests().antMatchers("/error").permitAll().anyRequest().authenticated();
  </code></pre>
  
  <pre><code>// security config with filter 
      http.addFilterBefore(new APISignatureFilter(), OAuth2AuthenticationProcessingFilter.class).authorizeRequests().antMatchers("/error").permitAll().anyRequest().authenticated();
  </code></pre>
  
  <p>I have implemented OncePerRequestFilter &amp; it is not getting called for any request. This has to be called before OAuth filter.</p>
  
  <pre><code>@Component
  public class APISignatureFilter extends OncePerRequestFilter {
  
      @Override
      protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
              throws ServletException, IOException {
      }
   }
  </code></pre>
  
  <p>Let me know what is going wrong in this security config.</p>