shiro设置加密算法源码解析

本文首次发布于My Blog,作者Ian,转载请保留原文链接。

自定义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);
    }
posted @ 2018-06-19 17:06  爱生活的阿琦  阅读(348)  评论(0编辑  收藏  举报