Shiro系列记录(二)——Shiro登录源码分析

前言

传送门:

Springboot整合Shiro实现登录登出

Shiro知识点概括

1、Shiro如何实现登录?

1.1 请求进入Controller  调用subject.login()

1.2 来到DelegatingSubject类,很明显还是securityManager干活

1.3 DefaultWebSecurityManager

该方法里会验证登录信息,如果登录通过会返回登录信息,如不通过则抛出异常;authenticate方法定义在父类AuthenticatingSecurityManager中

1.4  AuthenticatingSecurityManager

private Authenticator authenticator = new ModularRealmAuthenticator();

可以看到AuthenticatingSecurityManagerauthenticate方法交给了ModularRealmAuthenticator类来完成

ModularRealmAuthenticator 中的authenticate方法是继承自AbstractAuthenticator

 doAuthenticate是一个抽象方法

protected abstract AuthenticationInfo doAuthenticate(AuthenticationToken var1) throws AuthenticationException;

由子类ModularRealmAuthenticator来实现

    protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken) throws AuthenticationException {
        this.assertRealmsConfigured();
        Collection<Realm> realms = this.getRealms();
        return realms.size() == 1 ? this.doSingleRealmAuthentication((Realm)realms.iterator().next(), authenticationToken) : this.doMultiRealmAuthentication(realms, authenticationToken);
    }

这里可以看见Realm了,这里对单个Realm和多个Realm区分处理

我们直接看一下单个Realm如何处理的

这里就是真正调用Realm来实现登录了

看一下getAuthenticationInfo就懂了

第一个标记是从缓存中查看是否登录,

第二个标记就是自定义Realm中的身份认证方法了

第三个标记把此次的登录信息第二个标记中的身份认证方法从数据库中查询到的信息进行对比,信息一致则登录成功

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoneWalker、

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值