From a1869180d5499a5f0c3d69c84e6ed010a7015fa6 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 09 Apr 2009 08:27:35 +0000
Subject: [PATCH] Fix for issue 2017 (tools usage should disclose default value for options)

---
 opendj-sdk/opends/src/server/org/opends/server/tools/ManageTasks.java                                |   10 +
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java      |   11 +
 opendj-sdk/opends/src/server/org/opends/server/tools/ExportLDIF.java                                 |   10 +
 opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java           |   10 +
 opendj-sdk/opends/src/server/org/opends/server/tools/BackUpDB.java                                   |    9 +
 opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java |   21 +
 opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java        |  106 +----------
 opendj-sdk/opends/src/messages/messages/utility.properties                                           |    3 
 opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java         |  270 +++++++++++++++++++++++------
 opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java                           |   10 +
 opendj-sdk/opends/src/server/org/opends/server/tools/RestoreDB.java                                  |    9 +
 opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java                                 |    9 +
 opendj-sdk/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java               |   18 +
 opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java                         |   11 +
 14 files changed, 347 insertions(+), 160 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/utility.properties b/opendj-sdk/opends/src/messages/messages/utility.properties
index c55c1d2..741c78e 100644
--- a/opendj-sdk/opends/src/messages/messages/utility.properties
+++ b/opendj-sdk/opends/src/messages/messages/utility.properties
@@ -20,7 +20,7 @@
 #
 # CDDL HEADER END
 #
-#      Copyright 2006-2008 Sun Microsystems, Inc.
+#      Copyright 2006-2009 Sun Microsystems, Inc.
 
 
 
@@ -615,3 +615,4 @@
 could not be located because of the following reason: %s
 SEVERE_ERR_CERTMGR_CERT_SIGN_REQ_NOT_SUPPORTED_298=Certificate signing \
 request generation is not supported on JVM supplied by this vendor: %s
+INFO_ARGPARSER_USAGE_DEFAULT_VALUE_299=Default value: %s
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index 77b1566..775eb4f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -59,6 +59,13 @@
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.quicksetup.Constants;
 import org.opends.server.admin.AdministrationConnector;
+import org.opends.server.admin.server.ServerManagementContext;
+import org.opends.server.admin.std.server.AdministrationConnectorCfg;
+import org.opends.server.admin.std.server.FileBasedTrustManagerProviderCfg;
+import org.opends.server.admin.std.server.RootCfg;
+import org.opends.server.admin.std.server.TrustManagerProviderCfg;
+import org.opends.server.config.ConfigException;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.loggers.debug.DebugTracer;
 import org.opends.server.types.DebugLogLevel;
 import org.opends.server.util.PasswordReader;
@@ -172,6 +179,8 @@
   // the trust manager.
   private ApplicationTrustManager trustManager;
 
+  private boolean configurationInitialized = false;
+
   /**
    * The tracer object for the debug logger.
    */
@@ -199,9 +208,9 @@
    */
   public SecureConnectionCliArgs(boolean alwaysSSL)
   {
-      if (alwaysSSL) {
-        this.alwaysSSL = true;
-      }
+    if (alwaysSSL) {
+      this.alwaysSSL = true;
+    }
   }
 
   /**
@@ -324,37 +333,38 @@
       return bindPasswordValue;
     }
     else
-    if (fileArg.isPresent())
-    {
-      return fileArg.getValue();
-    }
-    else
-    {
-      // read the password from the stdin.
-      try
+      if (fileArg.isPresent())
       {
-        out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
-        out.flush();
-        char[] pwChars = PasswordReader.readPassword();
-        return new String(pwChars);
+        return fileArg.getValue();
       }
-      catch (Exception ex)
+      else
       {
-        if (debugEnabled())
-        {
-          TRACER.debugCaught(DebugLogLevel.ERROR, ex);
-        }
+        // read the password from the stdin.
         try
         {
-          err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
-          err.write(EOL.getBytes());
+          out.write(
+              INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
+          out.flush();
+          char[] pwChars = PasswordReader.readPassword();
+          return new String(pwChars);
         }
-        catch (IOException e)
+        catch (Exception ex)
         {
+          if (debugEnabled())
+          {
+            TRACER.debugCaught(DebugLogLevel.ERROR, ex);
+          }
+          try
+          {
+            err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
+            err.write(EOL.getBytes());
+          }
+          catch (IOException e)
+          {
+          }
+          return null;
         }
-        return null;
       }
-    }
 
   }
 
@@ -397,14 +407,14 @@
       pwd = clearArg.getValue();
     }
     else
-    if (fileArg.isPresent())
-    {
-      pwd = fileArg.getValue();
-    }
-    else
-    {
-      pwd = null;
-    }
+      if (fileArg.isPresent())
+      {
+        pwd = fileArg.getValue();
+      }
+      else
+      {
+        pwd = null;
+      }
     return pwd;
   }
 
@@ -434,7 +444,7 @@
     argList = new LinkedHashSet<Argument>();
 
     useSSLArg = new BooleanArgument("useSSL", OPTION_SHORT_USE_SSL,
-      OPTION_LONG_USE_SSL, INFO_DESCRIPTION_USE_SSL.get());
+        OPTION_LONG_USE_SSL, INFO_DESCRIPTION_USE_SSL.get());
     useSSLArg.setPropertyName(OPTION_LONG_USE_SSL);
     if (!alwaysSSL) {
       argList.add(useSSLArg);
@@ -444,8 +454,8 @@
     }
 
     useStartTLSArg = new BooleanArgument("startTLS", OPTION_SHORT_START_TLS,
-      OPTION_LONG_START_TLS,
-      INFO_DESCRIPTION_START_TLS.get());
+        OPTION_LONG_START_TLS,
+        INFO_DESCRIPTION_START_TLS.get());
     useStartTLSArg.setPropertyName(OPTION_LONG_START_TLS);
     if (!alwaysSSL) {
       argList.add(useStartTLSArg);
@@ -455,7 +465,7 @@
     try {
       defaultHostName = InetAddress.getLocalHost().getHostName();
     } catch (Exception e) {
-       defaultHostName="Unknown (" + e + ")";
+      defaultHostName="Unknown (" + e + ")";
     }
     hostNameArg = new StringArgument("host", OPTION_SHORT_HOST,
         OPTION_LONG_HOST, false, false, true, INFO_HOST_PLACEHOLDER.get(),
@@ -508,11 +518,11 @@
     argList.add(bindPasswordFileArg);
 
     saslOptionArg = new StringArgument(
-            "sasloption", OPTION_SHORT_SASLOPTION,
-            OPTION_LONG_SASLOPTION, false,
-            true, true,
-            INFO_SASL_OPTION_PLACEHOLDER.get(), null, null,
-            INFO_LDAP_CONN_DESCRIPTION_SASLOPTIONS.get());
+        "sasloption", OPTION_SHORT_SASLOPTION,
+        OPTION_LONG_SASLOPTION, false,
+        true, true,
+        INFO_SASL_OPTION_PLACEHOLDER.get(), null, null,
+        INFO_LDAP_CONN_DESCRIPTION_SASLOPTIONS.get());
     saslOptionArg.setPropertyName(OPTION_LONG_SASLOPTION);
     argList.add(saslOptionArg);
 
@@ -622,8 +632,8 @@
     // Couldn't have at the same time bindPassword and bindPasswordFile
     if (bindPasswordArg.isPresent() && bindPasswordFileArg.isPresent()) {
       Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              bindPasswordArg.getLongIdentifier(),
-              bindPasswordFileArg.getLongIdentifier());
+          bindPasswordArg.getLongIdentifier(),
+          bindPasswordFileArg.getLongIdentifier());
       errors.add(message);
     }
 
@@ -631,30 +641,30 @@
     // trustStore related arg
     if (trustAllArg.isPresent() && trustStorePathArg.isPresent()) {
       Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              trustAllArg.getLongIdentifier(),
-              trustStorePathArg.getLongIdentifier());
+          trustAllArg.getLongIdentifier(),
+          trustStorePathArg.getLongIdentifier());
       errors.add(message);
     }
     if (trustAllArg.isPresent() && trustStorePasswordArg.isPresent()) {
       Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              trustAllArg.getLongIdentifier(),
-              trustStorePasswordArg.getLongIdentifier());
+          trustAllArg.getLongIdentifier(),
+          trustStorePasswordArg.getLongIdentifier());
       errors.add(message);
     }
     if (trustAllArg.isPresent() && trustStorePasswordFileArg.isPresent()) {
       Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              trustAllArg.getLongIdentifier(),
-              trustStorePasswordFileArg.getLongIdentifier());
+          trustAllArg.getLongIdentifier(),
+          trustStorePasswordFileArg.getLongIdentifier());
       errors.add(message);
     }
 
     // Couldn't have at the same time trustStorePasswordArg and
     // trustStorePasswordFileArg
     if (trustStorePasswordArg.isPresent()
-            && trustStorePasswordFileArg.isPresent()) {
+        && trustStorePasswordFileArg.isPresent()) {
       Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              trustStorePasswordArg.getLongIdentifier(),
-              trustStorePasswordFileArg.getLongIdentifier());
+          trustStorePasswordArg.getLongIdentifier(),
+          trustStorePasswordFileArg.getLongIdentifier());
       errors.add(message);
     }
 
@@ -682,15 +692,15 @@
       }
     }
 
-      // Couldn't have at the same time startTLSArg and
-      // useSSLArg
+    // Couldn't have at the same time startTLSArg and
+    // useSSLArg
     if (useStartTLSArg.isPresent()
-            && useSSLArg.isPresent()) {
-        Message message = ERR_TOOL_CONFLICTING_ARGS.get(
-              useStartTLSArg
-                      .getLongIdentifier(), useSSLArg.getLongIdentifier());
-        errors.add(message);
-      }
+        && useSSLArg.isPresent()) {
+      Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+          useStartTLSArg
+          .getLongIdentifier(), useSSLArg.getLongIdentifier());
+      errors.add(message);
+    }
     if (errors.size() > 0)
     {
       for (Message error : errors)
@@ -964,4 +974,142 @@
     }
     return canRead;
   }
+
+  /**
+   *  Returns the absolute path of the trust store file that appears on the
+   *  config.  Returns <CODE>null</CODE> if the trust store is not defined or
+   *  it does not exist.
+   *
+   *  @return the absolute path of the trust store file that appears on the
+   *  config.
+   *  @throws ConfigException if there is an error reading the configuration.
+   */
+  public String getTruststoreFileFromConfig() throws ConfigException
+  {
+    String truststoreFileAbsolute = null;
+    TrustManagerProviderCfg trustManagerCfg = null;
+    AdministrationConnectorCfg administrationConnectorCfg = null;
+
+    // Initialization for admin framework
+    if (!configurationInitialized) {
+      initializeConfiguration();
+    }
+    // Get the Directory Server configuration handler and use it.
+    RootCfg root =
+      ServerManagementContext.getInstance().getRootConfiguration();
+    administrationConnectorCfg = root.getAdministrationConnector();
+
+    String trustManagerStr =
+      administrationConnectorCfg.getTrustManagerProvider();
+    trustManagerCfg = root.getTrustManagerProvider(trustManagerStr);
+    if (trustManagerCfg instanceof FileBasedTrustManagerProviderCfg) {
+      FileBasedTrustManagerProviderCfg fileBasedTrustManagerCfg =
+        (FileBasedTrustManagerProviderCfg) trustManagerCfg;
+      String truststoreFile = fileBasedTrustManagerCfg.getTrustStoreFile();
+      // Check the file
+      if (truststoreFile.startsWith(File.separator)) {
+        truststoreFileAbsolute = truststoreFile;
+      } else {
+        truststoreFileAbsolute =
+          DirectoryServer.getInstanceRoot() + File.separator + truststoreFile;
+      }
+      File f = new File(truststoreFileAbsolute);
+      if (!f.exists() || !f.canRead() || f.isDirectory())
+      {
+        truststoreFileAbsolute = null;
+      }
+      else
+      {
+        // Try to get the canonical path.
+        try
+        {
+          truststoreFileAbsolute = f.getCanonicalPath();
+        }
+        catch (Throwable t)
+        {
+          // We can ignore this error.
+        }
+      }
+    }
+    return truststoreFileAbsolute;
+  }
+
+  /**
+   * Returns the admin port from the configuration.
+   * @return the admin port from the configuration.
+   * @throws ConfigException if an error occurs reading the configuration.
+   */
+  public int getAdminPortFromConfig() throws ConfigException
+  {
+    // Initialization for admin framework
+    if (!configurationInitialized) {
+      initializeConfiguration();
+    }
+    RootCfg root =
+      ServerManagementContext.getInstance().getRootConfiguration();
+    int port = root.getAdministrationConnector().getListenPort();
+    return port;
+  }
+
+  private boolean initializeConfiguration() {
+    // check if the initialization is required
+    try {
+      ServerManagementContext.getInstance().getRootConfiguration().
+      getAdministrationConnector();
+    } catch (java.lang.Throwable th) {
+      try {
+        DirectoryServer.bootstrapClient();
+        DirectoryServer.initializeJMX();
+        DirectoryServer.getInstance().initializeConfiguration();
+      } catch (Exception ex) {
+        // do nothing
+        return false;
+      }
+    }
+    configurationInitialized = true;
+    return true;
+  }
+
+  /**
+   * Returns the port to be used according to the configuration and the
+   * arguments provided by the user.
+   * This method should be called after the arguments have been parsed.
+   * @return the port to be used according to the configuration and the
+   * arguments provided by the user.
+   */
+  public int getPortFromConfig()
+  {
+    int portNumber;
+    if (alwaysSSL()) {
+      portNumber =
+        AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT;
+      // Try to get the port from the config file
+      try
+      {
+        portNumber = getAdminPortFromConfig();
+      } catch (ConfigException ex) {
+        // nothing to do
+      }
+    } else {
+      portNumber = 636;
+    }
+    return portNumber;
+  }
+
+  /**
+   * Updates the default values of the port and the trust store with what is
+   * read in the configuration.
+   * @throws ConfigException if there is an error reading the configuration.
+   */
+  public void initArgumentsWithConfiguration() throws ConfigException
+  {
+    int portNumber = getPortFromConfig();
+    portArg.setDefaultValue(String.valueOf(portNumber));
+
+    String truststoreFileAbsolute = getTruststoreFileFromConfig();
+    if (truststoreFileAbsolute != null)
+    {
+      trustStorePathArg.setDefaultValue(truststoreFileAbsolute);
+    }
+  }
 }
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/BackUpDB.java b/opendj-sdk/opends/src/server/org/opends/server/tools/BackUpDB.java
index 24f09b2..cd5a1d6 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/BackUpDB.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/BackUpDB.java
@@ -285,6 +285,15 @@
       return 1;
     }
 
+    // Init the default values so that they can appear also on the usage.
+    try
+    {
+      argParser.getArguments().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
 
     // Parse the command-line arguments provided to this program.
     try
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/ExportLDIF.java b/opendj-sdk/opends/src/server/org/opends/server/tools/ExportLDIF.java
index c010e2a..ee5538c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/ExportLDIF.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/ExportLDIF.java
@@ -317,6 +317,16 @@
     }
 
 
+    // Init the default values so that they can appear also on the usage.
+    try
+    {
+      argParser.getArguments().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
+
     // Parse the command-line arguments provided to this program.
     try
     {
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java
index 3b96cd6..7634457 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -391,6 +391,15 @@
       return 1;
     }
 
+    // Init the default values so that they can appear also on the usage.
+    try
+    {
+      argParser.getArguments().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
 
     // Parse the command-line arguments provided to this program.
     try
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/ManageTasks.java b/opendj-sdk/opends/src/server/org/opends/server/tools/ManageTasks.java
index cd5ccbe..05bf11b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/ManageTasks.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/ManageTasks.java
@@ -30,6 +30,7 @@
 import org.opends.messages.Message;
 import static org.opends.messages.ToolMessages.*;
 import org.opends.server.api.ErrorLogPublisher;
+import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
 import static org.opends.server.loggers.ErrorLogger.removeErrorLogPublisher;
 import org.opends.server.protocols.asn1.ASN1Exception;
@@ -233,6 +234,15 @@
       return 1;
     }
 
+    try
+    {
+      argParser.getArguments().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
+
     // Parse the command-line arguments provided to this program.
     try {
       argParser.parseArguments(args);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/RestoreDB.java b/opendj-sdk/opends/src/server/org/opends/server/tools/RestoreDB.java
index e7308139..c48b999 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/RestoreDB.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -230,6 +230,15 @@
       return 1;
     }
 
+    // Init the default values so that they can appear also on the usage.
+    try
+    {
+      argParser.getArguments().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
 
     // Parse the command-line arguments provided to this program.
     try
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
index 6257fc3..64bed3d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2007-2008 Sun Microsystems, Inc.
+ *      Copyright 2007-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.tools.dsconfig;
 
@@ -42,6 +42,7 @@
 import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
 import org.opends.server.admin.client.ldap.LDAPConnection;
 import org.opends.server.admin.client.ldap.LDAPManagementContext;
+import org.opends.server.config.ConfigException;
 import org.opends.server.protocols.ldap.LDAPResultCode;
 import org.opends.server.tools.ClientException;
 import org.opends.server.util.args.Argument;
@@ -340,6 +341,14 @@
       parser.addGlobalArgument(arg);
     }
 
+    try
+    {
+      secureArgsList.initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
index f21b7f2..ce30d54 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
@@ -67,6 +67,8 @@
   private SubCommand preExternalInitializationSubCmd;
   private SubCommand statusReplicationSubCmd;
 
+  int defaultAdminPort = 4444;
+
   /**
    * No-prompt argument.
    */
@@ -293,6 +295,14 @@
       throws ArgumentException
   {
     initializeGlobalArguments(outStream);
+    try
+    {
+      defaultAdminPort = secureArgsList.getAdminPortFromConfig();
+    }
+    catch (Throwable t)
+    {
+      // Ignore
+    }
     createEnableReplicationSubCommand();
     createDisableReplicationSubCommand();
     createInitializeReplicationSubCommand();
@@ -529,7 +539,8 @@
         null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());
 
     port1Arg = new IntegerArgument("port1", OPTION_SHORT_PORT, "port1",
-        false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
+        false, false, true, INFO_PORT_PLACEHOLDER.get(),
+        defaultAdminPort, null,
         INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT1.get());
 
     bindDn1Arg = new StringArgument("bindDN1", OPTION_SHORT_BINDDN,
@@ -562,7 +573,7 @@
         null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());
 
     port2Arg = new IntegerArgument("port2", null, "port2",
-        false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
+        false, false, true, INFO_PORT_PLACEHOLDER.get(), defaultAdminPort, null,
         INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT2.get());
 
     bindDn2Arg = new StringArgument("bindDN2", null,
@@ -659,8 +670,8 @@
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_HOST_SOURCE.get());
 
     portSourceArg = new IntegerArgument("portSource", OPTION_SHORT_PORT,
-        "portSource", false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444,
-        null,
+        "portSource", false, false, true, INFO_PORT_PLACEHOLDER.get(),
+        defaultAdminPort, null,
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_SOURCE.get());
 
     hostNameDestinationArg = new StringArgument("hostDestination", 'O',
@@ -670,7 +681,7 @@
 
     portDestinationArg = new IntegerArgument("portDestination", null,
         "portDestination", false, false, true, INFO_PORT_PLACEHOLDER.get(),
-        4444,
+        defaultAdminPort,
         null,
         INFO_DESCRIPTION_INITIALIZE_REPLICATION_SERVER_PORT_DESTINATION.get());
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 5aec539..2787a50 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -111,6 +111,7 @@
 import org.opends.server.admin.client.ldap.LDAPManagementContext;
 import org.opends.server.admin.std.client.*;
 import org.opends.server.admin.std.meta.*;
+import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.tools.ClientException;
 import org.opends.server.tools.ToolConstants;
@@ -347,6 +348,15 @@
 
     if (returnValue == SUCCESSFUL_NOP)
     {
+      try
+      {
+        argParser.getSecureArgsList().initArgumentsWithConfiguration();
+      }
+      catch (ConfigException ce)
+      {
+        // Ignore.
+      }
+
       //  Parse the command-line arguments provided to this program.
       try
       {
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
index dcae02b..bf44d85 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/status/StatusCli.java
@@ -62,6 +62,7 @@
 import org.opends.server.admin.client.ManagementContext;
 import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
 import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
+import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
 
 import org.opends.messages.Message;
@@ -289,6 +290,15 @@
       return ErrorReturnCode.ERROR_UNEXPECTED.getReturnCode();
     }
 
+    try
+    {
+      argParser.getSecureArgsList().initArgumentsWithConfiguration();
+    }
+    catch (ConfigException ce)
+    {
+      // Ignore.
+    }
+
     // Validate user provided data
     try {
       argParser.parseArguments(args);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index d39c52c..25aaaa4 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.util.args;
 import org.opends.messages.Message;
@@ -1672,6 +1672,15 @@
         buffer.append(EOL);
       }
     }
+
+    if (a.needsValue() && (a.getDefaultValue() != null) &&
+       (a.getDefaultValue().length() > 0))
+    {
+      buffer.append(INDENT);
+      buffer.append(INFO_ARGPARSER_USAGE_DEFAULT_VALUE.get(
+          a.getDefaultValue()).toString());
+      buffer.append(EOL);
+    }
   }
 
   /**
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
index 063a18c..087ba25 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.util.args;
 import org.opends.messages.Message;
@@ -1558,6 +1558,14 @@
           buffer.append(EOL);
         }
       }
+      if (a.needsValue() && (a.getDefaultValue() != null) &&
+          (a.getDefaultValue().length() > 0))
+       {
+         buffer.append(INDENT);
+         buffer.append(INFO_ARGPARSER_USAGE_DEFAULT_VALUE.get(
+             a.getDefaultValue()).toString());
+         buffer.append(EOL);
+       }
     }
   }
 
@@ -1885,6 +1893,14 @@
 
     buffer.append(EOL);
     indentAndWrap(Message.raw(INDENT), a.getDescription(), buffer);
+
+    if (a.needsValue() && (a.getDefaultValue() != null) &&
+        (a.getDefaultValue().length() > 0))
+     {
+       indentAndWrap(Message.raw(INDENT),
+           INFO_ARGPARSER_USAGE_DEFAULT_VALUE.get(a.getDefaultValue()),
+           buffer);
+     }
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index 7364f7a..5433283 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -35,7 +35,6 @@
 import org.opends.quicksetup.Step;
 import org.opends.quicksetup.UserDataCertificateException;
 import org.opends.quicksetup.util.Utils;
-import org.opends.server.config.ConfigException;
 import org.opends.server.tools.dsconfig.ArgumentExceptionFactory;
 import org.opends.server.tools.LDAPConnectionOptions;
 import org.opends.server.tools.SSLConnectionFactory;
@@ -61,13 +60,6 @@
 import java.util.Enumeration;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import org.opends.server.admin.AdministrationConnector;
-import org.opends.server.admin.server.ServerManagementContext;
-import org.opends.server.admin.std.server.AdministrationConnectorCfg;
-import org.opends.server.admin.std.server.FileBasedTrustManagerProviderCfg;
-import org.opends.server.admin.std.server.RootCfg;
-import org.opends.server.admin.std.server.TrustManagerProviderCfg;
-import org.opends.server.core.DirectoryServer;
 
 /**
  * Supports interacting with a user through the command line to
@@ -128,8 +120,6 @@
   // The command builder that we can return with the connection information.
   private CommandBuilder commandBuilder;
 
-  private boolean configurationInitialized = false;
-
 
   /**
    * Enumeration description protocols for interactive CLI choices.
@@ -513,18 +503,7 @@
       }
       else
       {
-        if (secureArgsList.alwaysSSL()) {
-          portNumber =
-            AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT;
-          // Try to get the port from the config file
-          try {
-            portNumber = getAdminPortFromConfig();
-          } catch (ConfigException ex) {
-            // nothing to do
-            }
-        } else {
-          portNumber = 636;
-        }
+        portNumber = secureArgsList.getPortFromConfig();
       }
     }
     final int tmpPortNumber = portNumber;
@@ -1992,86 +1971,33 @@
   *
   *  @return true if the local trustore has been added.
   */
-  private boolean addLocalTrustStore() {
-    TrustManagerProviderCfg trustManagerCfg = null;
-    AdministrationConnectorCfg administrationConnectorCfg = null;
+  private boolean addLocalTrustStore()
+  {
     try {
       // If remote host, return
       if (!InetAddress.getLocalHost().getHostName().equals(hostName)) {
         return false;
       }
-      // Initialization for admin framework
-      if (!configurationInitialized) {
-        initializeConfiguration();
-      }
-      // Get the Directory Server configuration handler and use it.
-      RootCfg root =
-        ServerManagementContext.getInstance().getRootConfiguration();
-      administrationConnectorCfg =
-        root.getAdministrationConnector();
       // check if we are in a local instance. Already checked the host,
       // now check the port
-
-      if (administrationConnectorCfg.getListenPort() != portNumber) {
+      if (secureArgsList.getAdminPortFromConfig() != portNumber) {
         return false;
       }
-      String trustManagerStr = administrationConnectorCfg.
-        getTrustManagerProvider();
-      trustManagerCfg = root.getTrustManagerProvider(trustManagerStr);
+
+      String truststoreFileAbsolute =
+        secureArgsList.getTruststoreFileFromConfig();
+      if (truststoreFileAbsolute != null)
+      {
+        secureArgsList.trustStorePathArg.addValue(truststoreFileAbsolute);
+        return true;
+      }
+      else
+      {
+        return false;
+      }
     } catch (Exception ex) {
       // do nothing
       return false;
     }
-    if (trustManagerCfg instanceof FileBasedTrustManagerProviderCfg) {
-      FileBasedTrustManagerProviderCfg fileBasedTrustManagerCfg =
-        (FileBasedTrustManagerProviderCfg) trustManagerCfg;
-      String truststoreFile = fileBasedTrustManagerCfg.getTrustStoreFile();
-      // Check the file
-      String truststoreFileAbsolute = null;
-      if (truststoreFile.startsWith(File.separator)) {
-        truststoreFileAbsolute = truststoreFile;
-      } else {
-        truststoreFileAbsolute =
-          DirectoryServer.getInstanceRoot() + File.separator + truststoreFile;
-      }
-      File f = new File(truststoreFileAbsolute);
-      if (f.exists() && f.canRead() && !f.isDirectory()) {
-        secureArgsList.trustStorePathArg.addValue(truststoreFileAbsolute);
-        return true;
-      } else {
-        return false;
-      }
-    } else {
-      return false;
-    }
-  }
-
-  private int getAdminPortFromConfig() throws ConfigException {
-    // Initialization for admin framework
-    if (!configurationInitialized) {
-      initializeConfiguration();
-    }
-    RootCfg root =
-      ServerManagementContext.getInstance().getRootConfiguration();
-    return root.getAdministrationConnector().getListenPort();
-  }
-
-  private boolean initializeConfiguration() {
-    // check if the initialization is required
-    try {
-      ServerManagementContext.getInstance().getRootConfiguration().
-        getAdministrationConnector();
-    } catch (java.lang.Throwable th) {
-      try {
-        DirectoryServer.bootstrapClient();
-        DirectoryServer.initializeJMX();
-        DirectoryServer.getInstance().initializeConfiguration();
-      } catch (Exception ex) {
-        // do nothing
-        return false;
-      }
-    }
-    configurationInitialized = true;
-    return true;
   }
 }

--
Gitblit v1.10.0