跟着debug一起读shiro源码《二》
一、登录
1.controller登录入口
UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken(username,password,rememberMe);// 是用来存储用户和密码的
Subject subject = SecurityUtils.getSubject();
try {
//登录操作
subject.login(usernamePasswordToken);
2、DelegatingSubject类的login方法
因为自定义SecurityManager
进入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
执行结束