我使用spring-boot和spring-security来构建项目,使用404错误的自定义登录页面,我想做的是分离登录页面和项目,并在登录页面上验证使用Ajax URL发送的用户信息,但总是错误403,我更改了spring boot安全配置的配置信息,但没有特定的效果 . 以下代码:
@Override
public void configure(HttpSecurity http) throws Exception{
http.authorizeRequests()
.anyRequest().authenticated()
.antMatchers("/index.html").permitAll()
.and()
.formLogin().usernameParameter("username")
.passwordParameter("password")
.loginProcessingUrl("/login")
.loginPage("/login")
.failureUrl("/login?error")
.permitAll()
.and()
.logout().permitAll();
}
发送帖子网址:localhost:8888 / login
params:用户名,密码
回复:403
错误信息 :
此应用程序没有/ error的显式映射,因此您将此视为回退 .
出现意外错误(type = Forbidden,status = 403) .
未找到预期的csrf令牌 . 你的会话已经过期了吗?
1 回答
您必须配置post以包含Spring Security中的csrf令牌 . 您必须在POST请求中设置标头参数“X-CSRF-TOKEN” . 示例POST请求: