配置loginProcessingUrl参数不起作用
来源:4-4 个性化用户认证流程(一)
二十四分之七倍根号六
2019-10-17
配置代码:
protected void configure(HttpSecurity http) throws Exception {
http.formLogin() // 表单登陆
.loginPage("/login.html") // 登陆页面
.loginProcessingUrl("/security/oneself/form") // 登陆表单提交请求
.and()
.authorizeRequests() // 对请求进行授权
.antMatchers("/login.html") // 指定相应的请求
.permitAll() // 不需要验证
.anyRequest() // 任何请求
.authenticated(); // 都需要身份认证
}
登陆代码:
<form method="post" action="/security/oneself/form">
<fieldset>
<legend>登陆</legend>
<label>账号:</label><input type="text" name="username"/></span>
<label>密码:</label><input type="password" name="password"/></span>
<button type="submit" class="btn">提交</button>
</fieldset>
</form>
但当我输入正确的密码登陆时,还是会跳转到登陆页面,也就是说不轮正确与否都还跳转到登陆页面,这啥啥原因啊,老师求解决。
写回答
2回答
-
慕码人1018289
2020-03-06
我也遇到了这个问题,我开Debug看日志,发现是CSRF的错误,只要配置
http.csrf().disable()
就可以了。这是为什么呢?
当发生CSRF问题的时候,或者说发送任何错误包括密码错误,Spring Security默认都会使其跳转到/error页面,而/error页面也要走Spring Security的流程,也就是那堆Filter,如果我们的配置没有.antMatchers("/error").permitAll() ,则会被重定向到登录页。大概我们使用的版本和老师的不同,老师不存在这个问题。
222020-05-21 -
JoJo
2019-10-21
跳转回来一定是用户名密码没验过,可以配一个AuthenticationFailureHandler看一下抛了什么异常,也可以跟一下代码看看是哪里没过,可以重点看一下PasswordEncoder的match方法是不是返回true.
00
Spring Security技术栈开发企业级认证与授权
Spring Security技术栈,REST风格开发常见接口,独立开发认证授权模块保证REST服务安全
2662 学习 · 1561 问题
相似问题