gpt4 book ai didi

spring - 如何禁用某些资源路径的Spring Security

转载 作者:行者123 更新时间:2023-12-02 07:10:07 24 4
gpt4 key购买 nike

我正在 Spring Boot 应用程序中实现 Spring Security,以执行 JWT 验证,其中我有一个过滤器、一个 AuthenticationManager 和一个 AuthenticationProvider。我想做的是禁用某些资源路径的安全性(使它们基本上不安全)。

我在 securityConfig 类(从 WebSecuirtyConfigurerAdapter 扩展)中尝试过的内容如下:

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

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

但是上面的代码不起作用,并且我的 CustomAuthenticationProvider (从 AuthenticationProvider 扩展)中的 authenticate 方法每次都会执行

无论是否在每个请求上使用permitAll,身份验证部分都会被执行。我也尝试过anyRequest来代替antMatchers:

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

如有任何帮助,我们将不胜感激。

最佳答案

在类中重写以下扩展 WebSecuirtyConfigurerAdapater 的方法:

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

关于spring - 如何禁用某些资源路径的Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44815432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com