title: How do I add a rate limit filter before Oauth2 filters in Spring Boot
body: <p>I have a spring boot application that uses OAuth2 for authentication.  We need to rate limit attempts to sign in, the endpoint is <code>/oauth/token</code>.</p>
  
  <p>I have been unable to get a filter in front of this filter, but have not been able to.</p>
  
  <p>I've tried registering filters before BasicAuthenticationFilter in the <code>WebSecurityConfigurerAdapter</code>.</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
  @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Override
  protected void configure(final HttpSecurity http) throws Exception {
      http.addFilterBefore(filter, BasicAuthenticationFilter.class);
  }
  </code></pre>
  
  <p>I've also attempted to add this filter in the normal filter chains with order of <code>Integer.MIN_VALUE</code> where the security context has an order set via <code>application.properties</code> with the property <code>security.filter-order=5</code>.</p>
  
  <p>None of these have worked.</p>
  
  <p>Is there a "Spring" way to add api rate limiting? If it is via filters, is there a way to get a filter to be active before the <code>BasicAuthenticationFilter</code> or other security filters?</p>