From b9e7d96e98dda336fa97155085bd1740b1e8d18a Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Sun, 26 Jul 2009 22:25:18 +0000
Subject: [PATCH] dsreplication allowed an infinite number of password tries for the administrator. This is inconsistent with what is done elsewhere.
---
opends/src/ads/org/opends/admin/ads/TopologyCache.java | 9 ++
opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java | 22 +++++
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java | 33 ++++++++
opends/src/ads/org/opends/admin/ads/ServerDescriptor.java | 25 ++++++
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 104 +++++++++----------------
5 files changed, 126 insertions(+), 67 deletions(-)
diff --git a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index f5af8fe..fd33fe3 100644
--- a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@@ -432,6 +433,30 @@
}
/**
+ * Returns the list of enabled administration ports.
+ * @return the list of enabled administration ports.
+ */
+ public List<Integer> getEnabledAdministrationPorts()
+ {
+ List<Integer> ports = new ArrayList<Integer>(1);
+ ArrayList s = (ArrayList)serverProperties.get(
+ ServerProperty.ADMIN_ENABLED);
+ ArrayList p = (ArrayList)serverProperties.get(
+ ServerProperty.ADMIN_PORT);
+ if (s != null)
+ {
+ for (int i=0; i<s.size(); i++)
+ {
+ if (Boolean.TRUE.equals(s.get(i)))
+ {
+ ports.add((Integer)p.get(i));
+ }
+ }
+ }
+ return ports;
+ }
+
+ /**
* Returns a String of type host-name:port-number for the server. If
* the provided securePreferred is set to true the port that will be used
* will be the administration connector port.
diff --git a/opends/src/ads/org/opends/admin/ads/TopologyCache.java b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
index 7c5949b..3dc2954 100644
--- a/opends/src/ads/org/opends/admin/ads/TopologyCache.java
+++ b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
@@ -198,6 +198,15 @@
}
/**
+ * Returns the trust manager used by this class.
+ * @return the trust manager used by this class.
+ */
+ public ApplicationTrustManager getTrustManager()
+ {
+ return trustManager;
+ }
+
+ /**
* Reads the replication monitoring.
* @throws NamingException if an error occurs reading the replication
* monitoring.
diff --git a/opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java b/opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java
index 5b8b5ed..f856354 100644
--- a/opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java
+++ b/opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java
@@ -22,11 +22,13 @@
* CDDL HEADER END
*
*
- * Copyright 2008 Sun Microsystems, Inc.
+ * Copyright 2008-2009 Sun Microsystems, Inc.
*/
package org.opends.admin.ads.util;
+import java.util.LinkedHashSet;
+
import javax.naming.ldap.InitialLdapContext;
/**
@@ -144,4 +146,22 @@
PreferredConnection cnx = new PreferredConnection(ldapUrl, type);
return cnx;
}
+
+
+
+ /**
+ * Commodity method that generates a list of preferred connection (of just
+ * one) with the information on a given InitialLdapContext.
+ * @param ctx the connection we retrieve the inforamtion from.
+ * @return a list containing the preferred connection object.
+ */
+ public static LinkedHashSet<PreferredConnection> getPreferredConnections(
+ InitialLdapContext ctx)
+ {
+ PreferredConnection cnx = PreferredConnection.getPreferredConnection(ctx);
+ LinkedHashSet<PreferredConnection> returnValue =
+ new LinkedHashSet<PreferredConnection>();
+ returnValue.add(cnx);
+ return returnValue;
+ }
}
diff --git a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 88230d8..10f2622 100644
--- a/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -33,6 +33,8 @@
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import static org.opends.messages.ToolMessages.*;
+import static org.opends.messages.UtilityMessages.
+ ERR_CONFIRMATION_TRIES_LIMIT_REACHED;
import static org.opends.quicksetup.util.Utils.getFirstValue;
import static org.opends.quicksetup.util.Utils.getThrowableMsg;
import static org.opends.server.tools.ToolConstants.*;
@@ -1353,7 +1355,7 @@
println(INFO_REPLICATION_ENABLE_ADMINISTRATOR_MUST_BE_CREATED.get());
promptedForAdmin = true;
adminUid= askForAdministratorUID(
- argParser.getDefaultAdministratorUID());
+ argParser.getDefaultAdministratorUID(), LOG);
println();
}
uData.setAdminUid(adminUid);
@@ -1366,8 +1368,17 @@
if (!cancelled && (uData.getAdminPwd() == null) && !administratorDefined)
{
adminPwd = null;
+ int nPasswordPrompts = 0;
while (adminPwd == null)
{
+ if (nPasswordPrompts > CONFIRMATION_MAX_TRIES)
+ {
+ println(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get(
+ CONFIRMATION_MAX_TRIES));
+ cancelled = true;
+ break;
+ }
+ nPasswordPrompts ++;
if (!promptedForAdmin)
{
println();
@@ -1376,7 +1387,7 @@
}
while (adminPwd == null)
{
- adminPwd = askForAdministratorPwd();
+ adminPwd = askForAdministratorPwd(LOG);
println();
}
String adminPwdConfirm = null;
@@ -2813,7 +2824,8 @@
getTrustManager());
cache.getFilter().setSearchMonitoringInformation(false);
cache.getFilter().setSearchBaseDNInformation(false);
- cache.setPreferredConnections(getPreferredConnections(ctx[0]));
+ cache.setPreferredConnections(
+ PreferredConnection.getPreferredConnections(ctx[0]));
cache.reloadTopology();
reloadTopology = false;
@@ -2872,9 +2884,9 @@
errorDisplayed = true;
}
adminUid = askForAdministratorUID(
- argParser.getDefaultAdministratorUID());
+ argParser.getDefaultAdministratorUID(), LOG);
println();
- adminPwd = askForAdministratorPwd();
+ adminPwd = askForAdministratorPwd(LOG);
println();
}
try
@@ -2894,7 +2906,7 @@
cache.getFilter().setSearchMonitoringInformation(false);
cache.getFilter().setSearchBaseDNInformation(false);
cache.setPreferredConnections(
- getPreferredConnections(ctx[0]));
+ PreferredConnection.getPreferredConnections(ctx[0]));
connected = true;
}
catch (Throwable t)
@@ -4909,8 +4921,8 @@
{
LinkedHashSet<PreferredConnection> cnx =
new LinkedHashSet<PreferredConnection>();
- cnx.addAll(getPreferredConnections(ctx1));
- cnx.addAll(getPreferredConnections(ctx2));
+ cnx.addAll(PreferredConnection.getPreferredConnections(ctx1));
+ cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
if (adsCtx1.hasAdminData())
{
TopologyCache cache = new TopologyCache(adsCtx1, getTrustManager());
@@ -5227,8 +5239,8 @@
{
LinkedHashSet<PreferredConnection> cnx =
new LinkedHashSet<PreferredConnection>();
- cnx.addAll(getPreferredConnections(ctx1));
- cnx.addAll(getPreferredConnections(ctx2));
+ cnx.addAll(PreferredConnection.getPreferredConnections(ctx1));
+ cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
if (adsCtx1.hasAdminData())
{
cache1 = new TopologyCache(adsCtx1, getTrustManager());
@@ -5590,7 +5602,8 @@
if (adsCtx.hasAdminData() && tryToUpdateRemote)
{
cache = new TopologyCache(adsCtx, getTrustManager());
- cache.setPreferredConnections(getPreferredConnections(ctx));
+ cache.setPreferredConnections(
+ PreferredConnection.getPreferredConnections(ctx));
cache.getFilter().setSearchMonitoringInformation(false);
for (String dn : uData.getBaseDNs())
{
@@ -5993,7 +6006,7 @@
{
removeReferencesInServer(s, replicationServerHostPort, bindDn, pwd,
baseDNsToUpdate, disableReplicationServer,
- getPreferredConnections(ctx));
+ PreferredConnection.getPreferredConnections(ctx));
}
if (disableReplicationServer)
@@ -6108,7 +6121,8 @@
try
{
cache = new TopologyCache(adsCtx, getTrustManager());
- cache.setPreferredConnections(getPreferredConnections(ctx));
+ cache.setPreferredConnections(
+ PreferredConnection.getPreferredConnections(ctx));
for (String dn : uData.getBaseDNs())
{
cache.getFilter().addBaseDNToSearch(dn);
@@ -6235,7 +6249,7 @@
if (!rServers.isEmpty())
{
displayStatus(rServers, uData.isScriptFriendly(),
- getPreferredConnections(ctx));
+ PreferredConnection.getPreferredConnections(ctx));
somethingDisplayed = true;
}
}
@@ -6272,7 +6286,8 @@
{
printlnProgress();
displayStatus(replicas, uData.isScriptFriendly(),
- getPreferredConnections(ctx), cache.getServers(),
+ PreferredConnection.getPreferredConnections(ctx),
+ cache.getServers(),
replicasWithNoReplicationServer, serversWithNoReplica);
somethingDisplayed = true;
}
@@ -7046,7 +7061,6 @@
}
else if (!areReplicationServersEqual(servers, replicationServers))
{
- replicationServers.addAll(servers);
replicationServer.setReplicationServer(
mergeReplicationServers(replicationServers, servers));
mustCommit = true;
@@ -8553,36 +8567,6 @@
}
/**
- * Prompts the user to give the Global Administrator UID.
- * @param defaultValue the default value that will be proposed in the prompt
- * message.
- * @return the Global Administrator UID as provided by the user.
- */
- private String askForAdministratorUID(String defaultValue)
- {
- String s = defaultValue;
- try
- {
- s = readInput(INFO_ADMINISTRATOR_UID_PROMPT.get(), defaultValue);
- }
- catch (CLIException ce)
- {
- LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
- }
- return s;
- }
-
- /**
- * Prompts the user to give the Global Administrator password.
- * @return the Global Administrator password as provided by the user.
- */
- private String askForAdministratorPwd()
- {
- String pwd = readPassword(INFO_ADMINISTRATOR_PWD_PROMPT.get(), LOG);
- return pwd;
- }
-
- /**
* Prints a message to the output with no wrapping if we are not in quiet
* mode.
* @param msg the message to be displayed.
@@ -8758,22 +8742,6 @@
}
/**
- * Commodity method that generates a list of preferred connection (of just
- * one) with the information on a given InitialLdapContext.
- * @param ctx the connection we retrieve the inforamtion from.
- * @return a list containing the preferred connection object.
- */
- private LinkedHashSet<PreferredConnection> getPreferredConnections(
- InitialLdapContext ctx)
- {
- PreferredConnection cnx = PreferredConnection.getPreferredConnection(ctx);
- LinkedHashSet<PreferredConnection> returnValue =
- new LinkedHashSet<PreferredConnection>();
- returnValue.add(cnx);
- return returnValue;
- }
-
- /**
* Returns the host port representation of the server to be used in progress,
* status and error messages. It takes into account the fact the host and
* port provided by the user.
@@ -9759,7 +9727,8 @@
{
cache1 = new TopologyCache(adsContext, getTrustManager());
cache1.getFilter().setSearchMonitoringInformation(false);
- cache1.setPreferredConnections(getPreferredConnections(ctx1));
+ cache1.setPreferredConnections(
+ PreferredConnection.getPreferredConnections(ctx1));
cache1.reloadTopology();
}
}
@@ -9779,7 +9748,8 @@
{
cache2 = new TopologyCache(adsContext, getTrustManager());
cache2.getFilter().setSearchMonitoringInformation(false);
- cache2.setPreferredConnections(getPreferredConnections(ctx2));
+ cache2.setPreferredConnections(
+ PreferredConnection.getPreferredConnections(ctx2));
cache2.reloadTopology();
}
}
@@ -10007,8 +9977,10 @@
{
LinkedHashSet<PreferredConnection> cnx =
new LinkedHashSet<PreferredConnection>();
- cnx.addAll(getPreferredConnections(adsCtx1.getDirContext()));
- cnx.addAll(getPreferredConnections(adsCtx2.getDirContext()));
+ cnx.addAll(PreferredConnection.getPreferredConnections(
+ adsCtx1.getDirContext()));
+ cnx.addAll(PreferredConnection.getPreferredConnections(
+ adsCtx2.getDirContext()));
// Check that there are no errors. We do not allow to do the merge with
// errors.
TopologyCache cache1 = new TopologyCache(adsCtx1, getTrustManager());
diff --git a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
index 1d149d9..901de32 100644
--- a/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
+++ b/opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -1111,6 +1111,39 @@
}
/**
+ * Prompts the user to give the Global Administrator UID.
+ * @param defaultValue the default value that will be proposed in the prompt
+ * message.
+ * @param logger the Logger to be used to log the error message.
+ * @return the Global Administrator UID as provided by the user.
+ */
+ protected String askForAdministratorUID(String defaultValue,
+ Logger logger)
+ {
+ String s = defaultValue;
+ try
+ {
+ s = readInput(INFO_ADMINISTRATOR_UID_PROMPT.get(), defaultValue);
+ }
+ catch (CLIException ce)
+ {
+ logger.log(Level.WARNING, "Error reading input: "+ce, ce);
+ }
+ return s;
+ }
+
+ /**
+ * Prompts the user to give the Global Administrator password.
+ * @param logger the Logger to be used to log the error message.
+ * @return the Global Administrator password as provided by the user.
+ */
+ protected String askForAdministratorPwd(Logger logger)
+ {
+ String pwd = readPassword(INFO_ADMINISTRATOR_PWD_PROMPT.get(), logger);
+ return pwd;
+ }
+
+ /**
* The default period time used to write points in the output.
*/
protected static final long DEFAULT_PERIOD_TIME = 3000;
--
Gitblit v1.10.0