SpringSecurity认证流程详解-创新互联
SpringSecurity基本原理

在之前的文章《SpringBoot + Spring Security 基本使用及个性化登录配置》中对SpringSecurity进行了简单的使用介绍,基本上都是对于接口的介绍以及功能的实现。 这一篇文章尝试从源码的角度来上对用户认证流程做一个简单的分析。
在具体分析之前,我们可以先看看SpringSecurity的大概原理:
其实比较简单,主要是通过一系列的Filter对请求进行拦截处理。
认证处理流程说明
我们直接来看UsernamePasswordAuthenticationFilter类,
public class UsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter
// 登录请求认证
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
// 判断是否是POST请求
if (this.postOnly && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
} else {
// 获取用户,密码
String username = this.obtainUsername(request);
String password = this.obtainPassword(request);
if (username == null) {
username = "";
}
if (password == null) {
password = "";
}
username = username.trim();
// 生成Token,
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
this.setDetails(request, authRequest);
// 进一步验证
return this.getAuthenticationManager().authenticate(authRequest);
}
}
}
本文题目:SpringSecurity认证流程详解-创新互联
文章源于:http://www.lzwzjz.cn/article/cospjd.html


咨询
建站咨询
