如何仅在受保护的端点上应用Spring安全过滤器?
2022-08-31 21:01:29
我有以下Spring Security配置:
httpSecurity
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/**").fullyAuthenticated()
.and()
.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
即使在与表达式不匹配的终结点上也会应用 。我还尝试添加以下配置代码:authenticationTokenFilterBean()
/api/**
@Override
public void configure(WebSecurity webSecurity) {
webSecurity.ignoring().antMatchers("/some_endpoint");
}
但这仍然没有解决我的问题。如何告诉Spring Security仅在与安全URI表达式匹配的端点上应用过滤器?