我的 WebSecurityConfig
有以下配置方法,它扩展了 WebSecurityConfigurerAdapter
:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/login").permitAll()
.and()
.authorizeRequests()
.antMatchers("/signup").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.addFilterBefore(
new JWTAuthenticationFilter(userDetailsServiceBean()),
UsernamePasswordAuthenticationFilter.class);
}
JWTAuthenticationFilter
实际上过滤所有端点上收到的请求,并检查它们的 header 中是否具有正确的 JWT 身份验证 token 。
我不希望此过滤器对向 /login
端点发出的请求执行!有没有办法忽略特殊端点的过滤器? (这里是 /login
和 /signup
)。
是否有任何充分的理由让此过滤器对向所有端点(包括 login
和 signup
)发出的请求执行?
最佳答案
您可以尝试添加以下内容
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/login**", "/signup**");
}
关于java - 忽略对特定端点发出的请求执行的过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995085/