这可能是最详细的shiro密码验证原理解析

本文深入剖析了Apache Shiro的密码验证流程,从Subject的login()方法开始,逐步解析了DefaultSecurityManager、ModularRealmAuthenticator、AbstractAuthenticator、AuthenticatingRealm等关键组件的作用。核心在于doCredentialsMatch()方法,该方法通过PasswordMatcher和SimpleCredentialsMatcher进行密码匹配。整个过程中,Shiro将用户输入的账号密码与从数据库查询的账号密码进行对比,确保匹配无误。
摘要由CSDN通过智能技术生成

对于一个初学者来说,使用框架是一件再简单快乐的事情不过了,但是框架隐的细节实在是太多了,想要用好框架,阅读源码是必不可少的事情,这次刨析可以省去大家来回查找动态绑定的子类过程,也作为自己学习的一次笔记。
首先从Subject的login()方法开始,这东西是万恶之源
login方法穿了一个参数token进去,记住token里面有页面提交的账号密码即可

调用的是实现类org.apache.shiro.subject.support.DelegatingSubject的login方法
这里我只把关键代码展示出来其他用"…"省略,有兴趣研究的同学可以自己对照源码查看

 public void login(AuthenticationToken token) throws AuthenticationException {
   
        ...

        Subject subject = securityManager.login(this, token);

       ...
    }

securityManager又是一个接口这里调用的是实现类
org.apache.shiro.mgt.DefaultSecurityManager的login

 public Subject login(Subject subject, AuthenticationToken token) throws AuthenticationException {
   
        AuthenticationInfo info;
       ...
            info = authenticate(token);
       ...
 }
 public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
   
        return this.authenticator.authenticate(token);
    }

那么这个this.authenticator是何方神圣呢?再构造方法中声明的

 public AuthenticatingSecurityManager() {
   
        super();
        this.authenticator = new ModularRealmAuthenticator();
   
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值