From 68d1cc39007696bf12d0844eba88ea7ac81d8786 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 29 Aug 2007 11:50:00 +0000
Subject: [PATCH] Improve the status command-line interaction by asking the user for the BIndDN to use when this was not provided. Before asking to use SSL or startTLS check that they can actually be used.
---
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java | 46 ++++++++++++++++++++---
opends/src/server/org/opends/server/tools/ToolConstants.java | 12 ++++++
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java | 11 +++--
3 files changed, 58 insertions(+), 11 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
index 4a02cfd..6f0f360 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -137,7 +137,7 @@
static private final Logger LOG = Logger.getLogger(StatusCli.class.getName());
// The argument parser
- private StatusCliParser argParser;
+ private StatusCliArgumentParser argParser;
/**
* Constructor for the StatusCli object.
@@ -169,7 +169,7 @@
/**
* Parses the provided command-line arguments and uses that information to
- * run the replication tool.
+ * run the status tool.
*
* @param args the command-line arguments provided to this program.
*
@@ -183,7 +183,7 @@
/**
* Parses the provided command-line arguments and uses that information to
- * run the replication tool.
+ * run the status tool.
*
* @param args The command-line arguments provided to this
* program.
@@ -252,7 +252,7 @@
DirectoryServer.bootstrapClient();
}
- argParser = new StatusCliParser(StatusCli.class.getName());
+ argParser = new StatusCliArgumentParser(StatusCli.class.getName());
try
{
argParser.initializeGlobalArguments(err);
@@ -300,12 +300,11 @@
*/
ConfigFromFile offLineConf = new ConfigFromFile();
offLineConf.readConfiguration();
-
try
{
if (isServerRunning)
{
- String bindDn = argParser.getBindDN();
+ String bindDn;
String bindPwd;
boolean useSSL = argParser.useSSL();
boolean useStartTLS = argParser.useStartTLS();
@@ -313,17 +312,48 @@
{
boolean connected = false;
boolean cancelled = false;
+ boolean prompted = false;
+ boolean canUseSSL = offLineConf.getLDAPSURL() != null;
+ boolean canUseStartTLS = offLineConf.getStartTLSURL() != null;
+
+ bindDn = argParser.getExplicitBindDn();
bindPwd = argParser.getBindPassword();
+ if (bindDn == null)
+ {
+ bindDn = promptForString(
+ INFO_CLI_BINDDN_PROMPT.get(), argParser.getDefaultBindDn());
+ prompted = true;
+ }
if (bindPwd == null)
{
bindPwd = promptForPassword(
INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn));
+ prompted = true;
+ }
+
+ if (!useSSL && !useStartTLS)
+ {
+ if (canUseSSL)
+ {
+ useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
+ }
+ if (!useSSL && canUseStartTLS)
+ {
+ useStartTLS =
+ confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
+ }
+ prompted = true;
}
InitialLdapContext ctx = null;
while (!connected && !cancelled)
{
+ if (prompted)
+ {
+ printLineBreak();
+ }
+
String host = "localhost";
int port = 389;
try
@@ -355,6 +385,7 @@
useStartTLS =
confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
}
+ prompted = true;
}
catch (NamingException ne)
{
@@ -369,6 +400,7 @@
{
cancelled = true;
}
+ prompted = true;
}
else
{
@@ -392,6 +424,7 @@
useStartTLS =
confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
}
+ prompted = true;
}
}
}
@@ -412,6 +445,7 @@
}
else
{
+ bindDn = argParser.getBindDN();
bindPwd = argParser.getBindPassword();
if (bindDn == null)
diff --git a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
similarity index 92%
rename from opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java
rename to opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
index 2cacc19..ee8e7f2 100644
--- a/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliParser.java
+++ b/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -34,6 +34,7 @@
import java.util.ArrayList;
import org.opends.server.admin.client.cli.SecureConnectionCliParser;
+import org.opends.server.tools.ToolConstants;
import org.opends.server.util.args.Argument;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.BooleanArgument;
@@ -43,7 +44,7 @@
* line.
*
*/
-public class StatusCliParser extends SecureConnectionCliParser
+public class StatusCliArgumentParser extends SecureConnectionCliParser
{
private BooleanArgument noPromptArg;
@@ -55,7 +56,7 @@
* be invoked to launch the program with which this
* argument parser is associated.
*/
- public StatusCliParser(String mainClassName)
+ public StatusCliArgumentParser(String mainClassName)
{
super(mainClassName, INFO_STATUS_CLI_USAGE_DESCRIPTION.get(), false);
}
@@ -78,9 +79,9 @@
defaultArgs.remove(hostNameArg);
defaultArgs.remove(verboseArg);
noPromptArg = new BooleanArgument(
- NO_PROMPT_OPTION_LONG,
- NO_PROMPT_OPTION_SHORT,
- NO_PROMPT_OPTION_LONG,
+ ToolConstants.OPTION_LONG_NO_PROMPT,
+ ToolConstants.OPTION_SHORT_NO_PROMPT,
+ ToolConstants.OPTION_LONG_NO_PROMPT,
INFO_DESCRIPTION_NO_PROMPT.get());
defaultArgs.add(0, noPromptArg);
initializeGlobalArguments(defaultArgs);
diff --git a/opends/src/server/org/opends/server/tools/ToolConstants.java b/opends/src/server/org/opends/server/tools/ToolConstants.java
index a161322..8375877 100644
--- a/opends/src/server/org/opends/server/tools/ToolConstants.java
+++ b/opends/src/server/org/opends/server/tools/ToolConstants.java
@@ -655,5 +655,17 @@
* Value for the quiet option long form.
*/
public static final String OPTION_LONG_QUIET = "quiet";
+
+ /**
+ * Value for noninteractive session short form.
+ */
+ public static final Character OPTION_SHORT_NO_PROMPT = 'n';
+
+ /**
+ * Value for noninteractive session long form.
+ */
+ public static final String OPTION_LONG_NO_PROMPT = "no-prompt";
+
+
}
--
Gitblit v1.10.0