I have a spring boot application that uses OAuth2 for authentication. We need to rate limit attempts to sign in, the endpoint is /oauth/token
.
I have been unable to get a filter in front of this filter, but have not been able to.
I've tried registering filters before BasicAuthenticationFilter in the WebSecurityConfigurerAdapter
.
@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);
}
I've also attempted to add this filter in the normal filter chains with order of Integer.MIN_VALUE
where the security context has an order set via application.properties
with the property security.filter-order=5
.
None of these have worked.
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 BasicAuthenticationFilter
or other security filters?