From 2302060670eb0dc1712249c1eccc54683e63bb8c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 13 Nov 2007 01:46:38 +0000
Subject: [PATCH] Remove some unused methods. Fix a bug in the uninstall and dsreplication. When the user connected to the servers using LDAP, a null trust manager was used to load the topology (so all certificates were accepted). The code has been fixed to prompt the user to accept non trusted certificates.
---
opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java | 192 +++++++++---------------------------------------
1 files changed, 36 insertions(+), 156 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index 5c82604..7603fcb 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -112,9 +112,6 @@
import org.opends.server.util.cli.CLIException;
import org.opends.server.util.cli.ConsoleApplication;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
-import org.opends.server.util.cli.Menu;
-import org.opends.server.util.cli.MenuBuilder;
-import org.opends.server.util.cli.MenuResult;
import org.opends.server.util.table.TableBuilder;
import org.opends.server.util.table.TextTablePrinter;
@@ -137,6 +134,8 @@
/** Suffix for log files. */
static public final String LOG_FILE_SUFFIX = ".log";
+ private boolean forceNonInteractive;
+
private static final Logger LOG =
Logger.getLogger(ReplicationCliMain.class.getName());
@@ -1930,6 +1929,13 @@
int port = ConnectionUtils.getPort(ctx[0]);
boolean isSSL = ConnectionUtils.isSSL(ctx[0]);
boolean isStartTLS = ConnectionUtils.isStartTLS(ctx[0]);
+ if (getTrustManager() == null)
+ {
+ // This is required when the user did connect to the server using SSL or
+ // Start TLS. In this case LDAPConnectionInteraction.run does not
+ // initialize the keystore and the trust manager is null.
+ forceTrustManagerInitialization();
+ }
try
{
ADSContext adsContext = new ADSContext(ctx[0]);
@@ -5806,11 +5812,16 @@
* {@inheritDoc}
*/
public boolean isInteractive() {
- return argParser.isInteractive();
+ if (forceNonInteractive)
+ {
+ return false;
+ }
+ else
+ {
+ return argParser.isInteractive();
+ }
}
-
-
/**
* {@inheritDoc}
*/
@@ -5846,27 +5857,6 @@
}
/**
- * Prompts the user to give a value.
- * @param defaultValue the default value that will be proposed in the prompt
- * message.
- * @return the String as provided by the user or the defaultValue if an error.
- * occurred reading the input.
- */
- private String promptForString(Message prompt, String defaultValue)
- {
- String s = defaultValue;
- try
- {
- s = readInput(prompt, defaultValue);
- }
- catch (CLIException ce)
- {
- LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
- }
- return s;
- }
-
- /**
* Commodity method used to repeatidly ask the user to provide a port value.
* @param prompt the prompt message.
* @param defaultValue the default value of the port to be proposed to the
@@ -5935,135 +5925,6 @@
}
/**
- * Enumeration description protocols for interactive CLI choices.
- */
- private enum Protocols
- {
- LDAP(1, INFO_LDAP_CONN_PROMPT_SECURITY_LDAP.get()), SSL(2,
- INFO_LDAP_CONN_PROMPT_SECURITY_USE_SSL.get()), START_TLS(3,
- INFO_LDAP_CONN_PROMPT_SECURITY_USE_START_TLS.get());
-
- private Integer choice;
-
- private Message msg;
-
- /**
- * Private constructor.
- *
- * @param i
- * the menu return value.
- * @param msg
- * the message message.
- */
- private Protocols(int i, Message msg)
- {
- choice = i;
- this.msg = msg;
- }
-
- /**
- * Returns the choice number.
- *
- * @return the attribute name.
- */
- public Integer getChoice()
- {
- return choice;
- }
-
- /**
- * Return the menu message.
- *
- * @return the menu message.
- */
- public Message getMenuMessage()
- {
- return msg;
- }
- }
-
- private Protocols askProtocol(Message prompt, boolean isSecure,
- boolean isStartTLS)
- {
- Protocols protocol;
- MenuBuilder<Integer> builder = new MenuBuilder<Integer>(this);
- builder.setPrompt(prompt);
-
- Protocols defaultProtocol = Protocols.LDAP;
- if (isSecure)
- {
- defaultProtocol = Protocols.SSL;
- }
- else if (isStartTLS)
- {
- defaultProtocol = Protocols.START_TLS;
- }
- for (Protocols p : Protocols.values())
- {
- int i = builder.addNumberedOption(p.getMenuMessage(), MenuResult
- .success(p.getChoice()));
- if (p.equals(defaultProtocol))
- {
- builder.setDefault(
- INFO_LDAP_CONN_PROMPT_SECURITY_PROTOCOL_DEFAULT_CHOICE
- .get(i), MenuResult.success(p.getChoice()));
- }
- }
-
- Menu<Integer> menu = builder.toMenu();
- try
- {
- MenuResult<Integer> result = menu.run();
- if (result.isSuccess())
- {
- if (result.getValue().equals(Protocols.SSL.getChoice()))
- {
- protocol = Protocols.SSL;
- }
- else if (result.getValue()
- .equals(Protocols.START_TLS.getChoice()))
- {
- protocol = Protocols.START_TLS;
- }
- else
- {
- protocol = Protocols.LDAP;
- }
- }
- else
- {
- // Should never happen.
- throw new RuntimeException();
- }
- }
- catch (CLIException e)
- {
- throw new RuntimeException(e);
- }
- return protocol;
- }
-
- /**
- * Displays the provided header if is was not already displayed. This method
- * just is used for refactoring this small bit of code.
- * @param msg the heading to be displayed.
- * @param wasDisplayed whether this heading was already displayed or not.
- * @return <CODE>true</CODE> if the message was displayed and
- * <CODE>false</CODE> otherwise.
- */
- private boolean checkHeadingDisplay(Message msg, boolean wasDisplayed)
- {
- if (!wasDisplayed)
- {
- println(msg);
- println();
- println();
- }
- wasDisplayed = true;
- return wasDisplayed;
- }
-
- /**
* Resets the connection parameters for the LDAPConsoleInteraction object.
* The reset does not apply to the certificate parameters. This is called
* in order the LDAPConnectionConsoleInteraction object to ask for all this
@@ -6132,4 +5993,23 @@
argParser.getSecureArgsList().bindPasswordArg.setPresent(true);
}
}
+
+
+ /**
+ * Forces the initialization of the trust manager in the
+ * LDAPConnectionInteraction object.
+ */
+ private void forceTrustManagerInitialization()
+ {
+ forceNonInteractive = true;
+ try
+ {
+ ci.initializeTrustManagerIfRequired();
+ }
+ catch (ArgumentException ae)
+ {
+ LOG.log(Level.WARNING, "Error initializing trust store: "+ae, ae);
+ }
+ forceNonInteractive = false;
+ }
}
--
Gitblit v1.10.0