Shiro认证原理详解

本文详细解析了Shiro认证流程,包括Subject执行登录方法、SecurityManager代理执行、DefaultSecurityManager的具体实现、调用authenticate方法、Authenticator实现类的使用、ModularRealmAuthenticator的doAuthenticate方法、Realm的getAuthenticationInfo方法及密码匹配过程。

草根猿,仅为自己做个笔记


获取subject  执行login()方法



查看Subject实现类知,登录过程由SecurityManager代理执行

由其实现类DefaultSecurityManager实现


接着调用自己的authenticate(token)方法


然后SecurityManager的实现将authenticate()方法代理给Authenticator的实现类去实现


已知的实现该方法的实现类 AbstractAuthenticator和ModularRealmAuthenticator


而doAuthenticate由ModularRealmAuthenticator实现


然后调用自己的doSingleRealmAuthentication 方法


最终由Realm来调用getAuthenticationInfo()方法,而我们继承的AuthenticatingRealm对getAuthenticationInfo()做了实现,

并且回调了我们的dogetAuthenticationInfo()方法 并且拿到了info信息,根据我们自己的实现知里面包含了从数据库查询的用户所有信息


getAuthenticationInfo()实现中调用方法assertCredentialsMatch(token, info)


该方法中实例化了 一个CredentialsMatcher对象,调用doCredentialsMatch()方法,其实现类SimpleCredentialsMatcher对该方法做了实现

在其中的equals()方法中对密码进行了比对


至此shiro认证结束,写的比较毛躁,因为要下班了

参考博客:https://blog.youkuaiyun.com/w1196726224/article/details/53560385

                https://blog.youkuaiyun.com/acmman/article/details/78446008

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值