[英]InsufficientAuthenticationException: Full authentication is required to access this resource
[英]POST request org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource
使用 spring 安全与 jwt。
我的 spring 安全配置:
@RequiredArgsConstructor
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final JwtFilter jwtFilter;
private final exceptionHandler exceptionHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/api/v1/users/**").hasAnyRole("USER")
.antMatchers("/api/v1/admin/**").hasRole("ADMIN")
.anyRequest()
.authenticated()
.and()
.addFilterBefore(jwtFilter, FilterSecurityInterceptor.class)
.exceptionHandling().authenticationEntryPoint(exceptionHandler);
}
}
当我发送 GET 请求时,一切都很好。 但是当我发送 POST 时:
org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource
如果我添加.csrf().disable()
它会有所帮助,但我不明白它是如何工作的。 为什么 Get 请求正常,但没有.csrf().disable()
抛出异常?
我可以在没有.csrf().disable()
部分的情况下传递 POST 请求吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.