Spring Boot 2.1.5.RELEASE Spring Security 版本:5.1.5-RELEASE Spring Security 官方文档
AbstractAuthenticationProcessingFilter
是 进行用户凭证认证的基础过滤器。不过在进行身份认证前 Spring Security 通常会使用 AuthenticationEntryPoint
请求凭证。
接下来,AbstractAuthenticationProcessingFilter可以验证提交给它的任何身份验证请求。
处理流程逻辑图如下:
流程步骤:
step1、
当用户提交他们的凭证,
AbstractAuthenticationProcessingFilter
从要本认证的 HttpServletRequest 创建一个身份认证。创建的Authentication
类型取决于AbstractAuthenticationProcessingFilter
子类。例如:UsernamePasswordAuthenticationFilter
根据 HttpServletRequest 提交的 username 和 password 创建一个UsernamePasswordAuthenticationToken
。
step2、
接下来,
Authentication
通过AuthenticationManager
进行身份认证。
step3、如果认证失败
- SecurityContextHolder 清除
- 如果配置了记住我,调用
RememberMeServices.loginFail
- 调用
AuthenticationFailureHandler
step4、身份认证成功
SessionAuthenticationStrategy
通知一个新的登陆- 将
Authentication
设置到SecurityContextHolder
。稍后,SecurityContextPersistenceFilter将SecurityContext保存到HttpSession中 - 如果配置了记住我,调用
RememberMeService.loginSuccess
- 通过
ApplicationEventPublisher
发布InteractiveAuthenticationSuccessEvent
事件 - 调用
AuthenticationSuccessHandler