springboot post 请求报 403错误
由于使用的是 Spring Security,Spring Security 中默认是可以自动防御 CSRF 攻击的,所以我们要把这个关闭 ,
在SecurityConfig 配置文件中加入 .and().csrf().disable();
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/").hasAnyRole("train", "recruiter","manager")
.antMatchers("/emp/**").hasAnyRole("train", "recruiter")
.antMatchers("/emprp/**").hasAnyRole("train", "recruiter")
.antMatchers("/performance/**").hasAnyRole("train", "recruiter")
.antMatchers("/salary/**").hasAnyRole("train", "recruiter")
.antMatchers("/train/**").hasAnyRole("train", "recruiter")
.antMatchers("/wage/**").hasAnyRole("train", "recruiter").and().csrf().disable();
http.formLogin()
.loginPage("/toLogin").successForwardUrl("/index");
http.headers().frameOptions().sameOrigin();
http.headers().contentTypeOptions().disable();
}