use of org.pac4j.core.credentials.password.ShiroPasswordEncoder in project pac4j by pac4j.
the class ShiroEncoderBuilder method tryCreatePasswordEncoder.
public void tryCreatePasswordEncoder(final Map<String, PasswordEncoder> encoders) {
for (int i = 0; i <= MAX_NUM_ENCODERS; i++) {
final String exists = getProperty(SHIRO_ENCODER, i);
final boolean hasProperty = containsProperty(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i) || containsProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i) || containsProperty(SHIRO_ENCODER_HASH_ITERATIONS, i) || containsProperty(SHIRO_ENCODER_PRIVATE_SALT, i);
if (isNotBlank(exists) || hasProperty) {
final DefaultPasswordService passwordService = new DefaultPasswordService();
if (hasProperty) {
final DefaultHashService hashService = new DefaultHashService();
if (containsProperty(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i)) {
hashService.setGeneratePublicSalt(getPropertyAsBoolean(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i));
}
if (containsProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i)) {
hashService.setHashAlgorithmName(getProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i));
}
if (containsProperty(SHIRO_ENCODER_HASH_ITERATIONS, i)) {
hashService.setHashIterations(getPropertyAsInteger(SHIRO_ENCODER_HASH_ITERATIONS, i));
}
if (containsProperty(SHIRO_ENCODER_PRIVATE_SALT, i)) {
hashService.setPrivateSalt(ByteSource.Util.bytes(getProperty(SHIRO_ENCODER_PRIVATE_SALT, i)));
}
passwordService.setHashService(hashService);
}
encoders.put(concat(SHIRO_ENCODER, i), new ShiroPasswordEncoder(passwordService));
}
}
}
Aggregations