认证流程源码级详解(4-6节内容)

17 篇文章 0 订阅

一、认证处理流程说明

1、认证过程中涉及到的类

无

2、处理流程

1 、用户密码登录请求 -》 UsernamePasswordAuthenticationFilter 的 attemptAuthentication()  然后组装成一个

(1)Ctrl加鼠标左键点 UsernamePasswordAuthenticationToken 看到该类继承自 AbstractAuthenticationToken

(2)在点AbstractAuthenticationToken能看到实现了Authentication 接口

而 Authentication 是 封装了登录时的认证信息。

(3)UsernamePasswordAuthenticationToken的构造方法,super((Collection)null); 传到父类的权限集合是null所以this.setAuthenticated(false); 即没有通过身份认证。

(4)其中super((Collection)null); 点进去,可以看到是AbstractAuthenticationToken的构造方法,参数authorities是权限的集合,由于调用的时候不知道权限信息,所以传入的authorities是空的。

2、UsernamePasswordAuthenticationFilter类attemptAuthentication()的方法走到最后就进入了AuthenticationManager

AuthenticationManager的作用是管理AuthenticationProvider,找到AuthenticationManager的实现类ProviderManager的authenticate()方法

可以看到里面的AuthenticationProvider类型的,while()循环的原因是认证登录的方式多种多样,通过循环判断AuthenticationProvider的对象是否支持当前的验证类型。因此AuthenticationManager就需要把所有的AuthenticationProvider类型的对象收集起来。

因源码太过复杂故暂时跳过本节内容。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值