我想排除 url 的子部分,即我的 url 是 /eval/v2/save/public/image,此模式已通过身份验证,但有一个我想排除的 URI,并且该 URI 属于 /eval/ v2/**。 我已经尝试了下面的配置,但仍然为
OncePerRequestFilter
调用了我的自定义 save/public/images
,我尝试了 stackoverflow 本身的各种解决方案,但没有一个对我有用。
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
StringBuffer sb = constuctAntMatcher();
// http.headers().httpStrictTransportSecurity().includeSubDomains(true).maxAgeInSeconds(_MAX_AGE_IN_SEC);
return http.csrf().disable().cors().disable().authorizeRequests()
.antMatchers("/eval/v1/**").authenticated()
.antMatchers("/save/public/image").permitAll()
.and().formLogin().disable() // Disable default login page
.httpBasic().disable().addFilterBefore(userIdAuthenticationFilter(), DisableEncodeUrlFilter.class)
.build();
}
我知道我犯了错误,但问题是我无法弄清楚,任何帮助将不胜感激。
您可以尝试在身份验证之前设置允许所有吗:
return http.csrf().disable().cors().disable().authorizeRequests() .antMatchers("/save/public/image").permitAll() .antMatchers("/eval/v1/**").authenticated()