Commit c8257b38 authored by Phillip Webb's avatar Phillip Webb

Add algorithm prefix to encoded password

Update the CLI encodepassword command to also include the algorithm
prefix.

Closes gh-11875
parent 1e3bae9b
...@@ -100,7 +100,7 @@ public class EncodePasswordCommand extends OptionParsingCommand { ...@@ -100,7 +100,7 @@ public class EncodePasswordCommand extends OptionParsingCommand {
.collectionToCommaDelimitedString(ENCODERS.keySet())); .collectionToCommaDelimitedString(ENCODERS.keySet()));
return ExitStatus.ERROR; return ExitStatus.ERROR;
} }
Log.info(encoder.get().encode(password)); Log.info("{" + algorithm + "}" + encoder.get().encode(password));
return ExitStatus.OK; return ExitStatus.OK;
} }
......
...@@ -25,8 +25,7 @@ import org.mockito.MockitoAnnotations; ...@@ -25,8 +25,7 @@ import org.mockito.MockitoAnnotations;
import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.command.status.ExitStatus;
import org.springframework.boot.cli.util.MockLog; import org.springframework.boot.cli.util.MockLog;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -59,8 +58,9 @@ public class EncodePasswordCommandTests { ...@@ -59,8 +58,9 @@ public class EncodePasswordCommandTests {
EncodePasswordCommand command = new EncodePasswordCommand(); EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("boot"); ExitStatus status = command.run("boot");
verify(this.log).info(this.message.capture()); verify(this.log).info(this.message.capture());
assertThat(new BCryptPasswordEncoder().matches("boot", this.message.getValue())) assertThat(this.message.getValue()).startsWith("{bcrypt}");
.isTrue(); assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder()
.matches("boot", this.message.getValue())).isTrue();
assertThat(status).isEqualTo(ExitStatus.OK); assertThat(status).isEqualTo(ExitStatus.OK);
} }
...@@ -69,8 +69,9 @@ public class EncodePasswordCommandTests { ...@@ -69,8 +69,9 @@ public class EncodePasswordCommandTests {
EncodePasswordCommand command = new EncodePasswordCommand(); EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("-a", "pbkdf2", "boot"); ExitStatus status = command.run("-a", "pbkdf2", "boot");
verify(this.log).info(this.message.capture()); verify(this.log).info(this.message.capture());
assertThat(new Pbkdf2PasswordEncoder().matches("boot", this.message.getValue())) assertThat(this.message.getValue()).startsWith("{pbkdf2}");
.isTrue(); assertThat(PasswordEncoderFactories.createDelegatingPasswordEncoder()
.matches("boot", this.message.getValue())).isTrue();
assertThat(status).isEqualTo(ExitStatus.OK); assertThat(status).isEqualTo(ExitStatus.OK);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment