2021SC@SDUSC
AuthenticatingSecurityManager继承于RealmSecurityManager,RealmSecurityManager继承于CachingSecurityManager,CachingSecurityManager实现了SecurityManager接口
Shiro 支持 SecurityManager 类层次结构,该类层次结构将所有身份验证操作委托给包装的 Authenticator 实例。
也就是说,这个类实现SecurityManager 接口中的所有 Authenticator
方法,但实际上,这些方法只是对底层“真实”Authenticator 实例的传递调用。
含有变量
private Authenticator authenticator
含有方法
- public AuthenticatingSecurityManager
- public AuthenticatorgetAuthenticator
- public void setAuthenticator(Authenticator authenticator)
- protected void afterRealmsSet()
- public AuthenticationInfo authenticate(AuthenticationToken token)
- public void destroy()
变量分析
authenticator
此 SecurityManager 实例将用于执行所有身份验证操作的内部 Authenticator mdelegate 实例。
方法分析
AuthenticatingSecurityManager
public AuthenticatingSecurityManager() {
super();
this.authenticator = new ModularRealmAuthenticator();
}
默认的构造方法
AuthenticatorgetAuthenticator
public Authenticator getAuthenticator() {
return authenticator;
}
获得变量authenticator
setAuthenticator
public void setAuthenticator(Authenticator authenticator) throws IllegalArgumentException {
if (authenticator == null) {
String msg = “Authenticator argument cannot be null.”;
throw new IllegalArgumentException(msg);
}
this.authenticator = authenticator;
}
手动设置变量authenticator
afterRealmsSet
protected void afterRealmsSet() {
super.afterRealmsSet();
if (this.authenticator instanceof ModularRealmAuthenticator) {
((ModularRealmAuthenticator) this.authenticator).setRealms(getRealms());
}
}
将realm传递给内部委托 Authenticator 实例,以便它可以在身份验证尝试期间使用它们。
authenticate
public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
return this.authenticator.authenticate(token);
}
委托包装好的 Authenticator 进行身份验证。
destroy
public void destroy() {
LifecycleUtils.destroy(getAuthenticator());
this.authenticator = null;
super.destroy();
}
销毁authenticator对象