From 5d0ceeba98f7bfd2cf17a1f2970e4c8be3130388 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Sun, 26 Aug 2007 17:43:55 +0000
Subject: [PATCH] Fix for issues 2104 and 2162.
---
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java | 14
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java | 149 +++--
opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromFile.java | 83 +++
opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java | 80 ---
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java | 452 +++++++++++++++---
opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java | 25
opends/src/messages/messages/quicksetup.properties | 4
opends/src/messages/messages/tools.properties | 10
opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java | 171 ++----
opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliParser.java | 25
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java | 126 +++++
opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java | 141 ++++-
opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java | 22
opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java | 20
opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliParser.java | 2
opends/src/messages/messages/admin_tool.properties | 22
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java | 8
opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliReturnCode.java | 2
opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java | 13
opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java | 27
20 files changed, 936 insertions(+), 460 deletions(-)
diff --git a/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java b/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
index 57dd0e7..f6cc9eb 100644
--- a/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
+++ b/opends/src/ads/org/opends/admin/ads/util/ConnectionUtils.java
@@ -703,6 +703,28 @@
}
/**
+ * Returns the LDAP URL for the provided parameters.
+ * @param host the host name.
+ * @param port the LDAP port.
+ * @param useSSL whether to use SSL or not.
+ * @return the LDAP URL for the provided parameters.
+ */
+ public static String getLDAPUrl(String host, int port, boolean useSSL)
+ {
+ String ldapUrl;
+ host = getHostNameForLdapUrl(host);
+ if (useSSL)
+ {
+ ldapUrl = "ldaps://"+host+":"+port;
+ }
+ else
+ {
+ ldapUrl = "ldap://"+host+":"+port;
+ }
+ return ldapUrl;
+ }
+
+ /**
* Tells whether the provided Throwable was caused because of a problem with
* a certificate while trying to establish a connection.
* @param t the Throwable to analyze.
diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index d9ed908..2999b50 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -34,6 +34,8 @@
import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
import static org.opends.server.util.StaticUtils.wrapText;
+import java.io.File;
+import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -49,7 +51,6 @@
import java.util.logging.Logger;
import javax.naming.NamingException;
-import javax.naming.NoPermissionException;
import javax.naming.ldap.InitialLdapContext;
import org.opends.admin.ads.ADSContext;
@@ -67,6 +68,7 @@
import org.opends.quicksetup.ApplicationException;
import org.opends.quicksetup.CliApplicationHelper;
import org.opends.quicksetup.Constants;
+import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.event.ProgressUpdateEvent;
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.installer.InstallerHelper;
@@ -98,15 +100,15 @@
*/
private static final String CLASS_NAME = ReplicationCliMain.class.getName();
+ /** Prefix for log files. */
+ static public final String LOG_FILE_PREFIX = "opends-replication-";
+
+ /** Suffix for log files. */
+ static public final String LOG_FILE_SUFFIX = ".log";
+
private static final Logger LOG =
Logger.getLogger(CliApplicationHelper.class.getName());
- // The print stream to use for standard error.
- private PrintStream err;
-
- // The print stream to use for standard output.
- private PrintStream out;
-
// The argument parser to be used.
private ReplicationCliParser argParser;
@@ -117,13 +119,13 @@
/**
* Constructor for the ReplicationCliMain object.
*
- * @param out the print stream to use for standard output.
- * @param err the print stream to use for standard error.
+ * @param out the print stream to use for standard output.
+ * @param err the print stream to use for standard error.
+ * @param in the input stream to use for standard input.
*/
- public ReplicationCliMain(PrintStream out, PrintStream err)
+ public ReplicationCliMain(PrintStream out, PrintStream err, InputStream in)
{
- this.out = out;
- this.err = err;
+ super(out, err, in);
}
/**
@@ -134,7 +136,7 @@
public static void main(String[] args)
{
- int retCode = mainCLI(args, true, System.out, System.err);
+ int retCode = mainCLI(args, true, System.out, System.err, System.in);
if(retCode != 0)
{
@@ -153,7 +155,7 @@
public static int mainCLI(String[] args)
{
- return mainCLI(args, true, System.out, System.err);
+ return mainCLI(args, true, System.out, System.err, System.in);
}
/**
@@ -169,11 +171,12 @@
* @param errStream The output stream to use for standard error, or
* <CODE>null</CODE> if standard error is not
* needed.
+ * @param inStream The input stream to use for standard input.
* @return The error code.
*/
public static int mainCLI(String[] args, boolean initializeServer,
- OutputStream outStream, OutputStream errStream)
+ OutputStream outStream, OutputStream errStream, InputStream inStream)
{
PrintStream out;
if (outStream == null)
@@ -195,7 +198,18 @@
err = new PrintStream(errStream);
}
- ReplicationCliMain replicationCli = new ReplicationCliMain(out, err);
+ try {
+ QuickSetupLog.initLogFileHandler(
+ File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX),
+ "org.opends.guitools.replicationcli");
+ QuickSetupLog.disableConsoleLogging();
+ } catch (Throwable t) {
+ System.err.println("Unable to initialize log");
+ t.printStackTrace();
+ }
+
+ ReplicationCliMain replicationCli = new ReplicationCliMain(out, err,
+ inStream);
return replicationCli.execute(args, initializeServer);
}
@@ -487,7 +501,7 @@
LOG.log(Level.WARNING, "Error connecting to "+host1+":"+port1, ne);
if (Utils.isCertificateException(ne))
{
- String usedUrl = getLDAPUrl(host1, port1, useSSL1);
+ String usedUrl = ConnectionUtils.getLDAPUrl(host1, port1, useSSL1);
if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
{
cancelled = true;
@@ -499,7 +513,7 @@
{
printLineBreak();
printErrorMessage(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- host1+":"+port1));
+ host1+":"+port1, ne.getMessage()));
}
printLineBreak();
if (!firstTimeAsked || (argParser.getHostName1() == null))
@@ -516,20 +530,20 @@
if (!firstTimeAsked || (argParser.getBindDn1() == null))
{
bindDn1 = promptForString(
- INFO_REPLICATION_BINDDN_PROMPT.get(),
+ INFO_CLI_BINDDN_PROMPT.get(),
getValue(bindDn1, argParser.getDefaultBindDn1()));
}
if (!firstTimeAsked || (argParser.getBindPassword1() == null))
{
- pwd1 = promptForPassword(INFO_REPLICATION_PASSWORD_PROMPT.get());
+ pwd1 = promptForPassword(
+ INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn1));
}
if (!firstTimeAsked || (!useSSL1 && !useStartTLS1))
{
- useSSL1 = confirm(INFO_REPLICATION_USESSL_PROMPT.get(),
- useSSL1);
+ useSSL1 = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL1);
if (!useSSL1)
{
- useStartTLS1 = confirm(INFO_REPLICATION_USESTARTTLS_PROMPT.get(),
+ useStartTLS1 = confirm(INFO_CLI_USESTARTTLS_PROMPT.get(),
useStartTLS1);
}
}
@@ -621,7 +635,7 @@
LOG.log(Level.WARNING, "Error connecting to "+host2+":"+port2, ne);
if (Utils.isCertificateException(ne))
{
- String usedUrl = getLDAPUrl(host2, port2, useSSL2);
+ String usedUrl = ConnectionUtils.getLDAPUrl(host2, port2, useSSL2);
if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
{
cancelled = true;
@@ -633,7 +647,7 @@
{
printLineBreak();
printErrorMessage(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- host2+":"+port2));
+ host2+":"+port2, ne.getMessage()));
}
printLineBreak();
if (!firstTimeAsked || (argParser.getHostName2() == null))
@@ -649,21 +663,21 @@
}
if (!firstTimeAsked || (argParser.getBindDn2() == null))
{
- bindDn2 = promptForString(
- INFO_REPLICATION_BINDDN_PROMPT.get(),
+ bindDn2 = promptForString(INFO_CLI_BINDDN_PROMPT.get(),
getValue(bindDn2, argParser.getDefaultBindDn2()));
}
if (!firstTimeAsked || (argParser.getBindPassword2() == null))
{
- pwd2 = promptForPassword(INFO_REPLICATION_PASSWORD_PROMPT.get());
+ pwd2 = promptForPassword(
+ INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn2));
}
if (!firstTimeAsked || !useSSL2 || !useStartTLS2)
{
- useSSL2 = confirm(INFO_REPLICATION_USESSL_PROMPT.get(),
+ useSSL2 = confirm(INFO_CLI_USESSL_PROMPT.get(),
useSSL2);
if (!useSSL2)
{
- useStartTLS2 = confirm(INFO_REPLICATION_USESTARTTLS_PROMPT.get(),
+ useStartTLS2 = confirm(INFO_CLI_USESTARTTLS_PROMPT.get(),
useStartTLS2);
}
}
@@ -830,7 +844,7 @@
LOG.log(Level.WARNING, "Error connecting to "+host+":"+port, ne);
if (Utils.isCertificateException(ne))
{
- String usedUrl = getLDAPUrl(host, port, useSSL);
+ String usedUrl = ConnectionUtils.getLDAPUrl(host, port, useSSL);
if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
{
cancelled = true;
@@ -840,7 +854,7 @@
{
printLineBreak();
printErrorMessage(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- host+":"+port));
+ host+":"+port, ne.getMessage()));
printLineBreak();
if (!firstTimeAsked || (argParser.getHostNameToDisable() == null))
{
@@ -864,11 +878,11 @@
}
if (!firstTimeAsked || useSSL)
{
- useSSL = confirm(INFO_REPLICATION_USESSL_PROMPT.get(), useSSL);
+ useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
if (!useSSL)
{
useStartTLS =
- confirm(INFO_REPLICATION_USESTARTTLS_PROMPT.get(), useStartTLS);
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
}
}
firstTimeAsked = false;
@@ -991,7 +1005,8 @@
ne);
if (Utils.isCertificateException(ne))
{
- String usedUrl = getLDAPUrl(hostSource, portSource, useSSLSource);
+ String usedUrl = ConnectionUtils.getLDAPUrl(hostSource, portSource,
+ useSSLSource);
if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
{
cancelled = true;
@@ -1001,7 +1016,7 @@
{
printLineBreak();
printErrorMessage(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- hostSource+":"+portSource));
+ hostSource+":"+portSource, ne.getMessage()));
printLineBreak();
if (!firstTimeAsked || (argParser.getHostNameSource() == null))
{
@@ -1025,13 +1040,11 @@
}
if (!firstTimeAsked || useSSLSource)
{
- useSSLSource = confirm(INFO_REPLICATION_USESSL_PROMPT.get(),
- useSSLSource);
+ useSSLSource = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSLSource);
if (!useSSLSource)
{
useStartTLSSource =
- confirm(INFO_REPLICATION_USESTARTTLS_PROMPT.get(),
- useStartTLSSource);
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLSSource);
}
}
firstTimeAsked = false;
@@ -1077,8 +1090,8 @@
if (Utils.isCertificateException(ne))
{
- String usedUrl = getLDAPUrl(hostDestination, portDestination,
- useSSLDestination);
+ String usedUrl = ConnectionUtils.getLDAPUrl(hostDestination,
+ portDestination, useSSLDestination);
if (!promptForCertificateConfirmation(ne, getTrustManager(), usedUrl))
{
cancelled = true;
@@ -1088,7 +1101,7 @@
{
printLineBreak();
printErrorMessage(ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- hostDestination+":"+portDestination));
+ hostDestination+":"+portDestination, ne.getMessage()));
printLineBreak();
if (!firstTimeAsked || (argParser.getHostNameDestination() == null))
{
@@ -1106,12 +1119,12 @@
}
if (!firstTimeAsked || useSSLDestination)
{
- useSSLDestination = confirm(INFO_REPLICATION_USESSL_PROMPT.get(),
+ useSSLDestination = confirm(INFO_CLI_USESSL_PROMPT.get(),
useSSLDestination);
if (!useSSLDestination)
{
useStartTLSDestination =
- confirm(INFO_REPLICATION_USESTARTTLS_PROMPT.get(),
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(),
useStartTLSDestination);
}
}
@@ -1363,72 +1376,6 @@
}
/**
- * Returns an InitialLdapContext using the provided parameters. We try
- * to guarantee that the connection is able to read the configuration.
- * @param host the host name.
- * @param port the port to connect.
- * @param useSSL whether to use SSL or not.
- * @param useStartTLS whether to use StartTLS or not.
- * @param bindDn the bind dn to be used.
- * @param pwd the password.
- * @param trustManager the trust manager.
- * @return an InitialLdapContext connected.
- * @throws NamingException if there was an error establishing the connection.
- */
- private InitialLdapContext createContext(String host, int port,
- boolean useSSL, boolean useStartTLS, String bindDn, String pwd,
- ApplicationTrustManager trustManager)
- throws NamingException
- {
- InitialLdapContext ctx;
- String ldapUrl = getLDAPUrl(host, port, useSSL);
- if (useSSL)
- {
- ctx = Utils.createLdapsContext(ldapUrl, bindDn, pwd,
- Utils.getDefaultLDAPTimeout(), null, trustManager);
- }
- else if (useStartTLS)
- {
- ctx = Utils.createStartTLSContext(ldapUrl, bindDn, pwd,
- Utils.getDefaultLDAPTimeout(), null, trustManager,
- null);
- }
- else
- {
- ctx = Utils.createLdapContext(ldapUrl, bindDn, pwd,
- Utils.getDefaultLDAPTimeout(), null);
- }
- if (!ConnectionUtils.connectedAsAdministrativeUser(ctx))
- {
- throw new NoPermissionException(
- ERR_NOT_ADMINISTRATIVE_USER.get().toString());
- }
- return ctx;
- }
-
- /**
- * Returns the LDAP URL for the provided parameters.
- * @param host the host name.
- * @param port the LDAP port.
- * @param useSSL whether to use SSL or not.
- * @return the LDAP URL for the provided parameters.
- */
- private String getLDAPUrl(String host, int port, boolean useSSL)
- {
- String ldapUrl;
- host = Utils.getHostNameForLdapUrl(host);
- if (useSSL)
- {
- ldapUrl = "ldaps://"+host+":"+port;
- }
- else
- {
- ldapUrl = "ldap://"+host+":"+port;
- }
- return ldapUrl;
- }
-
- /**
* Tells whether the server to which the LdapContext is connected has a
* replication port or not.
* @param ctx the InitialLdapContext to be used.
@@ -1581,7 +1528,7 @@
printLineBreak();
printErrorMessage(
ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN.get(
- host+":"+port));
+ host+":"+port, t.getMessage()));
LOG.log(Level.WARNING, "Complete error stack:", t);
printLineBreak();
}
diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliParser.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliParser.java
index a00fd16..ce9e258 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliParser.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliParser.java
@@ -60,7 +60,7 @@
private SubCommand disableReplicationSubCmd;
private SubCommand initializeReplicationSubCmd;
- private BooleanArgument interactive;
+ private BooleanArgument noPromptArg;
/**
* The 'hostName' global argument for the first server.
@@ -361,38 +361,39 @@
{
defaultArgs.remove(argsToRemove[i]);
}
+ int index = 0;
baseDNsArg = new StringArgument("baseDNs", 'b',
"baseDNs", false, true, true, OPTION_VALUE_BASEDN, null,
null, INFO_DESCRIPTION_REPLICATION_BASEDNS.get());
- defaultArgs.add(baseDNsArg);
+ defaultArgs.add(index++, baseDNsArg);
adminUidArg = new StringArgument("adminUID", 'I',
"adminUID", false, false, true, "adminUID",
Constants.GLOBAL_ADMIN_UID, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_UID.get(
ENABLE_REPLICATION_SUBCMD_NAME));
- defaultArgs.add(adminUidArg);
+ defaultArgs.add(index++, adminUidArg);
adminPasswordArg = new StringArgument("adminPassword",
OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
OPTION_VALUE_BINDPWD, null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
- defaultArgs.add(adminPasswordArg);
+ defaultArgs.add(index++, adminPasswordArg);
adminPasswordFileArg = new FileBasedArgument("adminPasswordFile",
OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
OPTION_VALUE_BINDPWD_FILE, null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
- defaultArgs.add(adminPasswordFileArg);
+ defaultArgs.add(index++, adminPasswordFileArg);
defaultArgs.remove(verboseArg);
- interactive = new BooleanArgument(
- INTERACTIVE_OPTION_LONG,
- INTERACTIVE_OPTION_SHORT,
- INTERACTIVE_OPTION_LONG,
- INFO_DESCRIPTION_INTERACTIVE.get());
- defaultArgs.add(interactive);
+ noPromptArg = new BooleanArgument(
+ NO_PROMPT_OPTION_LONG,
+ NO_PROMPT_OPTION_SHORT,
+ NO_PROMPT_OPTION_LONG,
+ INFO_DESCRIPTION_NO_PROMPT.get());
+ defaultArgs.add(index++, noPromptArg);
quietArg = new BooleanArgument(
SecureConnectionCliParser.QUIET_OPTION_LONG,
@@ -580,7 +581,7 @@
*/
public boolean isInteractive()
{
- return interactive.isPresent();
+ return !noPromptArg.isPresent();
}
/**
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromFile.java b/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromFile.java
index 5c3beca..93458b7 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromFile.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromFile.java
@@ -267,6 +267,89 @@
return url;
}
+ /**
+ * Retuns the LDAP URL for the specified connection policy.
+ * @param policy the connection policy to be used.
+ * @return the LDAP URL for the specified connection policy.
+ * @throws ConfigException if a valid LDAP URL could not be found.
+ */
+ public String getURL(ConnectionProtocolPolicy policy) throws ConfigException
+ {
+ String url;
+ String ldapUrl = getLDAPURL();
+ String startTlsUrl = getStartTLSURL();
+ String ldapsUrl = getLDAPSURL();
+ switch (policy)
+ {
+ case USE_STARTTLS:
+ if (startTlsUrl != null)
+ {
+ url = startTlsUrl;
+ }
+ else
+ {
+ throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ }
+ break;
+ case USE_LDAPS:
+ if (ldapsUrl != null)
+ {
+ url = ldapsUrl;
+ }
+ else
+ {
+ throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ }
+ break;
+ case USE_LDAP:
+ if (ldapUrl != null)
+ {
+ url = ldapUrl;
+ }
+ else
+ {
+ throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ }
+ break;
+ case USE_MOST_SECURE_AVAILABLE:
+ if (ldapsUrl != null)
+ {
+ url = ldapsUrl;
+ }
+ else if (startTlsUrl != null)
+ {
+ url = startTlsUrl;
+ }
+ else if (ldapUrl != null)
+ {
+ url = ldapUrl;
+ }
+ else
+ {
+ throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ }
+ break;
+ case USE_LESS_SECURE_AVAILABLE:
+ if (ldapUrl != null)
+ {
+ url = ldapUrl;
+ }
+ else if (ldapsUrl != null)
+ {
+ url = ldapsUrl;
+ }
+ else
+ {
+ throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ }
+ break;
+ default:
+ throw new IllegalStateException("Unknown connection policy: "+
+ policy);
+ }
+ return url;
+ }
+
private String getLDAPURL(boolean secure)
{
String url = null;
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java b/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
index ee770d6..b4bd6a3 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
@@ -124,7 +124,7 @@
this.trustManager = trustManager;
this.offlineConf = offlineConf;
this.policy = policy;
- String ldapUrl = getURL(offlineConf, policy);
+ String ldapUrl = offlineConf.getURL(policy);
if (!Utils.areDnsEqual(dn, this.dn) ||
!pwd.equals(this.pwd) ||
@@ -1003,82 +1003,4 @@
{
return ConfigFromFile.isConfigBackend(id);
}
-
- private String getURL(ConfigFromFile offlineConf,
- ConnectionProtocolPolicy policy) throws ConfigException
- {
- String url;
- String ldapUrl = offlineConf.getLDAPURL();
- String startTlsUrl = offlineConf.getStartTLSURL();
- String ldapsUrl = offlineConf.getLDAPSURL();
- switch (policy)
- {
- case USE_STARTTLS:
- if (startTlsUrl != null)
- {
- url = startTlsUrl;
- }
- else
- {
- throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
- }
- break;
- case USE_LDAPS:
- if (ldapsUrl != null)
- {
- url = ldapsUrl;
- }
- else
- {
- throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
- }
- break;
- case USE_LDAP:
- if (ldapUrl != null)
- {
- url = ldapUrl;
- }
- else
- {
- throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
- }
- break;
- case USE_MOST_SECURE_AVAILABLE:
- if (ldapsUrl != null)
- {
- url = ldapsUrl;
- }
- else if (startTlsUrl != null)
- {
- url = startTlsUrl;
- }
- else if (ldapUrl != null)
- {
- url = ldapUrl;
- }
- else
- {
- throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
- }
- break;
- case USE_LESS_SECURE_AVAILABLE:
- if (ldapUrl != null)
- {
- url = ldapUrl;
- }
- else if (ldapsUrl != null)
- {
- url = ldapsUrl;
- }
- else
- {
- throw new ConfigException(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
- }
- break;
- default:
- throw new IllegalStateException("Unknown connection policy: "+
- policy);
- }
- return url;
- }
}
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
index a26ae7b..4a02cfd 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -28,23 +28,33 @@
package org.opends.guitools.statuspanel;
import java.io.File;
-import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.URI;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
import javax.swing.table.TableModel;
+import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.statuspanel.ui.DatabasesTableModel;
import org.opends.guitools.statuspanel.ui.ListenersTableModel;
+import org.opends.quicksetup.CliApplicationHelper;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.QuickSetupLog;
+import org.opends.quicksetup.util.Utils;
+
import static org.opends.quicksetup.util.Utils.*;
import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
-import org.opends.server.admin.client.cli.SecureConnectionCliParser;
import org.opends.server.core.DirectoryServer;
import org.opends.messages.Message;
@@ -53,7 +63,7 @@
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
-import org.opends.server.util.args.Argument;
+import org.opends.server.types.NullOutputStream;
import org.opends.server.util.args.ArgumentException;
/**
@@ -63,90 +73,222 @@
* in the command line.
*
*/
-class StatusCli extends SecureConnectionCliParser
+class StatusCli extends CliApplicationHelper
{
- private String[] args;
private boolean displayMustAuthenticateLegend;
private boolean displayMustStartLegend;
+ /** Prefix for log files. */
+ static public final String LOG_FILE_PREFIX = "opends-status-";
+
+ /** Suffix for log files. */
+ static public final String LOG_FILE_SUFFIX = ".log";
+
+ /**
+ * The enumeration containing the different return codes that the command-line
+ * can have.
+ *
+ */
+ enum ErrorReturnCode
+ {
+ /**
+ * Successful display of the status.
+ */
+ SUCCESSFUL(0),
+ /**
+ * We did no have an error but the status was not displayed (displayed
+ * version or usage).
+ */
+ SUCCESSFUL_NOP(0),
+ /**
+ * Unexpected error (potential bug).
+ */
+ ERROR_UNEXPECTED(1),
+ /**
+ * Cannot parse arguments.
+ */
+ ERROR_PARSING_ARGS(2),
+ /**
+ * User cancelled (for instance not accepting the certificate proposed).
+ */
+ USER_CANCELLED(3);
+
+ private int returnCode;
+ private ErrorReturnCode(int returnCode)
+ {
+ this.returnCode = returnCode;
+ }
+
+ /**
+ * Get the corresponding return code value.
+ *
+ * @return The corresponding return code value.
+ */
+ public int getReturnCode()
+ {
+ return returnCode;
+ }
+ };
+
/**
* The Logger.
*/
static private final Logger LOG = Logger.getLogger(StatusCli.class.getName());
+ // The argument parser
+ private StatusCliParser argParser;
+
/**
- * The main method which is called by the status command lines.
- * @param args the arguments passed by the status command lines.
+ * Constructor for the StatusCli object.
+ *
+ * @param out the print stream to use for standard output.
+ * @param err the print stream to use for standard error.
+ * @param in the input stream to use for standard input.
*/
+ public StatusCli(PrintStream out, PrintStream err, InputStream in)
+ {
+ super(out, err, in);
+ }
+
+ /**
+ * The main method for the status CLI tool.
+ *
+ * @param args the command-line arguments provided to this program.
+ */
+
public static void main(String[] args)
{
- QuickSetupLog.disableConsoleLogging();
- StatusCli cli = new StatusCli(args);
- System.exit(cli.run());
+ int retCode = mainCLI(args, true, System.out, System.err, System.in);
+
+ if(retCode != 0)
+ {
+ System.exit(retCode);
+ }
}
/**
- * The constructor for this object.
- * @param args the arguments of the status command line.
+ * Parses the provided command-line arguments and uses that information to
+ * run the replication tool.
+ *
+ * @param args the command-line arguments provided to this program.
+ *
+ * @return The error code.
*/
- StatusCli(String[] args)
+
+ public static int mainCLI(String[] args)
{
- super(org.opends.guitools.statuspanel.StatusCli.class.getName(),
- INFO_STATUS_CLI_USAGE_DESCRIPTION.get(), false);
- this.args = args;
- DirectoryServer.bootstrapClient();
+ return mainCLI(args, true, System.out, System.err, System.in);
}
/**
- * Parses the user data and displays usage if something is missing and the
- * status otherwise.
+ * Parses the provided command-line arguments and uses that information to
+ * run the replication tool.
+ *
+ * @param args The command-line arguments provided to this
+ * program.
+ * @param initializeServer Indicates whether to initialize the server.
+ * @param outStream The output stream to use for standard output, or
+ * <CODE>null</CODE> if standard output is not
+ * needed.
+ * @param errStream The output stream to use for standard error, or
+ * <CODE>null</CODE> if standard error is not
+ * needed.
+ * @param inStream The input stream to use for standard input.
+ * @return The error code.
+ */
+
+ public static int mainCLI(String[] args, boolean initializeServer,
+ OutputStream outStream, OutputStream errStream, InputStream inStream)
+ {
+ PrintStream out;
+ if (outStream == null)
+ {
+ out = NullOutputStream.printStream();
+ }
+ else
+ {
+ out = new PrintStream(outStream);
+ }
+
+ PrintStream err;
+ if (errStream == null)
+ {
+ err = NullOutputStream.printStream();
+ }
+ else
+ {
+ err = new PrintStream(errStream);
+ }
+
+ try {
+ QuickSetupLog.initLogFileHandler(
+ File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX),
+ "org.opends.guitools.statuspanel");
+ QuickSetupLog.disableConsoleLogging();
+ } catch (Throwable t) {
+ System.err.println("Unable to initialize log");
+ t.printStackTrace();
+ }
+
+ StatusCli statusCli = new StatusCli(out, err, inStream);
+
+ return statusCli.execute(args, initializeServer);
+ }
+
+ /**
+ * Parses the provided command-line arguments and uses that information to
+ * run the status CLI.
+ *
+ * @param args the command-line arguments provided to this program.
+ * @param initializeServer Indicates whether to initialize the server.
*
* @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG.
*/
- int run()
+ public int execute(String[] args, boolean initializeServer)
{
+ if (initializeServer)
+ {
+ DirectoryServer.bootstrapClient();
+ }
+
+ argParser = new StatusCliParser(StatusCli.class.getName());
try
{
- ArrayList<Argument> defaultArgs =
- new ArrayList<Argument>(createGlobalArguments(System.err));
- defaultArgs.remove(portArg);
- defaultArgs.remove(hostNameArg);
- defaultArgs.remove(verboseArg);
- initializeGlobalArguments(defaultArgs);
+ argParser.initializeGlobalArguments(err);
}
catch (ArgumentException ae)
{
Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
- System.err.println(wrap(message));
- return DsFrameworkCliReturnCode.ERROR_UNEXPECTED.getReturnCode();
+ err.println(wrap(message));
+ return ErrorReturnCode.ERROR_UNEXPECTED.getReturnCode();
}
// Validate user provided data
try
{
- parseArguments(args);
+ argParser.parseArguments(args);
}
catch (ArgumentException ae)
{
Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
- System.err.println(wrap(message));
- System.err.println(getUsage());
+ err.println(wrap(message));
+ err.println(argParser.getUsage());
- return DsFrameworkCliReturnCode.ERROR_PARSING_ARGS.getReturnCode();
+ return ErrorReturnCode.ERROR_PARSING_ARGS.getReturnCode();
}
// If we should just display usage or version information,
// then print it and exit.
- if (usageOrVersionDisplayed())
+ if (argParser.usageOrVersionDisplayed())
{
- return DsFrameworkCliReturnCode.SUCCESSFUL_NOP.getReturnCode();
+ return ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode();
}
- int v = validateGlobalOptions(System.err);
+ int v = argParser.validateGlobalOptions(err);
if (v != DsFrameworkCliReturnCode.SUCCESSFUL_NOP.getReturnCode())
{
- System.err.println(getUsage());
+ err.println(argParser.getUsage());
return v;
}
else
@@ -163,35 +305,131 @@
{
if (isServerRunning)
{
- String directoryManagerDn = getBindDN();
- String directoryManagerPwd = getBindPassword(directoryManagerDn,
- System.out, System.err);
- if (directoryManagerDn == null)
+ String bindDn = argParser.getBindDN();
+ String bindPwd;
+ boolean useSSL = argParser.useSSL();
+ boolean useStartTLS = argParser.useStartTLS();
+ if (argParser.isInteractive())
{
- directoryManagerDn = "";
- }
- if (directoryManagerPwd == null)
- {
- directoryManagerPwd = "";
- }
- ServerStatusDescriptor desc = createServerStatusDescriptor(
- directoryManagerDn, directoryManagerPwd);
- ConfigFromLDAP onLineConf = new ConfigFromLDAP();
- ConnectionProtocolPolicy policy;
- if (useStartTLSArg.isPresent())
- {
- policy = ConnectionProtocolPolicy.USE_STARTTLS;
- }
- if (useSSLArg.isPresent())
- {
- policy = ConnectionProtocolPolicy.USE_LDAPS;
+ boolean connected = false;
+ boolean cancelled = false;
+
+ bindPwd = argParser.getBindPassword();
+ if (bindPwd == null)
+ {
+ bindPwd = promptForPassword(
+ INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn));
+ }
+
+ InitialLdapContext ctx = null;
+ while (!connected && !cancelled)
+ {
+ String host = "localhost";
+ int port = 389;
+ try
+ {
+ String ldapUrl = offLineConf.getURL(
+ getConnectionPolicy(useSSL, useStartTLS));
+ try
+ {
+ URI uri = new URI(ldapUrl);
+ host = uri.getHost();
+ port = uri.getPort();
+ }
+ catch (Throwable t)
+ {
+ LOG.log(Level.SEVERE, "Error parsing url: "+ldapUrl);
+ }
+ ctx = createContext(host, port, useSSL, useStartTLS, bindDn,
+ bindPwd, getTrustManager());
+ connected = true;
+ }
+ catch (ConfigException ce)
+ {
+ LOG.log(Level.WARNING, "Error reading config file: "+ce, ce);
+ printLineBreak();
+ printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
+ useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
+ if (!useSSL)
+ {
+ useStartTLS =
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
+ }
+ }
+ catch (NamingException ne)
+ {
+ LOG.log(Level.WARNING, "Error connecting: "+ne, ne);
+
+ if (Utils.isCertificateException(ne))
+ {
+ String usedUrl = ConnectionUtils.getLDAPUrl(host, port,
+ useSSL);
+ if (!promptForCertificateConfirmation(ne, getTrustManager(),
+ usedUrl))
+ {
+ cancelled = true;
+ }
+ }
+ else
+ {
+ printLineBreak();
+ printErrorMessage(
+ ERR_STATUS_CLI_ERROR_CONNECTING_PROMPT_AGAIN.get(
+ ne.getMessage()));
+ String defaultValue = (bindDn != null) ? bindDn :
+ argParser.getDefaultBindDn();
+
+ bindDn = promptForString(
+ INFO_CLI_BINDDN_PROMPT.get(), defaultValue);
+
+ bindPwd = promptForPassword(
+ INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn));
+
+ printLineBreak();
+ useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
+ if (!useSSL)
+ {
+ useStartTLS =
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
+ }
+ }
+ }
+ }
+ if (ctx != null)
+ {
+ try
+ {
+ ctx.close();
+ }
+ catch (Throwable t)
+ {
+ }
+ }
+ if (cancelled)
+ {
+ return ErrorReturnCode.USER_CANCELLED.getReturnCode();
+ }
}
else
{
- policy = ConnectionProtocolPolicy.USE_MOST_SECURE_AVAILABLE;
+ bindPwd = argParser.getBindPassword();
+
+ if (bindDn == null)
+ {
+ bindDn = "";
+ }
+ if (bindPwd == null)
+ {
+ bindPwd = "";
+ }
}
- onLineConf.setConnectionInfo(offLineConf, policy, directoryManagerDn,
- directoryManagerPwd, getTrustManager());
+ ServerStatusDescriptor desc = createServerStatusDescriptor(
+ bindDn, bindPwd);
+ ConfigFromLDAP onLineConf = new ConfigFromLDAP();
+ ConnectionProtocolPolicy policy = getConnectionPolicy(useSSL,
+ useStartTLS);
+ onLineConf.setConnectionInfo(offLineConf, policy, bindDn,
+ bindPwd, getTrustManager());
onLineConf.readConfiguration();
updateDescriptorWithOnLineInfo(desc, onLineConf);
writeStatus(desc);
@@ -206,11 +444,11 @@
}
catch (ConfigException ce)
{
- System.err.println(wrap(ce.getMessageObject()));
+ printErrorMessage(ce.getMessageObject());
}
}
- return DsFrameworkCliReturnCode.SUCCESSFUL_NOP.getReturnCode();
+ return ErrorReturnCode.SUCCESSFUL.getReturnCode();
}
private ServerStatusDescriptor createServerStatusDescriptor(String dn,
@@ -286,23 +524,23 @@
{
labelWidth = Math.max(labelWidth, labels[i].length());
}
- System.out.println();
+ out.println();
Message title = INFO_SERVER_STATUS_TITLE.get();
- System.out.println(centerTitle(title));
+ out.println(centerTitle(title));
writeStatusContents(desc, labelWidth);
writeCurrentConnectionContents(desc, labelWidth);
- System.out.println();
+ out.println();
title = INFO_SERVER_DETAILS_TITLE.get();
- System.out.println(centerTitle(title));
+ out.println(centerTitle(title));
writeAdministrativeUserContents(desc, labelWidth);
writeInstallPathContents(desc, labelWidth);
writeVersionContents(desc, labelWidth);
writeJavaVersionContents(desc, labelWidth);
- System.out.println();
+ out.println();
writeListenerContents(desc);
- System.out.println();
+ out.println();
writeDatabaseContents(desc);
@@ -310,16 +548,16 @@
if (displayMustStartLegend)
{
- System.out.println();
- System.out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
+ out.println();
+ out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
}
else if (displayMustAuthenticateLegend)
{
- System.out.println();
- System.out.println(
+ out.println();
+ out.println(
wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
}
- System.out.println();
+ out.println();
}
/**
@@ -519,7 +757,7 @@
private void writeListenerContents(ServerStatusDescriptor desc)
{
Message title = INFO_LISTENERS_TITLE.get();
- System.out.println(centerTitle(title));
+ out.println(centerTitle(title));
Set<ListenerDescriptor> listeners = desc.getListeners();
@@ -529,17 +767,17 @@
{
if (!desc.isAuthenticated())
{
- System.out.println(
+ out.println(
wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()));
}
else
{
- System.out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
+ out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
}
}
else
{
- System.out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
+ out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
}
}
else
@@ -558,7 +796,7 @@
private void writeDatabaseContents(ServerStatusDescriptor desc)
{
Message title = INFO_DATABASES_TITLE.get();
- System.out.println(centerTitle(title));
+ out.println(centerTitle(title));
Set<DatabaseDescriptor> databases = desc.getDatabases();
@@ -568,17 +806,17 @@
{
if (!desc.isAuthenticated())
{
- System.out.println(
+ out.println(
wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()));
}
else
{
- System.out.println(wrap(INFO_NO_DBS_FOUND.get()));
+ out.println(wrap(INFO_NO_DBS_FOUND.get()));
}
}
else
{
- System.out.println(wrap(INFO_NO_DBS_FOUND.get()));
+ out.println(wrap(INFO_NO_DBS_FOUND.get()));
}
}
else
@@ -606,8 +844,8 @@
Message errorMsg = desc.getErrorMessage();
if (errorMsg != null)
{
- System.out.println();
- System.out.println(wrap(errorMsg));
+ out.println();
+ out.println(wrap(errorMsg));
}
}
@@ -718,13 +956,13 @@
headerLine.append(" ");
}
}
- System.out.println(wrap(headerLine.toMessage()));
+ out.println(wrap(headerLine.toMessage()));
MessageBuilder t = new MessageBuilder();
for (int i=0; i<headerLine.length(); i++)
{
t.append("=");
}
- System.out.println(wrap(t.toMessage()));
+ out.println(wrap(t.toMessage()));
for (int i=0; i<tableModel.getRowCount(); i++)
{
@@ -771,7 +1009,7 @@
line.append(" ");
}
}
- System.out.println(wrap(line.toMessage()));
+ out.println(wrap(line.toMessage()));
}
}
@@ -809,7 +1047,7 @@
{
if (i > 0)
{
- System.out.println();
+ out.println();
}
for (int j=0; j<tableModel.getColumnCount(); j++)
{
@@ -899,7 +1137,7 @@
buf.append(" ");
}
buf.append(" ").append(String.valueOf(value));
- System.out.println(wrap(buf.toMessage()));
+ out.println(wrap(buf.toMessage()));
}
@@ -924,6 +1162,40 @@
}
return centered;
}
+
+ /**
+ * Returns the trust manager to be used by this application.
+ * @return the trust manager to be used by this application.
+ */
+ private ApplicationTrustManager getTrustManager()
+ {
+ return argParser.getTrustManager();
+ }
+
+ /**
+ * Returns the ConnectionPolicy to be used with the parameters provided
+ * by the user.
+ * @param useSSL whether the user asked to use SSL or not.
+ * @param useStartTLS whether the user asked to use Start TLS or not.
+ * @return the ConnectionPolicy to be used with the parameters provided
+ * by the user.
+ */
+ private ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
+ boolean useStartTLS)
+ {
+ ConnectionProtocolPolicy policy;
+ if (useStartTLS)
+ {
+ policy = ConnectionProtocolPolicy.USE_STARTTLS;
+ }
+ if (useSSL)
+ {
+ policy = ConnectionProtocolPolicy.USE_LDAPS;
+ }
+ else
+ {
+ policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
+ }
+ return policy;
+ }
}
-
-
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java
new file mode 100644
index 0000000..2cacc19
--- /dev/null
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java
@@ -0,0 +1,126 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+
+package org.opends.guitools.statuspanel;
+
+import static org.opends.messages.AdminToolMessages.*;
+import static org.opends.messages.ToolMessages.*;
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.opends.server.admin.client.cli.SecureConnectionCliParser;
+import org.opends.server.util.args.Argument;
+import org.opends.server.util.args.ArgumentException;
+import org.opends.server.util.args.BooleanArgument;
+
+/**
+ * The class that is used to parse the arguments provided in the status command
+ * line.
+ *
+ */
+public class StatusCliParser extends SecureConnectionCliParser
+{
+ private BooleanArgument noPromptArg;
+
+ /**
+ * Creates a new instance of this argument parser with no arguments.
+ *
+ * @param mainClassName
+ * The fully-qualified name of the Java class that should
+ * be invoked to launch the program with which this
+ * argument parser is associated.
+ */
+ public StatusCliParser(String mainClassName)
+ {
+ super(mainClassName, INFO_STATUS_CLI_USAGE_DESCRIPTION.get(), false);
+ }
+
+ /**
+ * Initialize Global option.
+ *
+ * @param outStream
+ * The output stream used for the usage.
+ * @throws ArgumentException
+ * If there is a problem with any of the parameters used
+ * to create this argument.
+ */
+ public void initializeGlobalArguments(OutputStream outStream)
+ throws ArgumentException
+ {
+ ArrayList<Argument> defaultArgs =
+ new ArrayList<Argument>(createGlobalArguments(outStream));
+ defaultArgs.remove(portArg);
+ defaultArgs.remove(hostNameArg);
+ defaultArgs.remove(verboseArg);
+ noPromptArg = new BooleanArgument(
+ NO_PROMPT_OPTION_LONG,
+ NO_PROMPT_OPTION_SHORT,
+ NO_PROMPT_OPTION_LONG,
+ INFO_DESCRIPTION_NO_PROMPT.get());
+ defaultArgs.add(0, noPromptArg);
+ initializeGlobalArguments(defaultArgs);
+ }
+
+ /**
+ * Tells whether the user specified to have an interactive uninstall or not.
+ * This method must be called after calling parseArguments.
+ * @return <CODE>true</CODE> if the user specified to have an interactive
+ * uninstall and <CODE>false</CODE> otherwise.
+ */
+ public boolean isInteractive()
+ {
+ return !noPromptArg.isPresent();
+ }
+
+ /**
+ * Returns the first server bind dn explicitly provided in the enable
+ * replication subcommand.
+ * @return the first server bind dn explicitly provided in the enable
+ * replication subcommand. Returns -1 if no port was explicitly provided.
+ */
+ public String getExplicitBindDn()
+ {
+ String dn = null;
+ if (bindDnArg.isPresent())
+ {
+ dn = bindDnArg.getValue();
+ }
+ return dn;
+ }
+
+ /**
+ * Returns the first server bind dn default value in the enable replication
+ * subcommand.
+ * @return the first server bind dn default value in the enable replication
+ * subcommand.
+ */
+ public String getDefaultBindDn()
+ {
+ return bindDnArg.getDefaultValue();
+ }
+}
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index e1e4d3a..ac26dcc 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -78,6 +78,14 @@
private UninstallerArgumentParser parser;
/**
+ * Default constructor.
+ */
+ public UninstallCliHelper()
+ {
+ super(System.out, System.err, System.in);
+ }
+
+ /**
* Creates a UserData based in the arguments provided. It asks
* user for additional information if what is provided in the arguments is not
* enough.
@@ -620,21 +628,21 @@
try
{
String dn = ADSContext.getAdministratorDN(uid);
- if ((ldapsUrl != null) && (parser.useSSL() || !parser.startTLS()))
+ if ((ldapsUrl != null) && (parser.useSSL() || !parser.useStartTLS()))
{
usedUrl = ldapsUrl;
ctx = Utils.createLdapsContext(ldapsUrl, dn, pwd,
Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager());
}
else if ((startTlsUrl != null) &&
- (!parser.useSSL() || parser.startTLS()))
+ (!parser.useSSL() || parser.useStartTLS()))
{
usedUrl = startTlsUrl;
ctx = Utils.createStartTLSContext(startTlsUrl, dn, pwd,
Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager(),
null);
}
- else if ((ldapUrl != null) && !parser.useSSL() && !parser.startTLS())
+ else if ((ldapUrl != null) && !parser.useSSL() && !parser.useStartTLS())
{
usedUrl = ldapUrl;
ctx = Utils.createLdapContext(ldapUrl, dn, pwd,
@@ -838,19 +846,19 @@
String adminUid = userData.getAdminUID();
String pwd = userData.getAdminPwd();
String dn = ADSContext.getAdministratorDN(adminUid);
- if ((ldapsUrl != null) && (parser.useSSL() || !parser.startTLS()))
+ if ((ldapsUrl != null) && (parser.useSSL() || !parser.useStartTLS()))
{
ctx = Utils.createLdapsContext(ldapsUrl, dn, pwd,
Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager());
}
else if ((startTlsUrl != null) &&
- (!parser.useSSL() || parser.startTLS()))
+ (!parser.useSSL() || parser.useStartTLS()))
{
ctx = Utils.createStartTLSContext(startTlsUrl, dn, pwd,
Utils.getDefaultLDAPTimeout(), null, userData.getTrustManager(),
null);
}
- else if ((ldapUrl != null) && !parser.useSSL() && !parser.startTLS())
+ else if ((ldapUrl != null) && !parser.useSSL() && !parser.useStartTLS())
{
ctx = Utils.createLdapContext(ldapUrl, dn, pwd,
Utils.getDefaultLDAPTimeout(), null);
diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
index 04fd1b9..8d0e507 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallerArgumentParser.java
@@ -52,7 +52,7 @@
*/
public class UninstallerArgumentParser extends SecureConnectionCliParser
{
- private BooleanArgument interactive;
+ private BooleanArgument noPrompt;
private BooleanArgument forceOnError;
private BooleanArgument quiet;
private BooleanArgument removeAll;
@@ -151,17 +151,17 @@
INFO_UNINSTALLDS_DESCRIPTION_REMOVE_LDIF_FILES.get()
);
args.add(removeLDIFFiles);
- interactive = new BooleanArgument(
- INTERACTIVE_OPTION_LONG,
- INTERACTIVE_OPTION_SHORT,
- INTERACTIVE_OPTION_LONG,
- INFO_DESCRIPTION_INTERACTIVE.get());
- args.add(interactive);
+ noPrompt = new BooleanArgument(
+ NO_PROMPT_OPTION_LONG,
+ NO_PROMPT_OPTION_SHORT,
+ NO_PROMPT_OPTION_LONG,
+ INFO_DESCRIPTION_NO_PROMPT.get());
+ args.add(noPrompt);
forceOnError = new BooleanArgument(
"forceOnError",
'f',
"forceOnError",
- INFO_UNINSTALLDS_DESCRIPTION_FORCE.get());
+ INFO_UNINSTALLDS_DESCRIPTION_FORCE.get(noPrompt.getLongIdentifier()));
args.add(forceOnError);
quiet = new BooleanArgument(
SecureConnectionCliParser.QUIET_OPTION_LONG,
@@ -209,7 +209,7 @@
*/
public boolean isInteractive()
{
- return interactive.isPresent();
+ return !noPrompt.isPresent();
}
/**
@@ -370,11 +370,10 @@
public int validateGlobalOptions(MessageBuilder buf)
{
int returnValue;
- if (interactive.isPresent() && forceOnError.isPresent())
+ if (!noPrompt.isPresent() && forceOnError.isPresent())
{
- Message message = ERR_TOOL_CONFLICTING_ARGS.get(
- interactive.getLongIdentifier(),
- forceOnError.getLongIdentifier());
+ Message message = ERR_UNINSTALL_FORCE_REQUIRES_NO_PROMPT.get(
+ forceOnError.getLongIdentifier(), noPrompt.getLongIdentifier());
if (buf.length() > 0)
{
buf.append(EOL);
diff --git a/opends/src/messages/messages/admin_tool.properties b/opends/src/messages/messages/admin_tool.properties
index 04c0762..cc17bc2 100644
--- a/opends/src/messages/messages/admin_tool.properties
+++ b/opends/src/messages/messages/admin_tool.properties
@@ -266,6 +266,7 @@
INFO_STATE_COLUMN=State
INFO_STATUS_CLI_USAGE_DESCRIPTION=This utility may be used to display basic \
server information
+INFO_CLI_INVALID_PORT=The provided value is not a valid port
SEVERE_ERR_STATUS_PANEL_LAUNCHER_GUI_LAUNCH_FAILED=Could not launch Status \
Panel. Check that you have access to the display.
SEVERE_ERR_STATUS_PANEL_LAUNCHER_GUI_LAUNCH_FAILED_DETAILS=Could not launch \
@@ -337,8 +338,8 @@
INFO_UNKNOWN_LABEL=--
INFO_UNINSTALLDS_DESCRIPTION_FORCE=Specifies whether the uninstall should \
continue if there is an error updating references to this server in remote \
- OpenDS instances or not. This argument is not compatible with interactive \
- argument
+ OpenDS instances or not. This argument can only be used with the {%s} no \
+ prompt argument.
INFO_DESCRIPTION_REFERENCED_HOST=The name of this host (or IP address) as \
it is referenced in remote servers for replication
INFO_UNINSTALLDS_DESCRIPTION_CLI=Specifies to use the command line \
@@ -475,14 +476,18 @@
but no action was required
MILD_ERR_REPLICATION_USER_CANCELLED=User cancelled the operation
SEVERE_ERR_REPLICATION_NO_MESSAGE=
-
+SEVERE_ERR_UNINSTALL_FORCE_REQUIRES_NO_PROMPT=The {%s} argument only can be \
+ used when {%s} has been specified
INFO_ADMINISTRATOR_UID_PROMPT=Global Administrator User ID:
INFO_ADMINISTRATOR_PWD_PROMPT=Global Administrator Password:
INFO_ADMINISTRATOR_PWD_CONFIRM_PROMPT=Confirm Password:
MILD_ERR_ADMINISTRATOR_PWD_DO_NOT_MATCH=The provided passwords do not match.
MILD_ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN=Could not connect to the \
- Directory Server %s with the provided credentials.%nProvide again the \
- required information to connect to the server:
+ Directory Server %s with the provided credentials.%nError details: %s%nProvide \
+ again the required information to connect to the server:
+MILD_ERR_STATUS_CLI_ERROR_CONNECTING_PROMPT_AGAIN=Could not connect to the \
+ Directory Server with the provided credentials.%nError details: %s%nProvide \
+ again the required information to connect to the server:
INFO_REPLICATION_ENABLE_HOSTNAME1_PROMPT=Host name of the first server:
INFO_REPLICATION_ENABLE_PORT1_PROMPT=LDAP port of the first server:
INFO_REPLICATION_ENABLE_REPLICATIONPORT1_PROMPT=Replication port for the first \
@@ -500,11 +505,10 @@
destination server:
INFO_REPLICATION_INITIALIZE_PORTDESTINATION_PROMPT=LDAP port of the \
destination server:
-INFO_REPLICATION_BINDDN_PROMPT=Bind DN
-INFO_REPLICATION_PASSWORD_PROMPT=Password
-INFO_REPLICATION_USESSL_PROMPT=Use SSL to connect
+INFO_CLI_BINDDN_PROMPT=Bind DN
+INFO_CLI_USESSL_PROMPT=Use SSL to connect?
INFO_CLI_INVALID_PORT=The provided value is not a valid port
-INFO_REPLICATION_USESTARTTLS_PROMPT=Use StartTLS to connect
+INFO_CLI_USESTARTTLS_PROMPT=Use StartTLS to connect?
SEVERE_ERR_REPLICATION_PORT_AND_REPLICATION_PORT_EQUAL=The server LDAP port \
and the replication port cannot have the same value. You provided %s for both.
SEVERE_ERR_NO_SUFFIXES_AVAILABLE_TO_ENABLE_REPLICATION=There are no base DNs \
diff --git a/opends/src/messages/messages/quicksetup.properties b/opends/src/messages/messages/quicksetup.properties
index 8cbf3e4..8c79607 100644
--- a/opends/src/messages/messages/quicksetup.properties
+++ b/opends/src/messages/messages/quicksetup.properties
@@ -363,8 +363,8 @@
%s.
INFO_ERROR_LOGGING_OPERATION=Error writting operation details to log.
INFO_ERROR_OPTION_REQUIRED=Option %s is required.
-INFO_ERROR_OPTION_REQUIRED_OR_INTERACTIVE=Option %s is required when not \
- invoking this command in interactive mode. See the usage statement.
+INFO_ERROR_OPTION_REQUIRED_OR_INTERACTIVE=Option %s is required when invoking \
+ this command in non-interactive mode. See the usage statement.
INFO_ERROR_PARSING_OPTIONS=Error parsing options.
INFO_ERROR_POOLING_INITIALIZATION=Error reading the progress of the \
initialization with contents from server %s.
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 62d63aa..b13a171 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -1749,7 +1749,8 @@
property value per line
INFO_DESCRIPTION_QUIET_1075=Use quiet mode
INFO_DESCRIPTION_SCRIPT_FRIENDLY_1076=Use script-friendly mode
-INFO_DESCRIPTION_INTERACTIVE_1077=Use interactive mode
+INFO_DESCRIPTION_NO_PROMPT_1077=Use non-interactive mode. If some data in \
+the command is missing the user will not be prompted and the tool will fail
INFO_DSCFG_DESCRIPTION_UNIT_TIME_1078=Display time data using the specified \
unit. The value for UNIT can be one of ms, s, m, h, d, or w (milliseconds, \
seconds, minutes, hours, days, or weeks)
@@ -1988,8 +1989,8 @@
INFO_UPGRADE_DESCRIPTION_FILE_1190=Specifies an existing OpenDS package \
(.zip) file to which the current build will be upgraded using the command \
line version of this tool
-INFO_UPGRADE_DESCRIPTION_INTERACTIVE_1191=Prompt for any required information \
- rather than fail
+INFO_UPGRADE_DESCRIPTION_NO_PROMPT_1191=Use non-interactive mode. Prompt for \
+ any required information rather than fail
INFO_UPGRADE_DESCRIPTION_SILENT_1192=Perform a quiet upgrade
INFO_LDIFIMPORT_DESCRIPTION_COUNT_REJECTS_1195=Count the number of entries \
rejected by the server and return that value as the exit code (values > 255 \
@@ -2214,4 +2215,5 @@
root directory
SEVERE_ERR_CREATERC_CANNOT_WRITE_1325=An error occurred while attempting to \
generate the RC script: %s
-
+SEVERE_ERR_DSCFG_ERROR_QUIET_AND_INTERACTIVE_INCOMPATIBLE_1326=If you specify \
+ the {%s} argument you must also specify {%s}
diff --git a/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java b/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
index fd6cf28..43176a5 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
@@ -29,10 +29,12 @@
import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.ui.CertificateDialog;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
import static org.opends.messages.AdminToolMessages.*;
+import static org.opends.messages.ToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import org.opends.quicksetup.util.Utils;
@@ -53,22 +55,50 @@
import java.util.logging.Logger;
import java.util.logging.Level;
+import javax.naming.NamingException;
+import javax.naming.NoPermissionException;
+import javax.naming.ldap.InitialLdapContext;
+
/**
* Helper class containing useful methods for processing input and output
* for a CliApplication.
*/
-public class CliApplicationHelper {
+public abstract class CliApplicationHelper {
static private final Logger LOG =
- Logger.getLogger(CliApplication.class.getName());
+ Logger.getLogger(CliApplicationHelper.class.getName());
/** Format string used for deriving the console prompt. */
static public final String PROMPT_FORMAT = "%s%n[%s]:";
- private BooleanArgument interactiveArg = null;
+ private BooleanArgument noPromptArg = null;
private BooleanArgument quietArg = null;
+ /** The print stream to use for standard error. */
+ protected PrintStream err;
+
+ /** The print stream to use for standard output. */
+ protected PrintStream out;
+
+ /** The input stream. */
+ protected InputStream in;
+
+ /**
+ * Constructor for the CliApplicationHelper object.
+ *
+ * @param out the print stream to use for standard output.
+ * @param err the print stream to use for standard error.
+ * @param in the input stream to use for standard input.
+ */
+ protected CliApplicationHelper(PrintStream out, PrintStream err,
+ InputStream in)
+ {
+ this.out = out;
+ this.err = err;
+ this.in = in;
+ }
+
/**
* Interactively prompts (on standard output) the user to provide a string
* value. Any non-empty string will be allowed (the empty string will
@@ -95,8 +125,8 @@
Message msg = Message.raw(PROMPT_FORMAT, prompt, defaultValue);
- System.out.print(msg);
- System.out.flush();
+ out.print(msg);
+ out.flush();
response = Message.raw(readLine());
if (response.toString().equals(""))
@@ -131,23 +161,23 @@
Utils.getCommandLineMaxLineWidth());
while (true) {
- System.out.print(wrappedPrompt);
+ out.print(wrappedPrompt);
if (defaultValue == null) {
- System.out.print(": ");
+ out.print(": ");
} else {
- System.out.print("[");
- System.out.print(defaultValue);
- System.out.print("]: ");
+ out.print("[");
+ out.print(defaultValue);
+ out.print("]: ");
}
- System.out.flush();
+ out.flush();
String response = readLine();
if (response.equals("")) {
if (defaultValue == null) {
Message message = INFO_ERROR_EMPTY_RESPONSE.get();
- System.err.println(StaticUtils.wrapText(message,
+ err.println(StaticUtils.wrapText(message,
Utils.getCommandLineMaxLineWidth()));
} else {
return defaultValue;
@@ -172,8 +202,8 @@
printLineBreak();
String wrappedPrompt = StaticUtils.wrapText(msg,
Utils.getCommandLineMaxLineWidth());
- System.out.print(wrappedPrompt+" ");
- System.out.flush();
+ out.print(wrappedPrompt+" ");
+ out.flush();
try
{
char[] pwChars = PasswordReader.readPassword();
@@ -223,7 +253,7 @@
if (port == -1)
{
Message message = INFO_CLI_INVALID_PORT.get();
- System.err.println(StaticUtils.wrapText(message,
+ err.println(StaticUtils.wrapText(message,
Utils.getCommandLineMaxLineWidth()));
}
}
@@ -238,7 +268,7 @@
* attempting to read the response.
*/
public String readLine() {
- return readLine(System.in, System.err);
+ return readLine(in, err);
}
/**
@@ -367,7 +397,7 @@
* <CODE>false</CODE> otherwise.
*/
protected boolean isInteractive() {
- return interactiveArg != null && interactiveArg.isPresent();
+ return noPromptArg == null || !noPromptArg.isPresent();
}
/**
@@ -392,18 +422,19 @@
// Initialize all the common command-line argument types and register
// them with the parser.
try {
- interactiveArg =
- new BooleanArgument("noninteractive session",
- SecureConnectionCliParser.INTERACTIVE_OPTION_SHORT,
- SecureConnectionCliParser.INTERACTIVE_OPTION_LONG,
- null);
- argParser.addArgument(interactiveArg);
+ noPromptArg = new BooleanArgument(
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_SHORT,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ INFO_DESCRIPTION_NO_PROMPT.get());
+ argParser.addArgument(noPromptArg);
quietArg =
- new BooleanArgument("silent session",
- SecureConnectionCliParser.QUIET_OPTION_SHORT,
- SecureConnectionCliParser.QUIET_OPTION_LONG,
- null);
+ new BooleanArgument(
+ SecureConnectionCliParser.QUIET_OPTION_LONG,
+ SecureConnectionCliParser.QUIET_OPTION_SHORT,
+ SecureConnectionCliParser.QUIET_OPTION_LONG,
+ INFO_DESCRIPTION_QUIET.get());
argParser.addArgument(quietArg);
} catch (ArgumentException e) {
@@ -420,7 +451,7 @@
*/
protected void printErrorMessage(Message msg)
{
- System.err.println(org.opends.server.util.StaticUtils.wrapText(msg,
+ err.println(org.opends.server.util.StaticUtils.wrapText(msg,
Utils.getCommandLineMaxLineWidth()));
}
@@ -430,7 +461,7 @@
*/
protected void printErrorMessage(String msg)
{
- System.err.println(org.opends.server.util.StaticUtils.wrapText(msg,
+ err.println(org.opends.server.util.StaticUtils.wrapText(msg,
Utils.getCommandLineMaxLineWidth()));
}
@@ -439,7 +470,7 @@
*/
protected void printLineBreak()
{
- System.out.println();
+ out.println();
}
/**
@@ -511,6 +542,50 @@
}
/**
+ * Returns an InitialLdapContext using the provided parameters. We try
+ * to guarantee that the connection is able to read the configuration.
+ * @param host the host name.
+ * @param port the port to connect.
+ * @param useSSL whether to use SSL or not.
+ * @param useStartTLS whether to use StartTLS or not.
+ * @param bindDn the bind dn to be used.
+ * @param pwd the password.
+ * @param trustManager the trust manager.
+ * @return an InitialLdapContext connected.
+ * @throws NamingException if there was an error establishing the connection.
+ */
+ protected InitialLdapContext createContext(String host, int port,
+ boolean useSSL, boolean useStartTLS, String bindDn, String pwd,
+ ApplicationTrustManager trustManager)
+ throws NamingException
+ {
+ InitialLdapContext ctx;
+ String ldapUrl = ConnectionUtils.getLDAPUrl(host, port, useSSL);
+ if (useSSL)
+ {
+ ctx = Utils.createLdapsContext(ldapUrl, bindDn, pwd,
+ Utils.getDefaultLDAPTimeout(), null, trustManager);
+ }
+ else if (useStartTLS)
+ {
+ ctx = Utils.createStartTLSContext(ldapUrl, bindDn, pwd,
+ Utils.getDefaultLDAPTimeout(), null, trustManager,
+ null);
+ }
+ else
+ {
+ ctx = Utils.createLdapContext(ldapUrl, bindDn, pwd,
+ Utils.getDefaultLDAPTimeout(), null);
+ }
+ if (!ConnectionUtils.connectedAsAdministrativeUser(ctx))
+ {
+ throw new NoPermissionException(
+ ERR_NOT_ADMINISTRATIVE_USER.get().toString());
+ }
+ return ctx;
+ }
+
+ /**
* Prompts the user to accept the certificate.
* @param t the throwable that was generated because the certificate was
* not trusted.
@@ -539,7 +614,7 @@
}
else
{
- System.err.println();
+ err.println();
Message msg = Utils.getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(),
t);
printErrorMessage(msg);
@@ -705,10 +780,10 @@
};
for (int j=0; j<labels.length; j++)
{
- System.out.println(StaticUtils.wrapText(labels[j]+" "+values[j],
+ out.println(StaticUtils.wrapText(labels[j]+" "+values[j],
Utils.getCommandLineMaxLineWidth()));
}
}
- System.out.flush();
+ out.flush();
}
}
diff --git a/opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java b/opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java
index 544b0a0..7a4ae7c 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java
@@ -43,18 +43,11 @@
*/
public class CliUserInteraction extends CliApplicationHelper
implements UserInteraction {
-
- private PrintStream out;
- private PrintStream err;
- private InputStream in;
-
/**
* Creates an instance that will use standard streams for interaction.
*/
public CliUserInteraction() {
- this.out = System.out;
- this.err = System.err;
- this.in = System.in;
+ super(System.out, System.err, System.in);
}
/**
@@ -64,9 +57,7 @@
* @param in InputStream from which information will be read
*/
public CliUserInteraction(PrintStream out, PrintStream err, InputStream in) {
- this.out = out;
- this.err = err;
- this.in = in;
+ super(out, err, in);
}
/**
diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
index cb469a9..b9afe53 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
@@ -179,7 +179,7 @@
BooleanArgument showUsage;
FileBasedArgument file;
BooleanArgument quiet;
- BooleanArgument interactive;
+ BooleanArgument noPrompt;
try
{
file = new FileBasedArgument(
@@ -190,12 +190,12 @@
"{file}",
null, null, INFO_UPGRADE_DESCRIPTION_FILE.get());
argParser.addArgument(file);
- interactive = new BooleanArgument(
- SecureConnectionCliParser.INTERACTIVE_OPTION_LONG,
- SecureConnectionCliParser.INTERACTIVE_OPTION_SHORT,
- SecureConnectionCliParser.INTERACTIVE_OPTION_LONG,
- INFO_UPGRADE_DESCRIPTION_INTERACTIVE.get());
- argParser.addArgument(interactive);
+ noPrompt = new BooleanArgument(
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_SHORT,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ INFO_UPGRADE_DESCRIPTION_NO_PROMPT.get());
+ argParser.addArgument(noPrompt);
quiet = new BooleanArgument(
SecureConnectionCliParser.QUIET_OPTION_LONG,
SecureConnectionCliParser.QUIET_OPTION_SHORT,
diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java
index da46a78..1949ac8 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java
@@ -50,6 +50,14 @@
StringArgument localInstallPackFileNameArg = null;
/**
+ * Default constructor.
+ */
+ public UpgraderCliHelper()
+ {
+ super(System.out, System.err, System.in);
+ }
+
+ /**
* Creates a set of user data from command line arguments and installation
* status.
* @param args String[] of arguments passed in from the command line
diff --git a/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliParser.java b/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliParser.java
index 8984214..ed34041 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliParser.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliParser.java
@@ -247,7 +247,7 @@
return null;
}
}
- else if (startTLS())
+ else if (useStartTLS())
{
String ldapUrl = "ldap://" + host + ":" + port;
try
diff --git a/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliReturnCode.java b/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliReturnCode.java
index 386ba31..1e9c981 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliReturnCode.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliReturnCode.java
@@ -57,7 +57,7 @@
CANNOT_INITIALIZE_ARGS(1, ERR_ADMIN_NO_MESSAGE.get()),
/**
- * Cannot parse argument.
+ * Cannot parse arguments.
*/
ERROR_PARSING_ARGS(2, ERR_ADMIN_NO_MESSAGE.get()),
/**
diff --git a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index d2acf17..83e2bb1 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -161,14 +161,17 @@
*/
protected BooleanArgument useStartTLSArg = null;
+ // the trust manager.
+ private ApplicationTrustManager trustManager;
+
/** Short form of the option for specifying a noninteractive session. */
- static public final Character INTERACTIVE_OPTION_SHORT = 'i';
+ static public final Character NO_PROMPT_OPTION_SHORT = 'n';
/** Long form of the option for specifying a quiet session. */
static public final String QUIET_OPTION_LONG = "quiet";
/** Long form of the option for specifying a noninteractive session. */
- static public final String INTERACTIVE_OPTION_LONG = "interactive";
+ static public final String NO_PROMPT_OPTION_LONG = "no-prompt";
/** Short form of the option for specifying a quiet session. */
static public final Character QUIET_OPTION_SHORT = 'Q';
@@ -258,6 +261,7 @@
try
{
out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).getBytes());
+ out.flush();
char[] pwChars = PasswordReader.readPassword();
bindPasswordValue = new String(pwChars);
} catch(Exception ex)
@@ -289,8 +293,8 @@
// read the password from the stdin.
try
{
- out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString()
- .getBytes());
+ out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
+ out.flush();
char[] pwChars = PasswordReader.readPassword();
return new String(pwChars);
}
@@ -664,7 +668,7 @@
*
* @return True if startTLS mode is required
*/
- public boolean startTLS()
+ public boolean useStartTLS()
{
if (useStartTLSArg.isPresent())
{
@@ -683,78 +687,83 @@
*/
public ApplicationTrustManager getTrustManager()
{
- ApplicationTrustManager truststoreManager = null ;
- KeyStore truststore = null ;
- if (trustAllArg.isPresent())
+ if (trustManager == null)
{
- // Running a null TrustManager will force createLdapsContext and
- // createStartTLSContext to use a bindTrustManager.
- return null ;
- }
- else
- if (trustStorePathArg.isPresent())
- {
- try
+ KeyStore truststore = null ;
+ if (trustAllArg.isPresent())
{
- FileInputStream fos = new FileInputStream(trustStorePathArg.getValue());
- String trustStorePasswordStringValue = null;
- char[] trustStorePasswordValue = null;
- if (trustStorePasswordArg.isPresent())
+ // Running a null TrustManager will force createLdapsContext and
+ // createStartTLSContext to use a bindTrustManager.
+ return null ;
+ }
+ else
+ if (trustStorePathArg.isPresent())
{
- trustStorePasswordStringValue = trustStorePasswordArg.getValue();
- }
- else if (trustStorePasswordFileArg.isPresent())
- {
- trustStorePasswordStringValue = trustStorePasswordFileArg.getValue();
- }
+ try
+ {
+ FileInputStream fos =
+ new FileInputStream(trustStorePathArg.getValue());
+ String trustStorePasswordStringValue = null;
+ char[] trustStorePasswordValue = null;
+ if (trustStorePasswordArg.isPresent())
+ {
+ trustStorePasswordStringValue = trustStorePasswordArg.getValue();
+ }
+ else if (trustStorePasswordFileArg.isPresent())
+ {
+ trustStorePasswordStringValue =
+ trustStorePasswordFileArg.getValue();
+ }
- if (trustStorePasswordStringValue != null)
- {
- trustStorePasswordStringValue = System
+ if (trustStorePasswordStringValue != null)
+ {
+ trustStorePasswordStringValue = System
.getProperty("javax.net.ssl.trustStorePassword");
+ }
+
+
+ if (trustStorePasswordStringValue != null)
+ {
+ trustStorePasswordValue =
+ trustStorePasswordStringValue.toCharArray();
+ }
+
+ truststore = KeyStore.getInstance(KeyStore.getDefaultType());
+ truststore.load(fos, trustStorePasswordValue);
+ fos.close();
+ }
+ catch (KeyStoreException e)
+ {
+ // Nothing to do: if this occurs we will systematically refuse the
+ // certificates. Maybe we should avoid this and be strict, but we
+ // are in a best effort mode.
+ LOG.log(Level.WARNING, "Error with the truststore", e);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ // Nothing to do: if this occurs we will systematically refuse the
+ // certificates. Maybe we should avoid this and be strict, but we
+ // are in a best effort mode.
+ LOG.log(Level.WARNING, "Error with the truststore", e);
+ }
+ catch (CertificateException e)
+ {
+ // Nothing to do: if this occurs we will systematically refuse the
+ // certificates. Maybe we should avoid this and be strict, but we
+ // are in a best effort mode.
+ LOG.log(Level.WARNING, "Error with the truststore", e);
+ }
+ catch (IOException e)
+ {
+ // Nothing to do: if this occurs we will systematically refuse the
+ // certificates. Maybe we should avoid this and be strict, but we
+ // are in a best effort mode.
+ LOG.log(Level.WARNING, "Error with the truststore", e);
+ }
}
-
-
- if (trustStorePasswordStringValue != null)
- {
- trustStorePasswordValue = trustStorePasswordStringValue.toCharArray();
- }
-
- truststore = KeyStore.getInstance(KeyStore.getDefaultType());
- truststore.load(fos, trustStorePasswordValue);
- fos.close();
- }
- catch (KeyStoreException e)
- {
- // Nothing to do: if this occurs we will systematically refuse the
- // certificates. Maybe we should avoid this and be strict, but we are
- // in a best effort mode.
- LOG.log(Level.WARNING, "Error with the truststore", e);
- }
- catch (NoSuchAlgorithmException e)
- {
- // Nothing to do: if this occurs we will systematically refuse the
- // certificates. Maybe we should avoid this and be strict, but we are
- // in a best effort mode.
- LOG.log(Level.WARNING, "Error with the truststore", e);
- }
- catch (CertificateException e)
- {
- // Nothing to do: if this occurs we will systematically refuse the
- // certificates. Maybe we should avoid this and be strict, but we are
- // in a best effort mode.
- LOG.log(Level.WARNING, "Error with the truststore", e);
- }
- catch (IOException e)
- {
- // Nothing to do: if this occurs we will systematically refuse the
- // certificates. Maybe we should avoid this and be strict, but we are
- // in a best effort mode.
- LOG.log(Level.WARNING, "Error with the truststore", e);
- }
+ trustManager = new ApplicationTrustManager(truststore);
}
- truststoreManager = new ApplicationTrustManager(truststore);
- return truststoreManager;
+ return trustManager;
}
/**
diff --git a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
index a9c7db7..6b452e6 100644
--- a/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
+++ b/opends/src/server/org/opends/server/tools/dsconfig/DSConfig.java
@@ -51,6 +51,7 @@
import org.opends.server.admin.Tag;
import org.opends.server.admin.client.ManagedObjectDecodingException;
import org.opends.server.admin.client.ManagementContext;
+import org.opends.server.admin.client.cli.SecureConnectionCliParser;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.tools.ClientException;
import org.opends.server.types.DebugLogLevel;
@@ -150,9 +151,9 @@
private final Map<SubCommand, SubCommandHandler> handlers =
new HashMap<SubCommand, SubCommandHandler>();
- // The argument which should be used to request interactive
+ // The argument which should be used to request non interactive
// behavior.
- private BooleanArgument interactiveArgument;
+ private BooleanArgument noPromptArgument;
// The command-line argument parser.
private final SubCommandArgumentParser parser;
@@ -231,7 +232,7 @@
* {@inheritDoc}
*/
public boolean isInteractive() {
- return interactiveArgument.isPresent();
+ return !noPromptArgument.isPresent();
}
@@ -293,14 +294,20 @@
verboseArgument = new BooleanArgument("verbose", 'v', "verbose",
INFO_DESCRIPTION_VERBOSE.get());
- quietArgument = new BooleanArgument("quiet", 'Q', "quiet",
+ quietArgument = new BooleanArgument(
+ SecureConnectionCliParser.QUIET_OPTION_LONG,
+ SecureConnectionCliParser.QUIET_OPTION_SHORT,
+ SecureConnectionCliParser.QUIET_OPTION_LONG,
INFO_DESCRIPTION_QUIET.get());
scriptFriendlyArgument = new BooleanArgument("script-friendly", 's',
"script-friendly", INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
- interactiveArgument = new BooleanArgument("interactive", 'i',
- "interactive", INFO_DESCRIPTION_INTERACTIVE.get());
+ noPromptArgument = new BooleanArgument(
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_SHORT,
+ SecureConnectionCliParser.NO_PROMPT_OPTION_LONG,
+ INFO_DESCRIPTION_NO_PROMPT.get());
showUsageArgument = new BooleanArgument("showUsage", OPTION_SHORT_HELP,
OPTION_LONG_HELP,
@@ -312,7 +319,7 @@
parser.addGlobalArgument(verboseArgument);
parser.addGlobalArgument(quietArgument);
parser.addGlobalArgument(scriptFriendlyArgument);
- parser.addGlobalArgument(interactiveArgument);
+ parser.addGlobalArgument(noPromptArgument);
// Register any global arguments required by the management
// context factory.
@@ -443,10 +450,10 @@
return 1;
}
- if (quietArgument.isPresent() && interactiveArgument.isPresent()) {
- Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+ if (quietArgument.isPresent() && !noPromptArgument.isPresent()) {
+ Message message = ERR_DSCFG_ERROR_QUIET_AND_INTERACTIVE_INCOMPATIBLE.get(
quietArgument.getLongIdentifier(),
- interactiveArgument.getLongIdentifier());
+ noPromptArgument.getLongIdentifier());
displayMessageAndUsageReference(message);
return 1;
}
--
Gitblit v1.10.0