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中的静态常量用来存储登录用户的名字
![](https://i-blog.csdnimg.cn/blog_migrate/a86737df7114995d9fba68878bdd3a78.png)
再回到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);
这是它父类中的一个方法:如下图
![](https://i-blog.csdnimg.cn/blog_migrate/6324478239007d5ee5df80bf184d56ee.png)
public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException { return this.authenticator.authenticate(token);//找到了认证器组件 调用认证器的认证方法 }
进入了一个新的类
public final AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException { if (token