spring-boot - Spring Security 上的@PostMapping 403 错误我该如何解决?
问题描述
当我测试保存它工作正常但我收到 403 错误。
它之前确实有效,但在我更改了大部分 HTML 文件之后,它现在无法正常工作。
@RequiredArgsConstructor
@EnableWebSecurity // Enable Spring Security
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final CustomOAuth2UserService customOAuth2UserService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers()
.frameOptions().disable() // for using h2 console
.and()
.authorizeRequests() // authorizing by url and antMatchers require authorizeRequest()
.antMatchers("/api/v1/**").hasRole(Role.USER.name()) // url or http, only user can use /api/v1/**
.anyRequest().authenticated() // login user can use any other url
.antMatchers("/", "/css/**", "/images/**", "/js/**", "/h2-console/**", "/profile", "/index").permitAll()
.and()
.logout()
.logoutSuccessUrl("/")
.and()
.oauth2Login() // start OAuth2 login function
.userInfoEndpoint() // after login load user info
.userService(customOAuth2UserService); // after login function in service implement userService
}
}
后映射路径为/api/v1/posts
. 我也disalbed了csrf()
。Spring Boot 控制台上没有错误日志。