Java Code Examples for org.springframework.security.crypto.password.DelegatingPasswordEncoder#setDefaultPasswordEncoderForMatches()
The following examples show how to use
org.springframework.security.crypto.password.DelegatingPasswordEncoder#setDefaultPasswordEncoderForMatches() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalSecurityConfig.java From airsonic with GNU General Public License v3.0 | 6 votes |
@Bean public PasswordEncoder delegatingPasswordEncoder() { // Spring Security 5 require storing the encoder id alongside the encoded password // (e.g. "{md5}hash" for an MD5-encoded password hash), which differs from previous // versions. // // Airsonic unfortunately stores passwords in plain-text, which is why we are setting // the "no-op" (plain-text) password encoder as a default here. This default will be // used when no encoder id is present. // // This means that legacy Airsonic passwords (stored simply as "password" in the db) // will be matched like "{noop}password" and will be recognized successfully. In the // future password encoding updates will be done here. PasswordEncoder defaultEncoder = NoOpPasswordEncoder.getInstance(); String defaultIdForEncode = "noop"; Map<String, PasswordEncoder> encoders = new HashMap<>(); encoders.put(defaultIdForEncode, defaultEncoder); DelegatingPasswordEncoder passworEncoder = new DelegatingPasswordEncoder(defaultIdForEncode, encoders); passworEncoder.setDefaultPasswordEncoderForMatches(defaultEncoder); return passworEncoder; }
Example 2
Source File: INCEpTION.java From inception with Apache License 2.0 | 5 votes |
@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; }
Example 3
Source File: WebAnno.java From webanno with Apache License 2.0 | 5 votes |
@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; }
Example 4
Source File: PasswordEncoderTests.java From jakduk-api with MIT License | 5 votes |
@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)); }