/** * HashedCredentialsMatcher,这个类是为了对密码进行编码的, * 防止密码在数据库里明码保存,当然在登陆认证的时候, * 这个类也负责对form里输入的密码进行编码。 */ @Bean(name = "hashedCredentialsMatcher") public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); credentialsMatcher.setHashAlgorithmName("MD5"); credentialsMatcher.setHashIterations(2); credentialsMatcher.setStoredCredentialsHexEncoded(true); return credentialsMatcher; }
public static CredentialsMatcher getCredentialsMatcher(final SecurityConfig securityConfig) { // This needs to be in sync with DefaultTenantDao final HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(HASH_ALGORITHM_NAME); // base64 encoding, not hex credentialsMatcher.setStoredCredentialsHexEncoded(false); credentialsMatcher.setHashIterations(securityConfig.getShiroNbHashIterations()); return credentialsMatcher; } }
public static CredentialsMatcher getCredentialsMatcher() { // This needs to be in sync with DefaultTenantDao final HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(HASH_ALGORITHM_NAME); // base64 encoding, not hex credentialsMatcher.setStoredCredentialsHexEncoded(false); credentialsMatcher.setHashIterations(HASH_ITERATIONS); return credentialsMatcher; } }
/** * 凭证匹配器 (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了 * 所以我们需要修改下doGetAuthenticationInfo中的代码; @return */ @Bean public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(); hashedCredentialsMatcher.setHashAlgorithmName("md5");// 散列算法:这里使用MD5算法; hashedCredentialsMatcher.setHashIterations(2);// 散列的次数,比如散列两次,相当于md5(md5("")); hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);//表示是否存储散列后的密码为16进制,需要和生成密码时的一样,默认是base64; return hashedCredentialsMatcher; }
/*** * 密码凭证匹配器 * @return */ @Bean @ConditionalOnMissingBean public CredentialsMatcher hashedCredentialsMatcher(RedisTemplate<Object,Object> redisTemplate) { HashedCredentialsMatcher matcher=new RetryLimitHashedCredentialsMatcher(redisTemplate); matcher.setHashAlgorithmName ("SHA-512"); //散列的次数,比如散列两次 matcher.setHashIterations (2); matcher.setStoredCredentialsHexEncoded (Boolean.TRUE); return matcher; }
/** * 凭证匹配器 (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了 * 所以我们需要修改下doGetAuthenticationInfo中的代码; ) * @return */ @Bean public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(); hashedCredentialsMatcher.setHashAlgorithmName("md5");// 散列算法:这里使用MD5算法; hashedCredentialsMatcher.setHashIterations(3);// 散列的次数,比如散列两次,相当于md5(md5("")); hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true); return hashedCredentialsMatcher; }
public static CredentialsMatcher getCredentialsMatcher(final SecurityConfig securityConfig) { // This needs to be in sync with DefaultTenantDao final HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(HASH_ALGORITHM_NAME); // base64 encoding, not hex credentialsMatcher.setStoredCredentialsHexEncoded(false); credentialsMatcher.setHashIterations(securityConfig.getShiroNbHashIterations()); return credentialsMatcher; } }
/** * 凭证匹配器 (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了 * 所以我们需要修改下doGetAuthenticationInfo中的代码; @return */ @Bean public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher hashedCredentialsMatcher = new RetryLimitCredentialsMatcher(redisCacheManager()); hashedCredentialsMatcher.setHashAlgorithmName("md5");// 散列算法:这里使用MD5算法; hashedCredentialsMatcher.setHashIterations(2);// 散列的次数,比如散列两次,相当于md5(md5("")); hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);// 表示是否存储散列后的密码为16进制,需要和生成密码时的一样,默认是base64; return hashedCredentialsMatcher; }
@Override protected WebEnvironment createEnvironment(ServletContext sc) { WebEnvironment webEnvironment = super.createEnvironment(sc); RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment .getSecurityManager(); HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher( HASHING_ALGORITHM); hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true); jpaRealm.setCredentialsMatcher(hashedCredentialsMatcher); Collection<Realm> realms = rsm.getRealms(); realms.add(jpaRealm); rsm.setRealms(realms); ((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm); return webEnvironment; } }