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 {

本文深入探讨了Shiro框架的登录过程,从调用Subject的login方法开始,逐层剖析DelegatingSubject、安全管理器、AbstractAuthorizingRealm及其子类的内部实现。重点讲解了令牌的验证规则和唯一标识的含义,以及在SimpleAccountRealm中使用读写锁进行的认证信息缓存。
最低0.47元/天 解锁文章
894

被折叠的 条评论
为什么被折叠?



