shiro使用自定义session和redis源码解析登录过程

一、登录

1.controller登录入口

  UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken(username,password,rememberMe);// 是用来存储用户和密码的
   
        Subject subject = SecurityUtils.getSubject();
        try {
            //登录操作
            subject.login(usernamePasswordToken);

2、DelegatingSubject类的login方法

在这里插入图片描述
因为自定义SecurityManager
图1进入DefaultWebSecurityManager
在这里插入图片描述
在这里插入图片描述
调用自定义realm
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

3、进入自定义Realm 类的 doGetAuthenticationInfo方法

在这里插入图片描述

二、写入缓存

在这里插入图片描述

1、加载登录信息和db中对应的用户信息后再次回到

 public final AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        AuthenticationInfo info = getCachedAuthenticationInfo(token);
        if (info == null) {
            //otherwise not cached, perform the lookup:
            info = doGetAuthenticationInfo(token);//进入realm 密码认证方法
            log.debug("Looked up AuthenticationInfo [{}] from doGetAuthenticationInfo", info);
            if (token != null && info != null) {
                cacheAuthenticationInfoIfPossible(token, info);//缓存方法
            }
        } else {
            log.debug("Using cached authentication info [{}] to perform credentials matching.", info);
        }

        if (info != null) {
            assertCredentialsMatch(token, info);//密码校验
        } else {
            log.debug("No AuthenticationInfo found for submitted AuthenticationToken [{}].  Returning null.", token);
        }

        return info;
    }

2、缓存

在这里插入图片描述

3、密码校验

获取自定义密码比较器
在这里插入图片描述
在这里插入图片描述
再次回到DefaultSecurityManager
在这里插入图片描述
回到DelegatingSubject
在这里插入图片描述

执行结束
在这里插入图片描述

声明
纯属个人理解和参考大佬的博客理解
大佬博客1
大佬博客2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值