use of com.unboundid.util.args.BooleanArgument in project ldapsdk by pingidentity.
the class CommandLineTool method createArgumentParser.
/**
* Creates a parser that can be used to to parse arguments accepted by
* this tool.
*
* @return ArgumentParser that can be used to parse arguments for this
* tool.
*
* @throws ArgumentException If there was a problem initializing the
* parser for this tool.
*/
@NotNull()
public final ArgumentParser createArgumentParser() throws ArgumentException {
final ArgumentParser parser = new ArgumentParser(getToolName(), getToolDescription(), getAdditionalDescriptionParagraphs(), getMinTrailingArguments(), getMaxTrailingArguments(), getTrailingArgumentsPlaceholder());
parser.setCommandLineTool(this);
addToolArguments(parser);
if (supportsInteractiveMode()) {
interactiveArgument = new BooleanArgument(null, "interactive", INFO_CL_TOOL_DESCRIPTION_INTERACTIVE.get());
interactiveArgument.setUsageArgument(true);
parser.addArgument(interactiveArgument);
}
if (supportsOutputFile()) {
outputFileArgument = new FileArgument(null, "outputFile", false, 1, null, INFO_CL_TOOL_DESCRIPTION_OUTPUT_FILE.get(), false, true, true, false);
outputFileArgument.addLongIdentifier("output-file", true);
outputFileArgument.setUsageArgument(true);
parser.addArgument(outputFileArgument);
appendToOutputFileArgument = new BooleanArgument(null, "appendToOutputFile", 1, INFO_CL_TOOL_DESCRIPTION_APPEND_TO_OUTPUT_FILE.get(outputFileArgument.getIdentifierString()));
appendToOutputFileArgument.addLongIdentifier("append-to-output-file", true);
appendToOutputFileArgument.setUsageArgument(true);
parser.addArgument(appendToOutputFileArgument);
teeOutputArgument = new BooleanArgument(null, "teeOutput", 1, INFO_CL_TOOL_DESCRIPTION_TEE_OUTPUT.get(outputFileArgument.getIdentifierString()));
teeOutputArgument.addLongIdentifier("tee-output", true);
teeOutputArgument.setUsageArgument(true);
parser.addArgument(teeOutputArgument);
parser.addDependentArgumentSet(appendToOutputFileArgument, outputFileArgument);
parser.addDependentArgumentSet(teeOutputArgument, outputFileArgument);
}
helpArgument = new BooleanArgument('H', "help", INFO_CL_TOOL_DESCRIPTION_HELP.get());
helpArgument.addShortIdentifier('?', true);
helpArgument.setUsageArgument(true);
parser.addArgument(helpArgument);
if (!parser.getSubCommands().isEmpty()) {
helpSubcommandsArgument = new BooleanArgument(null, "helpSubcommands", 1, INFO_CL_TOOL_DESCRIPTION_HELP_SUBCOMMANDS.get());
helpSubcommandsArgument.addLongIdentifier("helpSubcommand", true);
helpSubcommandsArgument.addLongIdentifier("help-subcommands", true);
helpSubcommandsArgument.addLongIdentifier("help-subcommand", true);
helpSubcommandsArgument.setUsageArgument(true);
parser.addArgument(helpSubcommandsArgument);
}
final String version = getToolVersion();
if ((version != null) && (!version.isEmpty()) && (parser.getNamedArgument("version") == null)) {
final Character shortIdentifier;
if (parser.getNamedArgument('V') == null) {
shortIdentifier = 'V';
} else {
shortIdentifier = null;
}
versionArgument = new BooleanArgument(shortIdentifier, "version", INFO_CL_TOOL_DESCRIPTION_VERSION.get());
versionArgument.setUsageArgument(true);
parser.addArgument(versionArgument);
}
if (supportsPropertiesFile()) {
parser.enablePropertiesFileSupport();
}
return parser;
}
use of com.unboundid.util.args.BooleanArgument in project ldapsdk by pingidentity.
the class MultiServerLDAPCommandLineTool method addToolArguments.
/**
* {@inheritDoc}
*/
@Override()
public final void addToolArguments(@NotNull final ArgumentParser parser) throws ArgumentException {
for (int i = 0; i < numServers; i++) {
final StringBuilder groupNameBuffer = new StringBuilder();
if (serverNamePrefixes != null) {
final String prefix = serverNamePrefixes[i].replace('-', ' ').trim();
groupNameBuffer.append(StaticUtils.capitalize(prefix, true));
}
if (serverNameSuffixes != null) {
if (groupNameBuffer.length() > 0) {
groupNameBuffer.append(' ');
}
final String suffix = serverNameSuffixes[i].replace('-', ' ').trim();
groupNameBuffer.append(StaticUtils.capitalize(suffix, true));
}
groupNameBuffer.append(' ');
groupNameBuffer.append(INFO_MULTI_LDAP_TOOL_GROUP_CONN_AND_AUTH.get());
final String groupName = groupNameBuffer.toString();
host[i] = new StringArgument(null, genArgName(i, "hostname"), true, 1, INFO_LDAP_TOOL_PLACEHOLDER_HOST.get(), INFO_LDAP_TOOL_DESCRIPTION_HOST.get(), "localhost");
if (includeAlternateLongIdentifiers()) {
host[i].addLongIdentifier(genDashedArgName(i, "hostname"), true);
host[i].addLongIdentifier(genArgName(i, "host"), true);
host[i].addLongIdentifier(genDashedArgName(i, "host"), true);
host[i].addLongIdentifier(genArgName(i, "address"), true);
host[i].addLongIdentifier(genDashedArgName(i, "address"), true);
}
host[i].setArgumentGroupName(groupName);
parser.addArgument(host[i]);
port[i] = new IntegerArgument(null, genArgName(i, "port"), true, 1, INFO_LDAP_TOOL_PLACEHOLDER_PORT.get(), INFO_LDAP_TOOL_DESCRIPTION_PORT.get(), 1, 65_535, 389);
port[i].setArgumentGroupName(groupName);
if (includeAlternateLongIdentifiers()) {
port[i].addLongIdentifier(genDashedArgName(i, "port"), true);
}
parser.addArgument(port[i]);
bindDN[i] = new DNArgument(null, genArgName(i, "bindDN"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_DN.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_DN.get());
if (includeAlternateLongIdentifiers()) {
bindDN[i].addLongIdentifier(genDashedArgName(i, "bind-dn"), true);
}
bindDN[i].setArgumentGroupName(groupName);
parser.addArgument(bindDN[i]);
bindPassword[i] = new StringArgument(null, genArgName(i, "bindPassword"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_PW.get());
if (includeAlternateLongIdentifiers()) {
bindPassword[i].addLongIdentifier(genDashedArgName(i, "bind-password"), true);
}
bindPassword[i].setSensitive(true);
bindPassword[i].setArgumentGroupName(groupName);
parser.addArgument(bindPassword[i]);
bindPasswordFile[i] = new FileArgument(null, genArgName(i, "bindPasswordFile"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_PW_FILE.get(), true, true, true, false);
if (includeAlternateLongIdentifiers()) {
bindPasswordFile[i].addLongIdentifier(genDashedArgName(i, "bind-password-file"), true);
}
bindPasswordFile[i].setArgumentGroupName(groupName);
parser.addArgument(bindPasswordFile[i]);
useSSL[i] = new BooleanArgument(null, genArgName(i, "useSSL"), 1, INFO_LDAP_TOOL_DESCRIPTION_USE_SSL.get());
if (includeAlternateLongIdentifiers()) {
useSSL[i].addLongIdentifier(genDashedArgName(i, "use-ssl"), true);
}
useSSL[i].setArgumentGroupName(groupName);
parser.addArgument(useSSL[i]);
useStartTLS[i] = new BooleanArgument(null, genArgName(i, "useStartTLS"), 1, INFO_LDAP_TOOL_DESCRIPTION_USE_START_TLS.get());
if (includeAlternateLongIdentifiers()) {
useStartTLS[i].addLongIdentifier(genDashedArgName(i, "use-start-tls"), true);
}
useStartTLS[i].setArgumentGroupName(groupName);
parser.addArgument(useStartTLS[i]);
final String defaultTrustArgDesc;
if (InternalSDKHelper.getPingIdentityServerRoot() != null) {
defaultTrustArgDesc = INFO_LDAP_TOOL_DESCRIPTION_DEFAULT_TRUST_WITH_PING_DS.get();
} else {
defaultTrustArgDesc = INFO_LDAP_TOOL_DESCRIPTION_DEFAULT_TRUST_WITHOUT_PING_DS.get();
}
defaultTrust[i] = new BooleanArgument(null, genArgName(i, "defaultTrust"), 1, defaultTrustArgDesc);
defaultTrust[i].setArgumentGroupName(groupName);
if (includeAlternateLongIdentifiers()) {
defaultTrust[i].addLongIdentifier(genDashedArgName(i, "default-trust"), true);
defaultTrust[i].addLongIdentifier(genArgName(i, "useDefaultTrust"), true);
defaultTrust[i].addLongIdentifier(genDashedArgName(i, "use-default-trust"), true);
}
parser.addArgument(defaultTrust[i]);
trustAll[i] = new BooleanArgument(null, genArgName(i, "trustAll"), 1, INFO_LDAP_TOOL_DESCRIPTION_TRUST_ALL.get());
if (includeAlternateLongIdentifiers()) {
trustAll[i].addLongIdentifier(genDashedArgName(i, "trust-all"), true);
}
trustAll[i].setArgumentGroupName(groupName);
parser.addArgument(trustAll[i]);
keyStorePath[i] = new StringArgument(null, genArgName(i, "keyStorePath"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PATH.get());
if (includeAlternateLongIdentifiers()) {
keyStorePath[i].addLongIdentifier(genDashedArgName(i, "key-store-path"), true);
}
keyStorePath[i].setArgumentGroupName(groupName);
parser.addArgument(keyStorePath[i]);
keyStorePassword[i] = new StringArgument(null, genArgName(i, "keyStorePassword"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PASSWORD.get());
if (includeAlternateLongIdentifiers()) {
keyStorePassword[i].addLongIdentifier(genDashedArgName(i, "key-store-password"), true);
}
keyStorePassword[i].setSensitive(true);
keyStorePassword[i].setArgumentGroupName(groupName);
parser.addArgument(keyStorePassword[i]);
keyStorePasswordFile[i] = new FileArgument(null, genArgName(i, "keyStorePasswordFile"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PASSWORD_FILE.get(), true, true, true, false);
if (includeAlternateLongIdentifiers()) {
keyStorePasswordFile[i].addLongIdentifier(genDashedArgName(i, "key-store-password-file"), true);
}
keyStorePasswordFile[i].setArgumentGroupName(groupName);
parser.addArgument(keyStorePasswordFile[i]);
keyStoreFormat[i] = new StringArgument(null, genArgName(i, "keyStoreFormat"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_FORMAT.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_FORMAT.get());
if (includeAlternateLongIdentifiers()) {
keyStoreFormat[i].addLongIdentifier(genDashedArgName(i, "key-store-format"), true);
keyStoreFormat[i].addLongIdentifier(genArgName(i, "keyStoreType"), true);
keyStoreFormat[i].addLongIdentifier(genDashedArgName(i, "key-store-type"), true);
}
keyStoreFormat[i].setArgumentGroupName(groupName);
parser.addArgument(keyStoreFormat[i]);
trustStorePath[i] = new StringArgument(null, genArgName(i, "trustStorePath"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PATH.get());
if (includeAlternateLongIdentifiers()) {
trustStorePath[i].addLongIdentifier(genDashedArgName(i, "trust-store-path"), true);
}
trustStorePath[i].setArgumentGroupName(groupName);
parser.addArgument(trustStorePath[i]);
trustStorePassword[i] = new StringArgument(null, genArgName(i, "trustStorePassword"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PASSWORD.get());
if (includeAlternateLongIdentifiers()) {
trustStorePassword[i].addLongIdentifier(genDashedArgName(i, "trust-store-password"), true);
}
trustStorePassword[i].setSensitive(true);
trustStorePassword[i].setArgumentGroupName(groupName);
parser.addArgument(trustStorePassword[i]);
trustStorePasswordFile[i] = new FileArgument(null, genArgName(i, "trustStorePasswordFile"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PASSWORD_FILE.get(), true, true, true, false);
if (includeAlternateLongIdentifiers()) {
trustStorePasswordFile[i].addLongIdentifier(genDashedArgName(i, "trust-store-password-file"), true);
}
trustStorePasswordFile[i].setArgumentGroupName(groupName);
parser.addArgument(trustStorePasswordFile[i]);
trustStoreFormat[i] = new StringArgument(null, genArgName(i, "trustStoreFormat"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_FORMAT.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_FORMAT.get());
if (includeAlternateLongIdentifiers()) {
trustStoreFormat[i].addLongIdentifier(genDashedArgName(i, "trust-store-format"), true);
trustStoreFormat[i].addLongIdentifier(genArgName(i, "trustStoreType"), true);
trustStoreFormat[i].addLongIdentifier(genDashedArgName(i, "trust-store-type"), true);
}
trustStoreFormat[i].setArgumentGroupName(groupName);
parser.addArgument(trustStoreFormat[i]);
certificateNickname[i] = new StringArgument(null, genArgName(i, "certNickname"), false, 1, INFO_LDAP_TOOL_PLACEHOLDER_CERT_NICKNAME.get(), INFO_LDAP_TOOL_DESCRIPTION_CERT_NICKNAME.get());
if (includeAlternateLongIdentifiers()) {
certificateNickname[i].addLongIdentifier(genDashedArgName(i, "cert-nickname"), true);
certificateNickname[i].addLongIdentifier(genArgName(i, "certificateNickname"), true);
certificateNickname[i].addLongIdentifier(genDashedArgName(i, "certificate-nickname"), true);
}
certificateNickname[i].setArgumentGroupName(groupName);
parser.addArgument(certificateNickname[i]);
saslOption[i] = new StringArgument(null, genArgName(i, "saslOption"), false, 0, INFO_LDAP_TOOL_PLACEHOLDER_SASL_OPTION.get(), INFO_LDAP_TOOL_DESCRIPTION_SASL_OPTION.get());
if (includeAlternateLongIdentifiers()) {
saslOption[i].addLongIdentifier(genDashedArgName(i, "sasl-option"), true);
}
saslOption[i].setArgumentGroupName(groupName);
parser.addArgument(saslOption[i]);
parser.addDependentArgumentSet(bindDN[i], bindPassword[i], bindPasswordFile[i]);
parser.addExclusiveArgumentSet(useSSL[i], useStartTLS[i]);
parser.addExclusiveArgumentSet(bindPassword[i], bindPasswordFile[i]);
parser.addExclusiveArgumentSet(keyStorePassword[i], keyStorePasswordFile[i]);
parser.addExclusiveArgumentSet(trustStorePassword[i], trustStorePasswordFile[i]);
parser.addExclusiveArgumentSet(trustAll[i], trustStorePath[i]);
parser.addExclusiveArgumentSet(trustAll[i], defaultTrust[i]);
}
addNonLDAPArguments(parser);
}
use of com.unboundid.util.args.BooleanArgument in project ldapsdk by pingidentity.
the class TestLDAPCommandLineTool method addNonLDAPArguments.
/**
* {@inheritDoc}
*/
@Override()
public void addNonLDAPArguments(final ArgumentParser parser) throws ArgumentException {
final ArgumentParser argListParser1 = new ArgumentParser("argumentList1", "Argument List 1 Description");
argListParser1.addArgument(new StringArgument(null, "foo", false, -1, "{foo}", "Foo Description"));
final ArgumentParser argListParser2 = new ArgumentParser("argumentList2", "Argument List 2 Description");
argListParser2.addArgument(new StringArgument(null, "bar", false, -1, "{bar}", "Bar Description"));
singleValuedArgumentListArgument = new ArgumentListArgument(null, "singleValuedArgumentList", false, 1, "{argList}", "Argument List", argListParser1);
parser.addArgument(singleValuedArgumentListArgument);
multiValuedArgumentListArgument = new ArgumentListArgument(null, "multiValuedArgumentList", false, -1, "{argList}", "Argument List", argListParser2);
parser.addArgument(multiValuedArgumentListArgument);
booleanArgument = new BooleanArgument(null, "boolean", "Boolean Description");
parser.addArgument(booleanArgument);
booleanValueArgument = new BooleanValueArgument(null, "booleanValue", false, "{true|false}", "Boolean Value Description");
parser.addArgument(booleanValueArgument);
singleValuedControlArgument = new ControlArgument(null, "singleValuedControl", false, 1, null, "Control Description");
parser.addArgument(singleValuedControlArgument);
multiValuedControlArgument = new ControlArgument(null, "multiValuedControl", false, -1, null, "Control Description");
parser.addArgument(multiValuedControlArgument);
singleValuedDNArgument = new DNArgument(null, "singleValuedDN", false, 1, "{dn}", "DN Description");
parser.addArgument(singleValuedDNArgument);
multiValuedDNArgument = new DNArgument(null, "multiValuedDN", false, -1, "{dn}", "DN Description");
parser.addArgument(multiValuedDNArgument);
durationArgument = new DurationArgument(null, "duration", false, "{duration}", "Duration Description");
parser.addArgument(durationArgument);
singleValuedFileArgument = new FileArgument(null, "singleValuedFile", false, 1, "{path}", "File Description", false, true, true, false);
parser.addArgument(singleValuedFileArgument);
multiValuedFileArgument = new FileArgument(null, "multiValuedFile", false, -1, "{path}", "File Description", false, false, false, false);
parser.addArgument(multiValuedFileArgument);
singleValuedFilterArgument = new FilterArgument(null, "singleValuedFilter", false, 1, "{filter}", "Filter Description");
parser.addArgument(singleValuedFilterArgument);
multiValuedFilterArgument = new FilterArgument(null, "multiValuedFilter", false, -1, "{filter}", "Filter Description");
parser.addArgument(multiValuedFilterArgument);
singleValuedTimestampArgument = new TimestampArgument(null, "singleValuedGeneralizedTime", false, 1, "{timestamp}", "Generalized Time Description");
parser.addArgument(singleValuedTimestampArgument);
multiValuedTimestampArgument = new TimestampArgument(null, "multiValuedGeneralizedTime", false, -1, "{timestamp}", "Generalized Time Description");
parser.addArgument(multiValuedTimestampArgument);
singleValuedIntegerArgument = new IntegerArgument(null, "singleValuedInteger", false, 1, "{int}", "Integer Description");
parser.addArgument(singleValuedIntegerArgument);
multiValuedIntegerArgument = new IntegerArgument(null, "multiValuedInteger", false, -1, "{int}", "Integer Description");
parser.addArgument(multiValuedIntegerArgument);
scopeArgument = new ScopeArgument(null, "scope", false, "{scope}", "Scope Description");
parser.addArgument(scopeArgument);
singleValuedStringArgument = new StringArgument(null, "singleValuedString", false, 1, "{string}", "String Description");
parser.addArgument(singleValuedStringArgument);
multiValuedOpenOptionsStringArgument = new StringArgument(null, "multiValuedOpenOptionsString", false, -1, "{string}", "String Description");
parser.addArgument(multiValuedOpenOptionsStringArgument);
final LinkedHashSet<String> allowedValues = new LinkedHashSet<String>(5);
allowedValues.add("first");
allowedValues.add("second");
allowedValues.add("third");
allowedValues.add("fourth");
allowedValues.add("fifth");
multiValuedFixedOptionsStringArgument = new StringArgument(null, "multiValuedFixedOptionsString", false, -1, "{string}", "String Description", allowedValues);
parser.addArgument(multiValuedFixedOptionsStringArgument);
resultCodeArgument = new IntegerArgument(null, "resultCode", true, 1, "{intValue}", "The result code");
parser.addArgument(resultCodeArgument);
}
use of com.unboundid.util.args.BooleanArgument in project ldapsdk by pingidentity.
the class LDAPCommandLineTool method addToolArguments.
/**
* {@inheritDoc}
*/
@Override()
public final void addToolArguments(@NotNull final ArgumentParser parser) throws ArgumentException {
final String argumentGroup;
final boolean supportsAuthentication = supportsAuthentication();
if (supportsAuthentication) {
argumentGroup = INFO_LDAP_TOOL_ARG_GROUP_CONNECT_AND_AUTH.get();
} else {
argumentGroup = INFO_LDAP_TOOL_ARG_GROUP_CONNECT.get();
}
host = new StringArgument(getShortIdentifierIfNotSuppressed('h'), "hostname", true, (supportsMultipleServers() ? 0 : 1), INFO_LDAP_TOOL_PLACEHOLDER_HOST.get(), INFO_LDAP_TOOL_DESCRIPTION_HOST.get(), "localhost");
if (includeAlternateLongIdentifiers()) {
host.addLongIdentifier("host", true);
host.addLongIdentifier("address", true);
}
host.setArgumentGroupName(argumentGroup);
parser.addArgument(host);
port = new IntegerArgument(getShortIdentifierIfNotSuppressed('p'), "port", true, (supportsMultipleServers() ? 0 : 1), INFO_LDAP_TOOL_PLACEHOLDER_PORT.get(), INFO_LDAP_TOOL_DESCRIPTION_PORT.get(), 1, 65_535, 389);
port.setArgumentGroupName(argumentGroup);
parser.addArgument(port);
if (supportsAuthentication) {
bindDN = new DNArgument(getShortIdentifierIfNotSuppressed('D'), "bindDN", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_DN.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_DN.get());
bindDN.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
bindDN.addLongIdentifier("bind-dn", true);
}
parser.addArgument(bindDN);
bindPassword = new StringArgument(getShortIdentifierIfNotSuppressed('w'), "bindPassword", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_PW.get());
bindPassword.setSensitive(true);
bindPassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
bindPassword.addLongIdentifier("bind-password", true);
}
parser.addArgument(bindPassword);
bindPasswordFile = new FileArgument(getShortIdentifierIfNotSuppressed('j'), "bindPasswordFile", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_BIND_PW_FILE.get(), true, true, true, false);
bindPasswordFile.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
bindPasswordFile.addLongIdentifier("bind-password-file", true);
}
parser.addArgument(bindPasswordFile);
promptForBindPassword = new BooleanArgument(null, "promptForBindPassword", 1, INFO_LDAP_TOOL_DESCRIPTION_BIND_PW_PROMPT.get());
promptForBindPassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
promptForBindPassword.addLongIdentifier("prompt-for-bind-password", true);
}
parser.addArgument(promptForBindPassword);
}
useSSL = new BooleanArgument(getShortIdentifierIfNotSuppressed('Z'), "useSSL", 1, INFO_LDAP_TOOL_DESCRIPTION_USE_SSL.get());
useSSL.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
useSSL.addLongIdentifier("use-ssl", true);
}
parser.addArgument(useSSL);
useStartTLS = new BooleanArgument(getShortIdentifierIfNotSuppressed('q'), "useStartTLS", 1, INFO_LDAP_TOOL_DESCRIPTION_USE_START_TLS.get());
useStartTLS.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
useStartTLS.addLongIdentifier("use-starttls", true);
useStartTLS.addLongIdentifier("use-start-tls", true);
}
parser.addArgument(useStartTLS);
final String defaultTrustArgDesc;
if (InternalSDKHelper.getPingIdentityServerRoot() != null) {
defaultTrustArgDesc = INFO_LDAP_TOOL_DESCRIPTION_DEFAULT_TRUST_WITH_PING_DS.get();
} else {
defaultTrustArgDesc = INFO_LDAP_TOOL_DESCRIPTION_DEFAULT_TRUST_WITHOUT_PING_DS.get();
}
defaultTrust = new BooleanArgument(null, "defaultTrust", 1, defaultTrustArgDesc);
defaultTrust.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
defaultTrust.addLongIdentifier("default-trust", true);
defaultTrust.addLongIdentifier("useDefaultTrust", true);
defaultTrust.addLongIdentifier("use-default-trust", true);
}
parser.addArgument(defaultTrust);
trustAll = new BooleanArgument(getShortIdentifierIfNotSuppressed('X'), "trustAll", 1, INFO_LDAP_TOOL_DESCRIPTION_TRUST_ALL.get());
trustAll.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
trustAll.addLongIdentifier("trustAllCertificates", true);
trustAll.addLongIdentifier("trust-all", true);
trustAll.addLongIdentifier("trust-all-certificates", true);
}
parser.addArgument(trustAll);
keyStorePath = new StringArgument(getShortIdentifierIfNotSuppressed('K'), "keyStorePath", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PATH.get());
keyStorePath.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
keyStorePath.addLongIdentifier("key-store-path", true);
}
parser.addArgument(keyStorePath);
keyStorePassword = new StringArgument(getShortIdentifierIfNotSuppressed('W'), "keyStorePassword", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PASSWORD.get());
keyStorePassword.setSensitive(true);
keyStorePassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
keyStorePassword.addLongIdentifier("keyStorePIN", true);
keyStorePassword.addLongIdentifier("key-store-password", true);
keyStorePassword.addLongIdentifier("key-store-pin", true);
}
parser.addArgument(keyStorePassword);
keyStorePasswordFile = new FileArgument(getShortIdentifierIfNotSuppressed('u'), "keyStorePasswordFile", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PASSWORD_FILE.get());
keyStorePasswordFile.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
keyStorePasswordFile.addLongIdentifier("keyStorePINFile", true);
keyStorePasswordFile.addLongIdentifier("key-store-password-file", true);
keyStorePasswordFile.addLongIdentifier("key-store-pin-file", true);
}
parser.addArgument(keyStorePasswordFile);
promptForKeyStorePassword = new BooleanArgument(null, "promptForKeyStorePassword", 1, INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_PASSWORD_PROMPT.get());
promptForKeyStorePassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
promptForKeyStorePassword.addLongIdentifier("promptForKeyStorePIN", true);
promptForKeyStorePassword.addLongIdentifier("prompt-for-key-store-password", true);
promptForKeyStorePassword.addLongIdentifier("prompt-for-key-store-pin", true);
}
parser.addArgument(promptForKeyStorePassword);
keyStoreFormat = new StringArgument(null, "keyStoreFormat", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_FORMAT.get(), INFO_LDAP_TOOL_DESCRIPTION_KEY_STORE_FORMAT.get());
keyStoreFormat.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
keyStoreFormat.addLongIdentifier("keyStoreType", true);
keyStoreFormat.addLongIdentifier("key-store-format", true);
keyStoreFormat.addLongIdentifier("key-store-type", true);
}
parser.addArgument(keyStoreFormat);
trustStorePath = new StringArgument(getShortIdentifierIfNotSuppressed('P'), "trustStorePath", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PATH.get());
trustStorePath.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
trustStorePath.addLongIdentifier("trust-store-path", true);
}
parser.addArgument(trustStorePath);
trustStorePassword = new StringArgument(getShortIdentifierIfNotSuppressed('T'), "trustStorePassword", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PASSWORD.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PASSWORD.get());
trustStorePassword.setSensitive(true);
trustStorePassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
trustStorePassword.addLongIdentifier("trustStorePIN", true);
trustStorePassword.addLongIdentifier("trust-store-password", true);
trustStorePassword.addLongIdentifier("trust-store-pin", true);
}
parser.addArgument(trustStorePassword);
trustStorePasswordFile = new FileArgument(getShortIdentifierIfNotSuppressed('U'), "trustStorePasswordFile", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_PATH.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PASSWORD_FILE.get());
trustStorePasswordFile.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
trustStorePasswordFile.addLongIdentifier("trustStorePINFile", true);
trustStorePasswordFile.addLongIdentifier("trust-store-password-file", true);
trustStorePasswordFile.addLongIdentifier("trust-store-pin-file", true);
}
parser.addArgument(trustStorePasswordFile);
promptForTrustStorePassword = new BooleanArgument(null, "promptForTrustStorePassword", 1, INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_PASSWORD_PROMPT.get());
promptForTrustStorePassword.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
promptForTrustStorePassword.addLongIdentifier("promptForTrustStorePIN", true);
promptForTrustStorePassword.addLongIdentifier("prompt-for-trust-store-password", true);
promptForTrustStorePassword.addLongIdentifier("prompt-for-trust-store-pin", true);
}
parser.addArgument(promptForTrustStorePassword);
trustStoreFormat = new StringArgument(null, "trustStoreFormat", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_FORMAT.get(), INFO_LDAP_TOOL_DESCRIPTION_TRUST_STORE_FORMAT.get());
trustStoreFormat.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
trustStoreFormat.addLongIdentifier("trustStoreType", true);
trustStoreFormat.addLongIdentifier("trust-store-format", true);
trustStoreFormat.addLongIdentifier("trust-store-type", true);
}
parser.addArgument(trustStoreFormat);
certificateNickname = new StringArgument(getShortIdentifierIfNotSuppressed('N'), "certNickname", false, 1, INFO_LDAP_TOOL_PLACEHOLDER_CERT_NICKNAME.get(), INFO_LDAP_TOOL_DESCRIPTION_CERT_NICKNAME.get());
certificateNickname.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
certificateNickname.addLongIdentifier("certificateNickname", true);
certificateNickname.addLongIdentifier("cert-nickname", true);
certificateNickname.addLongIdentifier("certificate-nickname", true);
}
parser.addArgument(certificateNickname);
if (supportsSSLDebugging()) {
enableSSLDebugging = new BooleanArgument(null, "enableSSLDebugging", 1, INFO_LDAP_TOOL_DESCRIPTION_ENABLE_SSL_DEBUGGING.get());
enableSSLDebugging.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
enableSSLDebugging.addLongIdentifier("enableTLSDebugging", true);
enableSSLDebugging.addLongIdentifier("enableStartTLSDebugging", true);
enableSSLDebugging.addLongIdentifier("enable-ssl-debugging", true);
enableSSLDebugging.addLongIdentifier("enable-tls-debugging", true);
enableSSLDebugging.addLongIdentifier("enable-starttls-debugging", true);
enableSSLDebugging.addLongIdentifier("enable-start-tls-debugging", true);
}
parser.addArgument(enableSSLDebugging);
addEnableSSLDebuggingArgument(enableSSLDebugging);
}
if (supportsAuthentication) {
saslOption = new StringArgument(getShortIdentifierIfNotSuppressed('o'), "saslOption", false, 0, INFO_LDAP_TOOL_PLACEHOLDER_SASL_OPTION.get(), INFO_LDAP_TOOL_DESCRIPTION_SASL_OPTION.get());
saslOption.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
saslOption.addLongIdentifier("sasl-option", true);
}
parser.addArgument(saslOption);
useSASLExternal = new BooleanArgument(null, "useSASLExternal", 1, INFO_LDAP_TOOL_DESCRIPTION_USE_SASL_EXTERNAL.get());
useSASLExternal.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
useSASLExternal.addLongIdentifier("use-sasl-external", true);
}
parser.addArgument(useSASLExternal);
if (supportsSASLHelp()) {
helpSASL = new BooleanArgument(null, "helpSASL", INFO_LDAP_TOOL_DESCRIPTION_HELP_SASL.get());
helpSASL.setArgumentGroupName(argumentGroup);
if (includeAlternateLongIdentifiers()) {
helpSASL.addLongIdentifier("help-sasl", true);
}
helpSASL.setUsageArgument(true);
parser.addArgument(helpSASL);
setHelpSASLArgument(helpSASL);
}
}
// Both useSSL and useStartTLS cannot be used together.
parser.addExclusiveArgumentSet(useSSL, useStartTLS);
// Only one option may be used for specifying the key store password.
parser.addExclusiveArgumentSet(keyStorePassword, keyStorePasswordFile, promptForKeyStorePassword);
// Only one option may be used for specifying the trust store password.
parser.addExclusiveArgumentSet(trustStorePassword, trustStorePasswordFile, promptForTrustStorePassword);
// The defaultTrust argument cannot be used in conjunction with the
// trustAll argument.
parser.addExclusiveArgumentSet(defaultTrust, trustAll);
// It doesn't make sense to provide a trust store path if any server
// certificate should be trusted.
parser.addExclusiveArgumentSet(trustAll, trustStorePath);
// If a key store password is provided, then a key store path must have also
// been provided.
parser.addDependentArgumentSet(keyStorePassword, keyStorePath);
parser.addDependentArgumentSet(keyStorePasswordFile, keyStorePath);
parser.addDependentArgumentSet(promptForKeyStorePassword, keyStorePath);
// If a trust store password is provided, then a trust store path must have
// also been provided.
parser.addDependentArgumentSet(trustStorePassword, trustStorePath);
parser.addDependentArgumentSet(trustStorePasswordFile, trustStorePath);
parser.addDependentArgumentSet(promptForTrustStorePassword, trustStorePath);
// If a key or trust store path is provided, then the tool must either use
// SSL or StartTLS.
parser.addDependentArgumentSet(keyStorePath, useSSL, useStartTLS);
parser.addDependentArgumentSet(trustStorePath, useSSL, useStartTLS);
// If the default trust argument was used, then the tool must either use
// SSL or StartTLS.
parser.addDependentArgumentSet(defaultTrust, useSSL, useStartTLS);
// If the tool should trust all server certificates, then the tool must
// either use SSL or StartTLS.
parser.addDependentArgumentSet(trustAll, useSSL, useStartTLS);
if (supportsAuthentication) {
// provided unless defaultToPromptForBindPassword returns true.
if (!defaultToPromptForBindPassword()) {
parser.addDependentArgumentSet(bindDN, bindPassword, bindPasswordFile, promptForBindPassword);
}
// The bindDN, saslOption, and useSASLExternal arguments are all mutually
// exclusive.
parser.addExclusiveArgumentSet(bindDN, saslOption, useSASLExternal);
// Only one option may be used for specifying the bind password.
parser.addExclusiveArgumentSet(bindPassword, bindPasswordFile, promptForBindPassword);
// If a bind password was provided, then the a bind DN or SASL option
// must have also been provided.
parser.addDependentArgumentSet(bindPassword, bindDN, saslOption);
parser.addDependentArgumentSet(bindPasswordFile, bindDN, saslOption);
parser.addDependentArgumentSet(promptForBindPassword, bindDN, saslOption);
}
addNonLDAPArguments(parser);
}
use of com.unboundid.util.args.BooleanArgument in project ldapsdk by pingidentity.
the class ManageCertificates method doChangeCertificateAlias.
/**
* Performs the necessary processing for the change-certificate-alias
* subcommand.
*
* @return A result code that indicates whether the processing completed
* successfully.
*/
@NotNull()
private ResultCode doChangeCertificateAlias() {
// Get the values of a number of configured arguments.
final StringArgument currentAliasArgument = subCommandParser.getStringArgument("current-alias");
final String currentAlias = currentAliasArgument.getValue();
final StringArgument newAliasArgument = subCommandParser.getStringArgument("new-alias");
final String newAlias = newAliasArgument.getValue();
final String keystoreType;
final File keystorePath = getKeystorePath();
try {
keystoreType = inferKeystoreType(keystorePath);
} catch (final LDAPException le) {
Debug.debugException(le);
wrapErr(0, WRAP_COLUMN, le.getMessage());
return le.getResultCode();
}
final char[] keystorePassword;
try {
keystorePassword = getKeystorePassword(keystorePath);
} catch (final LDAPException le) {
Debug.debugException(le);
wrapErr(0, WRAP_COLUMN, le.getMessage());
return le.getResultCode();
}
// Get the keystore.
final KeyStore keystore;
try {
keystore = getKeystore(keystoreType, keystorePath, keystorePassword);
} catch (final LDAPException le) {
Debug.debugException(le);
wrapErr(0, WRAP_COLUMN, le.getMessage());
return le.getResultCode();
}
// See if we need to use a private key password that is different from the
// keystore password.
final char[] privateKeyPassword;
try {
privateKeyPassword = getPrivateKeyPassword(keystore, currentAlias, keystorePassword);
} catch (final LDAPException le) {
Debug.debugException(le);
wrapErr(0, WRAP_COLUMN, le.getMessage());
return le.getResultCode();
}
// Make sure that the keystore has an existing entry with the current alias.
// It must be either a certificate entry or a private key entry.
final Certificate existingCertificate;
final Certificate[] existingCertificateChain;
final PrivateKey existingPrivateKey;
try {
if (hasCertificateAlias(keystore, currentAlias)) {
existingCertificate = keystore.getCertificate(currentAlias);
existingCertificateChain = null;
existingPrivateKey = null;
} else if (hasKeyAlias(keystore, currentAlias)) {
existingCertificateChain = keystore.getCertificateChain(currentAlias);
existingPrivateKey = (PrivateKey) keystore.getKey(currentAlias, privateKeyPassword);
existingCertificate = null;
} else {
wrapErr(0, WRAP_COLUMN, ERR_MANAGE_CERTS_CHANGE_ALIAS_NO_SUCH_ALIAS.get(currentAlias));
return ResultCode.PARAM_ERROR;
}
} catch (final Exception e) {
Debug.debugException(e);
wrapErr(0, WRAP_COLUMN, ERR_MANAGE_CERTS_CHANGE_ALIAS_CANNOT_GET_EXISTING_ENTRY.get(currentAlias));
e.printStackTrace(getErr());
return ResultCode.LOCAL_ERROR;
}
// Make sure that the keystore does not have an entry with the new alias.
if (hasCertificateAlias(keystore, newAlias) || hasKeyAlias(keystore, newAlias)) {
wrapErr(0, WRAP_COLUMN, ERR_MANAGE_CERTS_CHANGE_ALIAS_NEW_ALIAS_IN_USE.get(newAlias));
return ResultCode.PARAM_ERROR;
}
// Generate the keytool arguments to use to change the certificate alias.
final BooleanArgument displayKeytoolCommandArgument = subCommandParser.getBooleanArgument("display-keytool-command");
if ((displayKeytoolCommandArgument != null) && displayKeytoolCommandArgument.isPresent()) {
final ArrayList<String> keytoolArguments = new ArrayList<>(30);
keytoolArguments.add("-changealias");
keytoolArguments.add("-keystore");
keytoolArguments.add(keystorePath.getAbsolutePath());
keytoolArguments.add("-storetype");
keytoolArguments.add(keystoreType);
keytoolArguments.add("-storepass");
keytoolArguments.add("*****REDACTED*****");
keytoolArguments.add("-keypass");
keytoolArguments.add("*****REDACTED*****");
keytoolArguments.add("-alias");
keytoolArguments.add(currentAlias);
keytoolArguments.add("-destalias");
keytoolArguments.add(newAlias);
displayKeytoolCommand(keytoolArguments);
}
// re-write it with the new alias.
try {
keystore.deleteEntry(currentAlias);
if (existingCertificate != null) {
keystore.setCertificateEntry(newAlias, existingCertificate);
} else {
keystore.setKeyEntry(newAlias, existingPrivateKey, privateKeyPassword, existingCertificateChain);
}
writeKeystore(keystore, keystorePath, keystorePassword);
} catch (final Exception e) {
Debug.debugException(e);
wrapErr(0, WRAP_COLUMN, ERR_MANAGE_CERTS_CHANGE_ALIAS_CANNOT_UPDATE_KEYSTORE.get());
e.printStackTrace(getErr());
return ResultCode.LOCAL_ERROR;
}
wrapOut(0, WRAP_COLUMN, INFO_MANAGE_CERTS_CHANGE_ALIAS_SUCCESSFUL.get(currentAlias, newAlias));
return ResultCode.SUCCESS;
}
Aggregations