Java 使用Web安全性忽略非静态资源实际上是一种不好的做法吗?

Java 使用Web安全性忽略非静态资源实际上是一种不好的做法吗?,java,spring,spring-security,Java,Spring,Spring Security,假设在我的Spring安全配置中,我希望允许所有选项请求 对我来说,最简单的方法是: @Override public void configure(WebSecurity web) { web.ignoring().antMatchers(HttpMethod.OPTIONS); } 但是WebSecurity.ignering()的定义如下: @Override public void configure(WebSecurity web) { web.ignoring().

假设在我的Spring安全配置中,我希望允许所有
选项
请求

对我来说,最简单的方法是:

@Override
public void configure(WebSecurity web) {
    web.ignoring().antMatchers(HttpMethod.OPTIONS);
}
但是
WebSecurity.ignering()
的定义如下:

@Override
public void configure(WebSecurity web) {
    web.ignoring().antMatchers(HttpMethod.OPTIONS);
}
通常,已注册的请求应仅为的请求 静态资源

对于动态请求,请考虑映射 请求改为允许所有用户

因此,根据这一建议,我将使用
HttpSecurity

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers(HttpMethod.OPTIONS).permitAll();
}
这本身就是更多的代码,但假设我还想添加一个JWT过滤器:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
           .authorizeRequests()
           .antMatchers(HttpMethod.OPTIONS).permitAll()
           .antMatchers("/some_endpoint_that_needs_the_filter").authenticated();
}
如果我这样做,
过滤器
也将应用于
选项
请求,这不是我想要的。当然,我可以阻止它,但为了实现基本相同的目标,需要添加更多的代码

在这种(或任何其他)情况下,使用
WebSecurity.ignering()
是否有任何实际的缺点

为什么不建议使用
WebSecurity
忽略非静态资源