shiro login

1调用subject的login方法,suject去掉用DelegatingSubject实现类中的login(token)


clearRunAsIdentities

这个方法是用来清除没用的session,以下为详细实现

private void clearRunAsIdentities() {
    Session session = this.getSession(false);//查询session如果有则返回没有则null  如果参数为true则是没有就创建一个新的session
    if (session != null) {
        session.removeAttribute(RUN_AS_PRINCIPALS_SESSION_KEY);//清除特定的session
    }

}

这里就不得不提下

RUN_AS_PRINCIPALS_SESSION_KEY

这是DelegatingSubject中的静态常量用来存储登录用户的名字


再回到DelegatingSubject中的login发现它调用的是(侧面验证了Subject主体的所有请求都经过安全管理器的分发)

securityManager中的login(this//DelegatingSubject,token记录用户账号密码的验证信息)

进入这个login

public Subject login(Subject subject, AuthenticationToken token) throws AuthenticationException {
    AuthenticationInfo info;//声明的一个认证信息的对象
    try {
        info = this.authenticate(token);
    } catch (AuthenticationException var7) {
        AuthenticationException ae = var7;

        try {
            this.onFailedLogin(token, ae, subject);
        } catch (Exception var6) {
            if (log.isInfoEnabled()) {
                log.info("onFailedLogin method threw an exception.  Logging and propagating original AuthenticationException.", var6);
            }
        }

        throw var7;
    }
 
 Subject loggedIn = this.createSubject(token, info, subject);//当你登录成功 会根据你主体 验证信息创建一个新的主题对象
    this.onSuccessfulLogin(token, info, loggedIn);
//当你登录成功  内部会调用RememberMeManager记住你的登录主体对象  相当于id
return loggedIn ;}
进入
  info = this.authenticate(token);
这是它父类中的一个方法:如下图

public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
    return this.authenticator.authenticate(token);//找到了认证器组件 调用认证器的认证方法
}    
 

进入了一个新的类


public final AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
    if (token 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值