大佬教程收集整理的这篇文章主要介绍了401 请求,其中指定了 `permitAll()`,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个 WebSecurityConfigurerAdapter 配置:
@EnableWebSecurity
public class httpSecurityConfig extends WebSecurityConfigurerAdapter {
@OverrIDe
public voID configure(httpSecurity http) throws Exception {
http.cors()
.and()
.authorizerequests()
.mvcMatchers("/auth/**").permitAll()
.anyrequest().authenticated()
.and()
.oauth2resourceServer().jwt()
;
}
}
当我向 auth
发出请求时,我收到 401,直到我通过了一些授权 - 这不适合此内点。
我认为这与 .anyrequest().authenticated()
有关。我之前读过这不应该影响 permitAll()
- 我是否配置错误?
您的请求可能被拒绝,因为您没有提供 CSRF token。默认情况下,Spring Security 为每个 POST
请求启用它,您需要明确禁用它。
@EnableWebSecurity
public class httpSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(httpSecurity http) throws Exception {
http.cors()
.and()
.csrf().disable()
.authorizerequests()
.mvcMatchers("/auth/**").permitAll()
.anyrequest().authenticated()
.and()
.oauth2resourceServer().jwt();
}
}
您可以将以下属性添加到您的 application.yml
文件中,这样您就可以看到如果 CSRF 不是这种情况,您的请求被拒绝的原因:
logging:
level:
org.springframework.security: TRACE
,
以上是大佬教程为你收集整理的401 请求,其中指定了 `permitAll()`全部内容,希望文章能够帮你解决401 请求,其中指定了 `permitAll()`所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。