作者简介:大家好,我是smart哥,前中兴通讯、美团架构师,现某互联网公司CTO
联系qq:184480602,加我进群,大家一起学习,一起进步,一起对抗互联网寒冬
学习必须往深处挖,挖的越深,基础越扎实!
个性化用户认证流程1
前面使用spring security默认的认证流程。处理了自定义的用户数据,密码加密;
但是在实际开发中,肯定是要使用自己开发的页面、登录成功失败的业务处理等。
本节内容
* 自定义登录页
* 自定义登录成功处理
* 自定义登录失败处理
自定义登录页面
在cn.mrcode.imooc.springsecurity.securitybrowser.BrowserSecurityConfig中修改配置
http
// 定义表单登录 - 身份认证的方式
.formLogin()
.loginPage("/imocc-signIn.html")
.and()
.authorizeRequests()
// 放行这个路径
.antMatchers("/imocc-signIn.html").permitAll()
如果不对该静态文件放行的话,将会无限跳转,造成错误:localhost 将您重定向的次数过多。
对于html存放资源文件夹下的哪一个目录,这个有点懵逼:
最后放在static下面才能访问到
|- resources
|-static
|-imocc-signIn.html
html内容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>标准登录页面</title>
</head>
<body>
<h2>标准登录页面</h2>
<h3>表单登录</h3>
<form action="/authentication/form" method="post">
| 用户名:||
| :-----: | :-----: |
| 用户名: | |
| 密码: | |
| 登录 |
</form>
</body>
</html>
注意这里的路径:acrion="/authentication/form"
;路径是自定义的,
而UsernamePasswordAuthenticationFilter默认是处理/login
路径的登录请求
public UsernamePasswordAuthenticationFilter() {
super(new AntPathRequestMatcher("/login", "