我有这样的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,直到我通过了一些授权--这不适合这个endopint。
我假设这与.anyRequest().authenticated()有关。我以前读过,这不应该影响permitAll()-我是不是配置错了什么?
发布于 2021-06-18 09:02:15
您的请求可能会被拒绝,因为您未提供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发布于 2021-06-18 05:03:01
如果你正在使用jwt filter,即使你添加了permitAll() .if你移除了这个filter,它也不会工作,它会工作的很好。
https://stackoverflow.com/questions/68026319
复制相似问题