Spring Security-AuthenticationManager执行登录认证过程

1.AuthenticationManager是一个接口,只有一个方法 authenticate,入参和返回值都 Authentication。

AuthenticationManager接口:

2.ProviderManager实现了AuthenticationManager接口,ProviderManager委托AuthenticationProvider接口去实现认证过程,有个抽象方法authenticate

ProviderManager实现的authenticate方法:

 AuthenticationProvider接口:

3.AbstractUserDetailsAuthenticationProvider实现了AuthenticationProvider接口并实现了authenticate方法,DaoAuthenticationProvider类继承了AbstractUserDetailsAuthenticationProvider,登录过程是在AbstractUserDetailsAuthenticationProvider的AuthenticationProvider方法中认证。

4. 调用DaoAuthenticationProvider的retrieveUser获取用户信息UserDetails,参数是根据用户名

5.获取到用户信息后,进行三次检查。

首先调用内部类DefaultPreAuthenticationChecks的check检查用户是否锁定,是否可用,账号是否过期

  然后调用 DaoAuthenticationProvider类的additionalAuthenticationChecks方法校验用户的密码是否正确

最后调用内部类DefaultPostAuthenticationChecks的check方法验证用户的认证凭证是否过期(一般指密码 )

6.都验证通过后,会调用createSuccessAuthentication方法创建一个认证过的UsernamePasswordAuthenticationToken实例,传入账号,密码,权限。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值