Search in sources :

Example 1 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project spring-security by spring-projects.

the class PasswordEncoderFactories method createDelegatingPasswordEncoder.

/**
 * Creates a {@link DelegatingPasswordEncoder} with default mappings. Additional
 * mappings may be added and the encoding will be updated to conform with best
 * practices. However, due to the nature of {@link DelegatingPasswordEncoder} the
 * updates should not impact users. The mappings current are:
 *
 * <ul>
 * <li>bcrypt - {@link BCryptPasswordEncoder} (Also used for encoding)</li>
 * <li>ldap -
 * {@link org.springframework.security.crypto.password.LdapShaPasswordEncoder}</li>
 * <li>MD4 -
 * {@link org.springframework.security.crypto.password.Md4PasswordEncoder}</li>
 * <li>MD5 - {@code new MessageDigestPasswordEncoder("MD5")}</li>
 * <li>noop -
 * {@link org.springframework.security.crypto.password.NoOpPasswordEncoder}</li>
 * <li>pbkdf2 - {@link Pbkdf2PasswordEncoder}</li>
 * <li>scrypt - {@link SCryptPasswordEncoder}</li>
 * <li>SHA-1 - {@code new MessageDigestPasswordEncoder("SHA-1")}</li>
 * <li>SHA-256 - {@code new MessageDigestPasswordEncoder("SHA-256")}</li>
 * <li>sha256 -
 * {@link org.springframework.security.crypto.password.StandardPasswordEncoder}</li>
 * <li>argon2 - {@link Argon2PasswordEncoder}</li>
 * </ul>
 * @return the {@link PasswordEncoder} to use
 */
@SuppressWarnings("deprecation")
public static PasswordEncoder createDelegatingPasswordEncoder() {
    String encodingId = "bcrypt";
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put(encodingId, new BCryptPasswordEncoder());
    encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
    encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
    encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
    encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
    encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
    encoders.put("scrypt", new SCryptPasswordEncoder());
    encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
    encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
    encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
    encoders.put("argon2", new Argon2PasswordEncoder());
    return new DelegatingPasswordEncoder(encodingId, encoders);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) Argon2PasswordEncoder(org.springframework.security.crypto.argon2.Argon2PasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) HashMap(java.util.HashMap) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) Argon2PasswordEncoder(org.springframework.security.crypto.argon2.Argon2PasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 2 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project apollo by ctripcorp.

the class ApolloPasswordEncoderFactory method createDelegatingPasswordEncoder.

/**
 * Creates a {@link DelegatingPasswordEncoder} with default mappings {@link
 * PasswordEncoderFactories#createDelegatingPasswordEncoder()}, and add a placeholder encoder for
 * oidc {@link PlaceholderPasswordEncoder}
 *
 * @return the {@link PasswordEncoder} to use
 */
@SuppressWarnings("deprecation")
public static PasswordEncoder createDelegatingPasswordEncoder() {
    // copy from PasswordEncoderFactories, and it's should follow the upgrade of the PasswordEncoderFactories
    String encodingId = "bcrypt";
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put(encodingId, new BCryptPasswordEncoder());
    encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
    encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
    encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
    encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
    encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
    encoders.put("scrypt", new SCryptPasswordEncoder());
    encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
    encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
    encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
    encoders.put("argon2", new Argon2PasswordEncoder());
    // placeholder encoder for oidc
    encoders.put(PlaceholderPasswordEncoder.ENCODING_ID, new PlaceholderPasswordEncoder());
    DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
    // todo: adapt the old password, and it should be removed in the next feature version of the 1.9.x
    delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(new PasswordEncoderAdapter(encoders.get(encodingId)));
    return delegatingPasswordEncoder;
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) Argon2PasswordEncoder(org.springframework.security.crypto.argon2.Argon2PasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) PlaceholderPasswordEncoder(com.ctrip.framework.apollo.portal.spi.oidc.PlaceholderPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) HashMap(java.util.HashMap) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) Argon2PasswordEncoder(org.springframework.security.crypto.argon2.Argon2PasswordEncoder) PlaceholderPasswordEncoder(com.ctrip.framework.apollo.portal.spi.oidc.PlaceholderPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 3 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project webanno by webanno.

the class WebAnno method passwordEncoder.

// The WebAnno User model class picks this bean up by name!
@Bean
public PasswordEncoder passwordEncoder() {
    // Set up a DelegatingPasswordEncoder which decodes legacy passwords using the
    // StandardPasswordEncoder but encodes passwords using the modern BCryptPasswordEncoder
    String encoderForEncoding = "bcrypt";
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put(encoderForEncoding, new BCryptPasswordEncoder());
    DelegatingPasswordEncoder delegatingEncoder = new DelegatingPasswordEncoder(encoderForEncoding, encoders);
    // Decode legacy passwords without encoder ID using the StandardPasswordEncoder
    delegatingEncoder.setDefaultPasswordEncoderForMatches(new StandardPasswordEncoder());
    return delegatingEncoder;
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) HashMap(java.util.HashMap) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Example 4 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project collect by openforis.

the class PasswordStorageWebSecurityConfigurer method createPasswordEncoder.

@Bean
public PasswordEncoder createPasswordEncoder() {
    PasswordEncoder defaultEncoder = new OldPasswordEncoder();
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put(BCRYPT, new BCryptPasswordEncoder());
    encoders.put(SCRYPT, new SCryptPasswordEncoder());
    DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(BCRYPT, encoders);
    passwordEncoder.setDefaultPasswordEncoderForMatches(defaultEncoder);
    return passwordEncoder;
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) MD5PasswordEncoder(org.openforis.collect.manager.MD5PasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) HashMap(java.util.HashMap) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Example 5 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project MaxKey by dromara.

the class ApplicationAutoConfiguration method passwordEncoder.

/**
 * Authentication Password Encoder .
 * @return
 */
@Bean(name = "passwordEncoder")
public PasswordEncoder passwordEncoder() {
    String idForEncode = "bcrypt";
    Map<String, PasswordEncoder> encoders = new HashMap<String, PasswordEncoder>();
    encoders.put(idForEncode, new BCryptPasswordEncoder());
    encoders.put("plain", NoOpPasswordEncoder.getInstance());
    encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
    encoders.put("scrypt", new SCryptPasswordEncoder());
    // md
    encoders.put("md4", new Md4PasswordEncoder());
    encoders.put("md5", new MessageDigestPasswordEncoder("MD5"));
    // sha
    encoders.put("sha1", new StandardPasswordEncoder("SHA-1", ""));
    encoders.put("sha256", new StandardPasswordEncoder());
    encoders.put("sha384", new StandardPasswordEncoder("SHA-384", ""));
    encoders.put("sha512", new StandardPasswordEncoder("SHA-512", ""));
    encoders.put("sm3", new SM3PasswordEncoder());
    encoders.put("ldap", new LdapShaPasswordEncoder());
    // idForEncode is default for encoder
    PasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(idForEncode, encoders);
    if (_logger.isTraceEnabled()) {
        _logger.trace("Password Encoders :");
        for (String key : encoders.keySet()) {
            _logger.trace("{}= {}", String.format("%-10s", key), encoders.get(key).getClass().getName());
        }
    }
    _logger.debug("{} is default encoder", idForEncode);
    return passwordEncoder;
}
Also used : StandardPasswordEncoder(org.maxkey.crypto.password.StandardPasswordEncoder) Md4PasswordEncoder(org.maxkey.crypto.password.Md4PasswordEncoder) NoOpPasswordEncoder(org.maxkey.crypto.password.NoOpPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) LdapShaPasswordEncoder(org.maxkey.crypto.password.LdapShaPasswordEncoder) SM3PasswordEncoder(org.maxkey.crypto.password.SM3PasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) Md4PasswordEncoder(org.maxkey.crypto.password.Md4PasswordEncoder) MessageDigestPasswordEncoder(org.maxkey.crypto.password.MessageDigestPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) StandardPasswordEncoder(org.maxkey.crypto.password.StandardPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) HashMap(java.util.HashMap) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) MessageDigestPasswordEncoder(org.maxkey.crypto.password.MessageDigestPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) LdapShaPasswordEncoder(org.maxkey.crypto.password.LdapShaPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) SM3PasswordEncoder(org.maxkey.crypto.password.SM3PasswordEncoder) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)11 DelegatingPasswordEncoder (org.springframework.security.crypto.password.DelegatingPasswordEncoder)11 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)10 HashMap (java.util.HashMap)8 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)7 Bean (org.springframework.context.annotation.Bean)6 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)5 Argon2PasswordEncoder (org.springframework.security.crypto.argon2.Argon2PasswordEncoder)3 PlaceholderPasswordEncoder (com.ctrip.framework.apollo.portal.spi.oidc.PlaceholderPasswordEncoder)2 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)2 Test (org.junit.jupiter.api.Test)1 LdapShaPasswordEncoder (org.maxkey.crypto.password.LdapShaPasswordEncoder)1 Md4PasswordEncoder (org.maxkey.crypto.password.Md4PasswordEncoder)1 MessageDigestPasswordEncoder (org.maxkey.crypto.password.MessageDigestPasswordEncoder)1 NoOpPasswordEncoder (org.maxkey.crypto.password.NoOpPasswordEncoder)1 SM3PasswordEncoder (org.maxkey.crypto.password.SM3PasswordEncoder)1 StandardPasswordEncoder (org.maxkey.crypto.password.StandardPasswordEncoder)1 MD5PasswordEncoder (org.openforis.collect.manager.MD5PasswordEncoder)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1