Shiro认证原理详解

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

Shiro认证原理详解

获取subject  执行login()方法

Shiro认证原理详解

Shiro认证原理详解

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

由其实现类DefaultSecurityManager实现

Shiro认证原理详解

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

Shiro认证原理详解

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

Shiro认证原理详解

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

Shiro认证原理详解

而doAuthenticate由ModularRealmAuthenticator实现

Shiro认证原理详解

然后调用自己的doSingleRealmAuthentication 方法

Shiro认证原理详解

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

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

Shiro认证原理详解

Shiro认证原理详解

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

Shiro认证原理详解

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

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

Shiro认证原理详解

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

参考博客:https://blog.****.net/w1196726224/article/details/53560385

                https://blog.****.net/acmman/article/details/78446008