EncodePasswordCommand Class — spring-boot Architecture
Architecture documentation for the EncodePasswordCommand class in EncodePasswordCommand.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommand.java lines 50–115
public class EncodePasswordCommand extends OptionParsingCommand {
private static final Map<String, Supplier<PasswordEncoder>> ENCODERS;
static {
Map<String, Supplier<PasswordEncoder>> encoders = new LinkedHashMap<>();
encoders.put("default", PasswordEncoderFactories::createDelegatingPasswordEncoder);
encoders.put("bcrypt", BCryptPasswordEncoder::new);
encoders.put("pbkdf2", Pbkdf2PasswordEncoder::defaultsForSpringSecurity_v5_8);
ENCODERS = Collections.unmodifiableMap(encoders);
}
public EncodePasswordCommand() {
super("encodepassword", "Encode a password for use with Spring Security", new EncodePasswordOptionHandler());
}
@Override
public String getUsageHelp() {
return "[options] <password to encode>";
}
@Override
public Collection<HelpExample> getExamples() {
List<HelpExample> examples = new ArrayList<>();
examples.add(new HelpExample("To encode a password with the default (bcrypt) encoder",
"spring encodepassword mypassword"));
examples.add(new HelpExample("To encode a password with pbkdf2", "spring encodepassword -a pbkdf2 mypassword"));
return examples;
}
private static final class EncodePasswordOptionHandler extends OptionHandler {
@SuppressWarnings("NullAway.Init")
private OptionSpec<String> algorithm;
@Override
protected void options() {
this.algorithm = option(Arrays.asList("algorithm", "a"),
"The algorithm to use. Supported algorithms: "
+ StringUtils.collectionToDelimitedString(ENCODERS.keySet(), ", ")
+ ". The default algorithm uses bcrypt")
.withRequiredArg()
.defaultsTo("default");
}
@Override
protected ExitStatus run(OptionSet options) {
if (options.nonOptionArguments().size() != 1) {
Log.error("A single password option must be provided");
return ExitStatus.ERROR;
}
String algorithm = options.valueOf(this.algorithm);
String password = (String) options.nonOptionArguments().get(0);
Supplier<PasswordEncoder> encoder = ENCODERS.get(algorithm);
if (encoder == null) {
Log.error("Unknown algorithm, valid options are: "
+ StringUtils.collectionToCommaDelimitedString(ENCODERS.keySet()));
return ExitStatus.ERROR;
}
Log.info(encoder.get().encode(password));
return ExitStatus.OK;
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free