try {
boolean hasToken = (token != null);
boolean hasTokenOptions = !loginOptions.isEmpty();
if (hasToken && password != null) {
throw new ParameterException("Can not supply '--pass' option with '--tokenClass' option");
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
reader.getTerminal().setEchoEnabled(true);
}
});
// Need either both a token and options, or neither, but not just one.
if (hasToken != hasTokenOptions) {
throw new ParameterException("Must supply either both or neither of '--tokenClass' and '--tokenProperty'");
} else if (hasToken) { // implied hasTokenOptions
// Fully qualified name so we don't shadow java.util.Properties
org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties props;
// and line wrap it because the package name is so long
props = new org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties();
props.putAllStrings(loginOptions);
token.init(props);
} else {
// Read password if the user explicitly asked for it, or didn't specify anything at all
if ("stdin".equals(password) || password == null) {
password = reader.readLine("Password: ", '*');
}
if (password == null) {
// User cancel, e.g. Ctrl-D pressed
throw new ParameterException("No password or token option supplied");
} else {
this.token = new PasswordToken(password);
}
}