【发布时间】:2018-07-14 04:24:08
【问题描述】:
我有一个使用 OAuth2 进行身份验证的 Spring Boot 应用程序。我们需要对登录尝试进行速率限制,端点是/oauth/token。
我一直无法在这个过滤器前面得到一个过滤器,但一直没能。
我尝试在 WebSecurityConfigurerAdapter 中的 BasicAuthenticationFilter 之前注册过滤器。
@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);
}
我还尝试将此过滤器添加到常规过滤器链中,顺序为Integer.MIN_VALUE,其中安全上下文的顺序通过application.properties 设置,属性为security.filter-order=5。
这些都不起作用。
是否有“春天”的方式来添加 api 速率限制?如果是通过过滤器,有没有办法让过滤器在BasicAuthenticationFilter 或其他安全过滤器之前激活?
【问题讨论】:
-
你可以试试
OncePerRequestFilterdocs.spring.io/spring/docs/current/javadoc-api/org/… -
您的订单错误,因为它太高了 (2147483640)。授权服务器安全配置的顺序为 0。所以你的配置没有被使用。您可以更改授权服务器安全配置,而不是创建其他配置。
-
使用 servlet 过滤器也应该可以工作,参见stackoverflow.com/questions/25957879/…。
标签: spring spring-mvc spring-boot spring-security