Java 自定义自动生成表单中的Post请求返回403
尝试创建自定义AuthenticationProvider。现在只需添加println,检查是否使用Spring这个类。就在那里开始了一些奇怪的事情: 以官方文件为例:Java 自定义自动生成表单中的Post请求返回403,java,spring-mvc,spring-security,Java,Spring Mvc,Spring Security,尝试创建自定义AuthenticationProvider。现在只需添加println,检查是否使用Spring这个类。就在那里开始了一些奇怪的事情: 以官方文件为例: http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .and() .httpBasic(); Spring执行我的自定义AuthenticationProv
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
Spring执行我的自定义AuthenticationProvider。然后以自定义登录页面为例:
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
视图:
页面将打开,但如果我们尝试按
submit
,它将返回403。Сustom AuthenticationProvider不返回任何内容。已启用Spring安全默认csrf选项。如果您在没有csrf令牌的情况下发布,Spring Security将生成403禁止的错误http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.csrf()
.disabled();
或者在表单中附加csrf令牌
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.csrf()
.disabled();