mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
09.27.2009 a1869180d5499a5f0c3d69c84e6ed010a7015fa6
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
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);
    }
  }
}
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
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
    {
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
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);
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
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.
    }
  }
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());
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
      {
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);
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);
    }
  }
  /**
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);
     }
  }
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;
  }
}