@Test(expected = IllegalArgumentException.class) public void constructorWhenIdForEncodeNullThenIllegalArgumentException() { new DelegatingPasswordEncoder(null, this.delegates); }
@Test(expected = IllegalArgumentException.class) public void constructorWhenIdForEncodeDoesNotExistThenIllegalArgumentException() { new DelegatingPasswordEncoder(this.bcryptId + "INVALID", this.delegates); }
@Before public void setup() { this.delegates = new HashMap<>(); this.delegates.put(this.bcryptId, this.bcrypt); this.delegates.put("noop", this.noop); this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates); }
@Test public void matchesWhenIdIsNullThenFalse() { this.delegates = new Hashtable<>(this.delegates); DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates); assertThatThrownBy(() -> passwordEncoder.matches(this.rawPassword, this.rawPassword)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("There is no PasswordEncoder mapped for the id \"null\""); verifyZeroInteractions(this.bcrypt, this.noop); }
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); return new DelegatingPasswordEncoder(encodingId, encoders);
@Test public void matchesWhenNullIdThenDelegatesToInvalidId() { this.delegates.put(null, this.invalidId); this.passwordEncoder = new DelegatingPasswordEncoder(this.bcryptId, this.delegates); when(this.invalidId.matches(this.rawPassword, this.encodedPassword)).thenReturn(true); assertThat(this.passwordEncoder.matches(this.rawPassword, this.encodedPassword)).isTrue(); verify(this.invalidId).matches(this.rawPassword, this.encodedPassword); verifyZeroInteractions(this.bcrypt, this.noop); }
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); return new DelegatingPasswordEncoder(encodingId, encoders);
@Bean public PasswordEncoder passwordEncoder() { // set up the list of supported encoders and their prefixes PasswordEncoder defaultEncoder = new StandardPasswordEncoder(); Map<String, PasswordEncoder> encoders = new HashMap<>(); encoders.put("bcrypt", new BCryptPasswordEncoder()); encoders.put("scrypt", new SCryptPasswordEncoder()); encoders.put("noop", NoOpPasswordEncoder.getInstance()); DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder("bcrypt", encoders); passwordEncoder.setDefaultPasswordEncoderForMatches(defaultEncoder); return passwordEncoder; }
/** * Create {@link DelegatingPasswordEncoder} with sha-256 as a default hash function. * * @return delegating password encoder */ public static PasswordEncoder createDelegatingPasswordEncoder() { final String encodingId = CredentialsConstants.HASH_FUNCTION_SHA256; final Map<String, PasswordEncoder> encoders = new HashMap<String, PasswordEncoder>(); encoders.put(encodingId, new MessageDigestPasswordEncoder("SHA-256")); encoders.put("pbkdf2", new Pbkdf2PasswordEncoder()); encoders.put("scrypt", new SCryptPasswordEncoder()); encoders.put(CredentialsConstants.HASH_FUNCTION_BCRYPT, new BCryptPasswordEncoder()); encoders.put(CredentialsConstants.HASH_FUNCTION_SHA512, new MessageDigestPasswordEncoder("SHA-512")); return new DelegatingPasswordEncoder(encodingId, encoders); } }
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); return new DelegatingPasswordEncoder(encodingId, encoders);
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); return new DelegatingPasswordEncoder(encodingId, encoders);
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder()); return new DelegatingPasswordEncoder(encodingId, encoders);