编程之路 Shiro设置加密算法源码解析

作者: 爱生活的阿琦 | 2018-04-18 | 阅读

layout: post # 使用的布局(不需要改) title: shiro设置加密算法源码解析 # 标题 subtitle: #副标题 date: 2018-04-18 # 时间 author: Ian # 作者 header-img: img/post-bg-re-vs-ng2.jpg #这篇文章标题背景图片 catalog: true # 是否归档 iscopyright: true # 是否版权 tags: #标签 - 编程之路 - 鉴权 —

自定义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);
    }



留言区:

TOP