BooleanArgument trustAll;
FileBasedArgument bindPWFile;
FileBasedArgument keyStorePWFile;
FileBasedArgument trustStorePWFile;
IntegerArgument port;
StringArgument bindDN;
StringArgument bindPW;
StringArgument certNickname;
StringArgument host;
StringArgument keyStoreFile;
StringArgument keyStorePW;
StringArgument saslOption;
StringArgument targetDN;
StringArgument trustStoreFile;
StringArgument trustStorePW;
try
{
host = new StringArgument("host", OPTION_SHORT_HOST,
OPTION_LONG_HOST, false, false, true,
INFO_HOST_PLACEHOLDER.get(), "127.0.0.1", null,
INFO_PWPSTATE_DESCRIPTION_HOST.get());
argParser.addGlobalArgument(host);
port = new IntegerArgument(
"port", OPTION_SHORT_PORT,
OPTION_LONG_PORT, false, false, true,
INFO_PORT_PLACEHOLDER.get(),
AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT,
null, true, 1,
true, 65535, INFO_PWPSTATE_DESCRIPTION_PORT.get());
argParser.addGlobalArgument(port);
bindDN = new StringArgument("binddn", OPTION_SHORT_BINDDN,
OPTION_LONG_BINDDN, false, false, true,
INFO_BINDDN_PLACEHOLDER.get(), null, null,
INFO_PWPSTATE_DESCRIPTION_BINDDN.get());
argParser.addGlobalArgument(bindDN);
bindPW = new StringArgument("bindpw", OPTION_SHORT_BINDPWD,
OPTION_LONG_BINDPWD, false, false,
true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_PWPSTATE_DESCRIPTION_BINDPW.get());
argParser.addGlobalArgument(bindPW);
bindPWFile = new FileBasedArgument(
"bindpwfile",
OPTION_SHORT_BINDPWD_FILE,
OPTION_LONG_BINDPWD_FILE,
false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(),
null, null,
INFO_PWPSTATE_DESCRIPTION_BINDPWFILE.get());
argParser.addGlobalArgument(bindPWFile);
targetDN = new StringArgument("targetdn", 'b', "targetDN", true, false,
true, INFO_TARGETDN_PLACEHOLDER.get(), null,
null,
INFO_PWPSTATE_DESCRIPTION_TARGETDN.get());
argParser.addGlobalArgument(targetDN);
saslOption = new StringArgument(
"sasloption", OPTION_SHORT_SASLOPTION,
OPTION_LONG_SASLOPTION, false,
true, true,
INFO_SASL_OPTION_PLACEHOLDER.get(), null, null,
INFO_PWPSTATE_DESCRIPTION_SASLOPTIONS.get());
argParser.addGlobalArgument(saslOption);
trustAll = new BooleanArgument("trustall", 'X', "trustAll",
INFO_PWPSTATE_DESCRIPTION_TRUST_ALL.get());
argParser.addGlobalArgument(trustAll);
keyStoreFile = new StringArgument("keystorefile",
OPTION_SHORT_KEYSTOREPATH,
OPTION_LONG_KEYSTOREPATH,
false, false, true,
INFO_KEYSTOREPATH_PLACEHOLDER.get(),
null, null,
INFO_PWPSTATE_DESCRIPTION_KSFILE.get());
argParser.addGlobalArgument(keyStoreFile);
keyStorePW = new StringArgument("keystorepw", OPTION_SHORT_KEYSTORE_PWD,
OPTION_LONG_KEYSTORE_PWD,
false, false, true,
INFO_KEYSTORE_PWD_PLACEHOLDER.get(),
null, null,
INFO_PWPSTATE_DESCRIPTION_KSPW.get());
argParser.addGlobalArgument(keyStorePW);
keyStorePWFile = new FileBasedArgument("keystorepwfile",
OPTION_SHORT_KEYSTORE_PWD_FILE,
OPTION_LONG_KEYSTORE_PWD_FILE, false, false,
INFO_KEYSTORE_PWD_FILE_PLACEHOLDER.get(), null,
null,
INFO_PWPSTATE_DESCRIPTION_KSPWFILE.get());
argParser.addGlobalArgument(keyStorePWFile);
certNickname = new StringArgument(
"certnickname", 'N', "certNickname",
false, false, true, INFO_NICKNAME_PLACEHOLDER.get(), null,
null, INFO_DESCRIPTION_CERT_NICKNAME.get());
argParser.addGlobalArgument(certNickname);
trustStoreFile = new StringArgument(
"truststorefile",
OPTION_SHORT_TRUSTSTOREPATH,
OPTION_LONG_TRUSTSTOREPATH,
false, false, true,
INFO_TRUSTSTOREPATH_PLACEHOLDER.get(),
null, null,
INFO_PWPSTATE_DESCRIPTION_TSFILE.get());
argParser.addGlobalArgument(trustStoreFile);
trustStorePW = new StringArgument(
"truststorepw", 'T',
OPTION_LONG_TRUSTSTORE_PWD,
false, false,
true, INFO_TRUSTSTORE_PWD_PLACEHOLDER.get(), null,
null, INFO_PWPSTATE_DESCRIPTION_TSPW.get());
argParser.addGlobalArgument(trustStorePW);
trustStorePWFile = new FileBasedArgument("truststorepwfile",
OPTION_SHORT_TRUSTSTORE_PWD_FILE,
OPTION_LONG_TRUSTSTORE_PWD_FILE,
false, false,
INFO_TRUSTSTORE_PWD_FILE_PLACEHOLDER.get(),
null, null,
INFO_PWPSTATE_DESCRIPTION_TSPWFILE.get());
argParser.addGlobalArgument(trustStorePWFile);
showUsage = new BooleanArgument(
"showusage", OPTION_SHORT_HELP,
OPTION_LONG_HELP,
INFO_PWPSTATE_DESCRIPTION_SHOWUSAGE.get());
argParser.addGlobalArgument(showUsage);
argParser.setUsageArgument(showUsage, out);
HashSet<String> booleanValues = new HashSet<String>(2);
booleanValues.add(INFO_MULTICHOICE_TRUE_VALUE.get().toString());
booleanValues.add(INFO_MULTICHOICE_FALSE_VALUE.get().toString());
Message msg = INFO_DESCRIPTION_PWPSTATE_GET_ALL.get();
new SubCommand(argParser, SC_GET_ALL, msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_POLICY_DN.get();
new SubCommand(argParser, SC_GET_PASSWORD_POLICY_DN, msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_ACCOUNT_DISABLED_STATE.get();
new SubCommand(argParser, SC_GET_ACCOUNT_DISABLED_STATE, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_ACCOUNT_DISABLED_STATE.get();
SubCommand sc = new SubCommand(argParser, SC_SET_ACCOUNT_DISABLED_STATE,
msg);
sc.addArgument(new MultiChoiceArgument(ARG_OP_VALUE, 'O',
"operationValue", true, false, true,
INFO_TRUE_FALSE_PLACEHOLDER.get(), null, null,
booleanValues, false,
INFO_DESCRIPTION_OPERATION_BOOLEAN_VALUE.get()));
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_ACCOUNT_DISABLED_STATE.get();
new SubCommand(argParser, SC_CLEAR_ACCOUNT_DISABLED_STATE, msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_ACCOUNT_EXPIRATION_TIME.get();
new SubCommand(argParser, SC_GET_ACCOUNT_EXPIRATION_TIME, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_ACCOUNT_EXPIRATION_TIME.get();
sc = new SubCommand(argParser, SC_SET_ACCOUNT_EXPIRATION_TIME, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, false, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_ACCOUNT_EXPIRATION_TIME.get();
sc = new SubCommand(argParser, SC_CLEAR_ACCOUNT_EXPIRATION_TIME, msg);
sc.setHidden(true);
msg =
INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION
.get();
new SubCommand(argParser,
SC_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_CHANGED_TIME.get();
new SubCommand(argParser, SC_GET_PASSWORD_CHANGED_TIME, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_CHANGED_TIME.get();
sc = new SubCommand(argParser, SC_SET_PASSWORD_CHANGED_TIME, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, false, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_CHANGED_TIME.get();
sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_CHANGED_TIME, msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_EXPIRATION_WARNED_TIME
.get();
new SubCommand(argParser, SC_GET_PASSWORD_EXP_WARNED_TIME, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_EXPIRATION_WARNED_TIME
.get();
sc = new SubCommand(argParser, SC_SET_PASSWORD_EXP_WARNED_TIME, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, false, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_EXPIRATION_WARNED_TIME
.get();
sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_EXP_WARNED_TIME, msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_PASSWORD_EXP.get();
new SubCommand(argParser, SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_PASSWORD_EXP_WARNING
.get();
new SubCommand(argParser,
SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION_WARNING, msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_AUTH_FAILURE_TIMES.get();
new SubCommand(argParser, SC_GET_AUTHENTICATION_FAILURE_TIMES, msg);
msg = INFO_DESCRIPTION_PWPSTATE_ADD_AUTH_FAILURE_TIME.get();
sc = new SubCommand(argParser, SC_ADD_AUTHENTICATION_FAILURE_TIME,
msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, true, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_SET_AUTH_FAILURE_TIMES.get();
sc = new SubCommand(argParser, SC_SET_AUTHENTICATION_FAILURE_TIMES,
msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, true, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUES.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_AUTH_FAILURE_TIMES.get();
sc = new SubCommand(argParser, SC_CLEAR_AUTHENTICATION_FAILURE_TIMES,
msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_AUTH_FAILURE_UNLOCK
.get();
new SubCommand(argParser,
SC_GET_SECONDS_UNTIL_AUTHENTICATION_FAILURE_UNLOCK,
msg);
msg =
INFO_DESCRIPTION_PWPSTATE_GET_REMAINING_AUTH_FAILURE_COUNT.get();
new SubCommand(argParser, SC_GET_REMAINING_AUTHENTICATION_FAILURE_COUNT,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_LAST_LOGIN_TIME.get();
new SubCommand(argParser, SC_GET_LAST_LOGIN_TIME, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_LAST_LOGIN_TIME.get();
sc = new SubCommand(argParser, SC_SET_LAST_LOGIN_TIME, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, false, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_LAST_LOGIN_TIME.get();
sc = new SubCommand(argParser, SC_CLEAR_LAST_LOGIN_TIME, msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_IDLE_LOCKOUT.get();
new SubCommand(argParser, SC_GET_SECONDS_UNTIL_IDLE_LOCKOUT, msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_RESET_STATE.get();
new SubCommand(argParser, SC_GET_PASSWORD_RESET_STATE, msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_RESET_STATE.get();
sc = new SubCommand(argParser, SC_SET_PASSWORD_RESET_STATE, msg);
sc.addArgument(new MultiChoiceArgument(ARG_OP_VALUE, 'O',
"operationValue", true, false, true,
INFO_TRUE_FALSE_PLACEHOLDER.get(), null, null,
booleanValues, false,
INFO_DESCRIPTION_OPERATION_BOOLEAN_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_RESET_STATE.get();
sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_RESET_STATE, msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_RESET_LOCKOUT.get();
new SubCommand(argParser, SC_GET_SECONDS_UNTIL_PASSWORD_RESET_LOCKOUT,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_GRACE_LOGIN_USE_TIMES.get();
new SubCommand(argParser, SC_GET_GRACE_LOGIN_USE_TIMES, msg);
msg = INFO_DESCRIPTION_PWPSTATE_ADD_GRACE_LOGIN_USE_TIME.get();
sc = new SubCommand(argParser, SC_ADD_GRACE_LOGIN_USE_TIME, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, true, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_SET_GRACE_LOGIN_USE_TIMES.get();
sc = new SubCommand(argParser, SC_SET_GRACE_LOGIN_USE_TIMES, msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, true, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUES.get()));
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_GRACE_LOGIN_USE_TIMES.get();
sc = new SubCommand(argParser, SC_CLEAR_GRACE_LOGIN_USE_TIMES, msg);
sc.setHidden(true);
msg = INFO_DESCRIPTION_PWPSTATE_GET_REMAINING_GRACE_LOGIN_COUNT.get();
new SubCommand(argParser, SC_GET_REMAINING_GRACE_LOGIN_COUNT,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PW_CHANGED_BY_REQUIRED_TIME.get();
new SubCommand(argParser, SC_GET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_SET_PW_CHANGED_BY_REQUIRED_TIME.get();
sc = new SubCommand(argParser, SC_SET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
msg);
sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
false, false, true, INFO_TIME_PLACEHOLDER.get(),
null, null,
INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
sc.setHidden(true);
msg =
INFO_DESCRIPTION_PWPSTATE_CLEAR_PW_CHANGED_BY_REQUIRED_TIME.get();
sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_CHANGED_BY_REQUIRED_TIME,
msg);
sc.setHidden(true);
msg =
INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_REQUIRED_CHANGE_TIME
.get();
new SubCommand(argParser, SC_GET_SECONDS_UNTIL_REQUIRED_CHANGE_TIME,
msg);
msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_HISTORY.get();
new SubCommand(argParser, SC_GET_PASSWORD_HISTORY, msg);
msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_HISTORY.get();
sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_HISTORY, msg);
sc.setHidden(true);
}
catch (ArgumentException ae)
{
Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
err.println(wrapText(message, MAX_LINE_WIDTH));
return LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
}
try
{
argParser.parseArguments(args);
}
catch (ArgumentException ae)
{
Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
err.println(wrapText(message, MAX_LINE_WIDTH));
err.println(argParser.getUsage());
return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
}
// If we should just display usage or version information,
// then exit because it will have already been done.
if (argParser.usageOrVersionDisplayed())
{
return -1;
}
// Get the target DN as a string for later use.
targetDNString = targetDN.getValue();
// Create the LDAP connection options object, which will be used to
// customize the way that we connect to the server and specify a set of
// basic defaults.
LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
connectionOptions.setVersionNumber(3);
// If both a bind password and bind password file were provided, then
// return an error.
if (bindPW.isPresent() && bindPWFile.isPresent())
{
Message message = ERR_PWPSTATE_MUTUALLY_EXCLUSIVE_ARGUMENTS.get(
bindPW.getLongIdentifier(),
bindPWFile.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
}
// If both a key store password and key store password file were provided,
// then return an error.
if (keyStorePW.isPresent() && keyStorePWFile.isPresent())
{
Message message = ERR_PWPSTATE_MUTUALLY_EXCLUSIVE_ARGUMENTS.get(
keyStorePW.getLongIdentifier(),
keyStorePWFile.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
}
// If both a trust store password and trust store password file were
// provided, then return an error.
if (trustStorePW.isPresent() && trustStorePWFile.isPresent())
{
Message message = ERR_PWPSTATE_MUTUALLY_EXCLUSIVE_ARGUMENTS.get(
trustStorePW.getLongIdentifier(),
trustStorePWFile.getLongIdentifier());
err.println(wrapText(message, MAX_LINE_WIDTH));
return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
}
// If we should blindly trust any certificate, then install the appropriate
// SSL connection factory.
try {
String clientAlias;
if (certNickname.isPresent()) {
clientAlias = certNickname.getValue();
} else {
clientAlias = null;
}
SSLConnectionFactory sslConnectionFactory = new SSLConnectionFactory();
sslConnectionFactory.init(trustAll.isPresent(), keyStoreFile.getValue(),
keyStorePW.getValue(), clientAlias,
trustStoreFile.getValue(),
trustStorePW.getValue());
connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
} catch (SSLConnectionException sce) {
Message message = ERR_PWPSTATE_CANNOT_INITIALIZE_SSL.get(
sce.getMessage());