Search in sources :

Example 1 with ShiroPasswordEncoder

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));
        }
    }
}
Also used : DefaultPasswordService(org.apache.shiro.authc.credential.DefaultPasswordService) DefaultHashService(org.apache.shiro.crypto.hash.DefaultHashService) ShiroPasswordEncoder(org.pac4j.core.credentials.password.ShiroPasswordEncoder)

Aggregations

DefaultPasswordService (org.apache.shiro.authc.credential.DefaultPasswordService)1 DefaultHashService (org.apache.shiro.crypto.hash.DefaultHashService)1 ShiroPasswordEncoder (org.pac4j.core.credentials.password.ShiroPasswordEncoder)1