本文首次发布于,作者,转载请保留原文链接。
自定义Realm继承AuthorizingRealm父类。
HashedCredentialsMatcher 实例化并设置加密算法。源码:
public AuthorizingRealm(CredentialsMatcher matcher) { this((CacheManager)null, matcher); }设置迭代次数: public void setHashIterations(int hashIterations) { if (hashIterations < 1) { this.hashIterations = 1; } else { this.hashIterations = hashIterations; } }
最后把实例化HashedCredentialsMatcher对象通过父类构造方法设置。
源码:
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) { this.credentialsMatcher = credentialsMatcher; } public interface CredentialsMatcher { boolean doCredentialsMatch(AuthenticationToken var1, AuthenticationInfo var2); } HashedCredentialsMatcher实现CredentialsMatcher接口
源码:
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { Object tokenHashedCredentials = this.hashProvidedCredentials(token, info); Object accountCredentials = this.getCredentials(info); return this.equals(tokenHashedCredentials, accountCredentials); }