Search in sources :

Example 6 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project best-cloud by shanzhaozhen.

the class AuthorizeApplicationTests method testPassword.

@Test
public void testPassword() throws IOException {
    // PasswordEncoder passwordEncoder = new DelegatingPasswordEncoder();
    PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    boolean matches = passwordEncoder.matches("secret", "$2a$10$eX5hrXVr5/QWXAEt1BzRneb.RJIPOYNVj6NjTBLPfRJbQhx4jjPU2");
    System.out.println(matches);
    String encode = passwordEncoder.encode("123456");
    System.out.println(encode);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project javaBook-src by huifer.

the class DefaultPasswordEncoderFactories method createDelegatingPasswordEncoder.

@SuppressWarnings("deprecation")
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());
    DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
    delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(new BCryptPasswordEncoder(10));
    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) 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) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 8 with DelegatingPasswordEncoder

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

the class PasswordUtils method createDelegatingPasswordEncoder.

/**
 * 创建一个密码加密的代理,方便后续切换密码的加密算法
 * @see PasswordEncoderFactories#createDelegatingPasswordEncoder()
 * @return DelegatingPasswordEncoder
 */
@SuppressWarnings("deprecation")
private static PasswordEncoder createDelegatingPasswordEncoder() {
    String encodingId = "bcrypt";
    Map<String, PasswordEncoder> encoders = new HashMap<>(10);
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    encoders.put(encodingId, 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());
    DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder(encodingId, encoders);
    // 设置默认的密码解析器,以便兼容历史版本的密码
    delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(bCryptPasswordEncoder);
    return delegatingPasswordEncoder;
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) Argon2PasswordEncoder(org.springframework.security.crypto.argon2.Argon2PasswordEncoder) 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 9 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project jakduk-api by JakduK.

the class PasswordEncoderTests method 스프링시큐리티_암호_인코딩.

@Test
public void 스프링시큐리티_암호_인코딩() {
    String password = passwordEncoder.encode("1111");
    Assert.assertFalse(passwordEncoder.matches("1112", password));
    Assert.assertTrue(passwordEncoder.matches("1111", password));
    DelegatingPasswordEncoder newPasswordEncoder = (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
    newPasswordEncoder.setDefaultPasswordEncoderForMatches(new StandardPasswordEncoder());
    System.out.println(newPasswordEncoder.encode("1111"));
    Assert.assertTrue(newPasswordEncoder.matches("1111", password));
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) Test(org.junit.Test)

Example 10 with DelegatingPasswordEncoder

use of org.springframework.security.crypto.password.DelegatingPasswordEncoder in project jakduk-api by JakduK.

the class SecurityConfig method passwordEncoder.

@Bean
public PasswordEncoder passwordEncoder() {
    DelegatingPasswordEncoder passwordEncoder = (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
    passwordEncoder.setDefaultPasswordEncoderForMatches(new StandardPasswordEncoder());
    return passwordEncoder;
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Aggregations

DelegatingPasswordEncoder (org.springframework.security.crypto.password.DelegatingPasswordEncoder)19 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)16 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)16 HashMap (java.util.HashMap)13 Bean (org.springframework.context.annotation.Bean)10 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)8 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)8 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)5 Argon2PasswordEncoder (org.springframework.security.crypto.argon2.Argon2PasswordEncoder)4 PlaceholderPasswordEncoder (com.ctrip.framework.apollo.portal.spi.oidc.PlaceholderPasswordEncoder)2 Before (org.junit.Before)2 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)2 CustomerRepository (org.terasoluna.tourreservation.domain.repository.customer.CustomerRepository)2 Test (org.junit.Test)1 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