SpringBoot Security 启动过程

启动流程图

Tomcat中StandardWrapperValve类调ApplicationFilterFactory获取filterChain
springSecurityFilterChain等放到数组里
获取FilterChain对象,传给DelegatingFilterProxy这个代理类处理
获取DelegatingFilterProxy bean
获取代理对象delegate,传入invokeDelegate
FilterChainProxy extends GenericFilterBean 代理类开始工作
AbstractAuthenticationProcessingFilter的doFilter
UsernamePasswordAuthenticationFilter类attemptAuthentication方法中
创建 UsernamePasswordAuthenticationToken
成功
失败,抛异常
http发送login请求
ApplicationFilterFactory中addFilter方法
ApplicationFilterChain implements FilterChain
DelegatingFilterProxy extends GenericFilterBean
Spring 启动
保存等待调用
invokeDelegate 中delegate调用doFilter
调用doFilter过滤器,一连串不同类doFilter的调用链
Authentication authenticationResult = this.attemptAuthentication...获取认证
下一步
验证用户名密码,返回Authentication
通过AuthenticationManager获取Authentication
调用successfulAuthentication方法
调用unsuccessfulAuthentication方法
下一个doFilter

在图中ApplicationFilterFactory负责组装过滤器链,请求过来时,代理类会去执行doFilter方法。

UsernamePasswordAuthenticationFilter //用户名密码认证过滤器

最主要的便是调用 AuthenticationManager 进行身份认证

attemptAuthentication 方法主要是获取参数(username、password),封装为验证请求(UsernamePasswordAuthenticationToken),然后调用AuthenticationManager 进行身份认证。
在这里插入图片描述1
拿到经过认证的Authentication之后,至此UsernamePasswordAuthenticationFilter的过滤步骤就完全结束了,之后就会进入BasicAuthenticationFilter,具体来说就是去调用successHandler。或者未通过认证,去调用failureHandler

待补充


  1. 图片来源 ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值