对于一个初学者来说,使用框架是一件再简单快乐的事情不过了,但是框架隐的细节实在是太多了,想要用好框架,阅读源码是必不可少的事情,这次刨析可以省去大家来回查找动态绑定的子类过程,也作为自己学习的一次笔记。
首先从Subject的login()方法开始,这东西是万恶之源
login方法穿了一个参数token进去,记住token里面有页面提交的账号密码即可
调用的是实现类org.apache.shiro.subject.support.DelegatingSubject的login方法
这里我只把关键代码展示出来其他用"…"省略,有兴趣研究的同学可以自己对照源码查看
public void login(AuthenticationToken token) throws AuthenticationException {
...
Subject subject = securityManager.login(this, token);
...
}
securityManager又是一个接口这里调用的是实现类
org.apache.shiro.mgt.DefaultSecurityManager的login
public Subject login(Subject subject, AuthenticationToken token) throws AuthenticationException {
AuthenticationInfo info;
...
info = authenticate(token);
...
}
public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
return this.authenticator.authenticate(token);
}
那么这个this.authenticator是何方神圣呢?再构造方法中声明的
public AuthenticatingSecurityManager() {
super();
this.authenticator = new ModularRealmAuthenticator();