【发布时间】:2020-10-15 18:16:28
【问题描述】:
我有一个 Spring Boot 应用程序和一个自定义身份验证过滤器。该应用程序有一个 URL“/”,我希望避免运行任何 Spring Security 过滤器(包括身份验证和授权),包括我的自定义过滤器。
我不想将WebSecurity 配置为忽略此 URL,因为我想应用一些其他 Spring Security 功能,我的理解是使用:
webSecurityBuilder.ignoring().antMatchers("/");
将阻止 所有 Spring Security 功能在此 URL 上运行。
有没有办法为此使用 HttpSecurity?
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomAuthenticationFilter customAuthFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/").
anonymous().and().authorizeRequests()
.antMatchers("/", "/index.html").permitAll()
.anyRequest().authenticated();
http.addFilterBefore(customAuthFilter, UsernamePasswordAuthenticationFilter.class);
}
这是我目前所拥有的,但由于某种原因,当我导航到“/”时,我仍然点击了我的自定义过滤器。
【问题讨论】:
标签: java spring spring-security