Correctly handle password promnpt in CLI

This commit is contained in:
James Agnew 2018-10-01 11:59:47 -04:00
parent 3fd86efa73
commit 87f90fec47
2 changed files with 18 additions and 8 deletions

View File

@ -90,18 +90,23 @@ public abstract class BaseCommand implements Comparable<BaseCommand> {
protected String promptUser(String thePrompt) throws ParseException {
System.out.print(ansi().bold().fgBrightDefault());
System.out.print(thePrompt);
System.out.print(ansi().bold().fgBrightGreen());
System.out.print(ansi().boldOff().fgBlack().bgDefault());
System.out.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Console console = System.console();
String retVal;
try {
retVal = reader.readLine();
} catch (IOException e) {
throw new ParseException("Failed to read input from user: " + e.toString());
if (console == null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
retVal = reader.readLine();
} catch (IOException e) {
throw new ParseException("Failed to read input from user: " + e.toString());
}
} else {
retVal = new String(console.readPassword());
}
System.out.print(ansi().boldOff().fgDefault());
System.out.print(ansi().boldOff().fgDefault().bgDefault());
return retVal;
}
@ -254,7 +259,8 @@ public abstract class BaseCommand implements Comparable<BaseCommand> {
if (theCommandLine.hasOption(theOptionName)) {
String optionValue = theCommandLine.getOptionValue(theOptionName);
if (PROMPT.equals(optionValue)) {
promptUser("Enter Basic Auth Credentials (format is \"username:password\"): ");
optionValue = promptUser("Enter Basic Auth Credentials (format is \"username:password\"): ");
optionValue = trim(optionValue);
}
byte[] basicAuth = optionValue.getBytes();

View File

@ -44,6 +44,10 @@
The JPA database migrator tool has been enhanced so that it now supports migrations from
HAPI FHIR 3.3.0 to HAPI FHIR 3.4.0 / 3.5.0+ as well.
</action>
<action type="fix">
When using the HAPI FHIR CLI, user-prompted passwords were not correctly encoded, meaning that the
"--basic-auth PROMPT" action was not usable. This has been corrected.
</action>
</release>
<release version="3.5.0" date="2018-09-17">