如何禁用某些资源路径的春季安全性



我正在弹簧启动应用程序中实现弹簧安全性,以执行我有过滤器和AuthenticationManager和Authentication Provider的JWT验证。我想做的是我想禁用某些资源路径的安全性(基本上使它们不安全(。

我在SecurityConfig类中尝试过的(从WebSecuirtyConfigurerAdapater延伸(如下:

protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.addFilterBefore(buildJwtTokenAuthenticationProcessingFilter(),
                UsernamePasswordAuthenticationFilter.class);
        httpSecurity.authorizeRequests().antMatchers("/**").permitAll();
        httpSecurity.csrf().disable();
        httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    } 

我现在想做的是我想让所有资源路径变得不安全,

但是上面的代码不起作用,我的 authenticate 在我的customAuthentication provider((中,每次都会执行从Authentication Provider (。

身份验证件被执行,无论在每个请求中使用许可证,都将执行。我也尝试了AnyRequest代替Antmatchers:

httpSecurity.authorizeRequests().anyRequest().permitAll();

任何帮助将不胜感激。

覆盖类中延伸WebsecuirtyConfigurerAdapater的以下方法:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/unsecurePage");
}

尝试更新代码,以便允许以下特定路径的请求

protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.addFilterBefore(buildJwtTokenAuthenticationProcessingFilter(),
                UsernamePasswordAuthenticationFilter.class);
        httpSecurity.authorizeRequests().antMatchers("/").permitAll().and()
            .authorizeRequests().antMatchers("/exemptedPaths/").permitAll();
httpSecurity.csrf().disable(); 
 httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
} 

最新更新