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

Violette Roche-Montane
24.50.2014 8a0c7b4a24af390782c917be4f68b45174972b19
Checkpoint OPENDJ-1343 Migrate dsconfig
- Code cleanup on the StatusCli and UnistallCliHelper as they are linked to the LDAPManagementContextFactory.java which is in the dsconfig package.

- LDAPManagementContextFactory
- Refactored the useStartTLS part.

- StatusCli :
- Replaced Quicksetup return Code by opendj-cli return codes. The argument exception now throws CLIENT_SIDE_PARAM_ERROR(89) resultcode instead of ERROR_UNEXPECTED(1).
- Replaced SUCCESSFUL_NOP(0) by SUCCESS(0).
- Removed enum ErrorReturnCode.

- UninstallerCliHelper.java
- Replaced ApplicationException by ClientException (opendj-cli).
- Replaced import org.opends.quicksetup.ReturnCode by opendj-cli ReturnCode.
- Code cleanup.

- CliApplication add ClientException to createUserData.
5 files modified
571 ■■■■■ changed files
opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java 246 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java 62 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/CliApplication.java 18 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java 92 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCli.java 153 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -26,6 +26,13 @@
 */
package org.opends.guitools.uninstaller;
import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_LONG_BINDPWD;
import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_LONG_BINDPWD_FILE;
import static com.forgerock.opendj.cli.Utils.CONFIRMATION_MAX_TRIES;
import static org.forgerock.util.Utils.joinAsString;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -52,15 +59,20 @@
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.controlpanel.datamodel.ConnectionProtocolPolicy;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.quicksetup.*;
import org.opends.quicksetup.ReturnCode;
import org.opends.quicksetup.Application;
import org.opends.quicksetup.ApplicationException;
import org.opends.quicksetup.Configuration;
import org.opends.quicksetup.Constants;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.ProgressStep;
import org.opends.quicksetup.Step;
import org.opends.quicksetup.UserDataException;
import org.opends.quicksetup.event.ProgressUpdateEvent;
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
import org.opends.quicksetup.util.ServerController;
import org.opends.quicksetup.util.Utils;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.opends.server.tools.JavaPropertiesTool.ErrorReturnCode;
import org.opends.server.tools.dsconfig.LDAPManagementContextFactory;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
@@ -71,12 +83,7 @@
import com.forgerock.opendj.cli.Menu;
import com.forgerock.opendj.cli.MenuBuilder;
import com.forgerock.opendj.cli.MenuResult;
import static org.forgerock.util.Utils.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import static com.forgerock.opendj.cli.Utils.*;
import static com.forgerock.opendj.cli.ArgumentConstants.*;
import com.forgerock.opendj.cli.ReturnCode;
/**
 * The class used to provide some CLI interface in the uninstall.
@@ -100,7 +107,7 @@
  private ControlPanelInfo info;
  // This CLI is always using the administration connector with SSL
  /** This CLI is always using the administration connector with SSL. */
  private final boolean alwaysSSL = true;
  private boolean useSSL = true;
  private boolean useStartTLS = false;
@@ -114,23 +121,25 @@
  }
  /**
   * Creates a UserData based in the arguments provided.  It asks
   * user for additional information if what is provided in the arguments is not
   * enough.
   * @param args the ArgumentParser with the allowed arguments of the command
   * line.  The code assumes that the arguments have already been parsed.
   * @param rawArguments the arguments provided in the command line.
   * @return the UserData object with what the user wants to uninstall
   * and null if the user cancels the uninstallation.
   * @throws UserDataException if there is an error with the data
   * in the arguments.
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   * Creates a UserData based in the arguments provided. It asks user for
   * additional information if what is provided in the arguments is not enough.
   *
   * @param args
   *          the ArgumentParser with the allowed arguments of the command line.
   *          The code assumes that the arguments have already been parsed.
   * @param rawArguments
   *          the arguments provided in the command line.
   * @return the UserData object with what the user wants to uninstall and null
   *         if the user cancels the uninstallation.
   * @throws UserDataException
   *           if there is an error with the data in the arguments.
   * @throws ClientException
   *           If there is an error processing data in non-interactive mode and
   *           an error must be thrown (not in force on error mode).
   */
  public UninstallUserData createUserData(UninstallerArgumentParser args,
      String[] rawArguments)
  throws UserDataException, ApplicationException
  throws UserDataException, ClientException
  {
    parser = args;
    UninstallUserData userData = new UninstallUserData();
@@ -162,7 +171,7 @@
       */
      LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
      int v = args.validateGlobalOptions(buf);
      if (v != ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode())
      if (v != ReturnCode.SUCCESS.get())
      {
        throw new UserDataException(null, buf.toMessage());
      }
@@ -226,14 +235,14 @@
        }
      }
      String adminUid = args.getAdministratorUID();
      if ((adminUid == null) && !args.isInteractive())
      if (adminUid == null && !args.isInteractive())
      {
        adminUid = args.getDefaultAdministratorUID();
      }
      userData.setAdminUID(adminUid);
      userData.setAdminPwd(args.getBindPassword());
      String referencedHostName = args.getReferencedHostName();
      if ((referencedHostName == null) && !args.isInteractive())
      if (referencedHostName == null && !args.isInteractive())
      {
        referencedHostName = args.getDefaultReferencedHostName();
      }
@@ -264,8 +273,7 @@
        if (!parser.isInteractive())
        {
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
          throw new ClientException(ReturnCode.APPLICATION_ERROR, msg);
        }
      }
      userData.setLocalServerUrl(adminConnectorUrl);
@@ -286,7 +294,7 @@
        userData = null;
      }
      if ((userData != null) && !args.isQuiet())
      if (userData != null && !args.isQuiet())
      {
        println();
      }
@@ -298,9 +306,9 @@
      {
        throw (UserDataException)t;
      }
      else if (t instanceof ApplicationException)
      else if (t instanceof ClientException)
      {
        throw (ApplicationException)t;
        throw (ClientException)t;
      }
      else
      {
@@ -419,8 +427,8 @@
        {
          for (int i=0; i<msgs.length; i++)
          {
            boolean ignore = ((i == 6) && (outsideDbs.size() == 0)) ||
            ((i == 7) && (outsideLogs.size() == 0));
            boolean ignore = (i == 6 && outsideDbs.size() == 0) ||
            (i == 7 && outsideLogs.size() == 0);
            if (!ignore)
            {
              answers[i] = askConfirmation(msgs[i], true, logger);
@@ -481,8 +489,8 @@
              break;
            }
          }
          if ((userData.getExternalDbsToRemove().size() == 0) &&
              (userData.getExternalLogsToRemove().size() == 0) &&
          if (userData.getExternalDbsToRemove().size() == 0 &&
              userData.getExternalLogsToRemove().size() == 0 &&
              !userData.getRemoveLibrariesAndTools() &&
              !userData.getRemoveDatabases() &&
              !userData.getRemoveConfigurationAndSchema() &&
@@ -508,20 +516,23 @@
  /**
   * Commodity method used to ask the user (when necessary) if the server must
   * be stopped or not.  It also prompts (if required) for authentication.
   * @param userData the UserData object to be updated with the
   * authentication of the user.
   * be stopped or not. It also prompts (if required) for authentication.
   *
   * @param userData
   *          the UserData object to be updated with the authentication of the
   *          user.
   * @return <CODE>true</CODE> if the user wants to continue with uninstall and
   * <CODE>false</CODE> otherwise.
   * @throws UserDataException if there is a problem with the data
   * provided by the user (in the particular case where we are on
   * non-interactive uninstall and some data is missing or not valid).
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   *         <CODE>false</CODE> otherwise.
   * @throws UserDataException
   *           if there is a problem with the data provided by the user (in the
   *           particular case where we are on non-interactive uninstall and
   *           some data is missing or not valid).
   * @throws ClientException
   *           If there is an error processing data in non-interactive mode and
   *           an error must be thrown (not in force on error mode).
   */
  private boolean checkServerState(UninstallUserData userData)
  throws UserDataException, ApplicationException
  throws UserDataException, ClientException
  {
    boolean cancelled = false;
    boolean interactive = parser.isInteractive();
@@ -782,17 +793,19 @@
  }
  /**
   *  Ask for data required to update configuration on remote servers.  If
   *  all the data is provided and validated, we assume that the user wants
   *  to update the remote servers.
   *  @return <CODE>true</CODE> if the user wants to continue and update the
   *  remote servers.  <CODE>false</CODE> otherwise.
   *  @throws UserDataException if there is a problem with the information
   *  provided by the user.
   *  @throws ApplicationException if there is an error processing data.
   * Ask for data required to update configuration on remote servers. If all the
   * data is provided and validated, we assume that the user wants to update the
   * remote servers.
   *
   * @return <CODE>true</CODE> if the user wants to continue and update the
   *         remote servers. <CODE>false</CODE> otherwise.
   * @throws UserDataException
   *           if there is a problem with the information provided by the user.
   * @throws ClientException
   *           If there is an error processing data.
   */
  private boolean askForAuthenticationIfNeeded(UninstallUserData userData)
  throws UserDataException, ApplicationException
  throws UserDataException, ClientException
  {
    boolean accepted = true;
    String uid = userData.getAdminUID();
@@ -860,8 +873,7 @@
          logger.warn(LocalizableMessage.raw(
         "Error retrieving a valid Administration Connector URL in conf file."));
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
            throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
                null);
            throw new ClientException(ReturnCode.APPLICATION_ERROR, msg);
        }
        try
        {
@@ -889,8 +901,7 @@
          logger.warn(LocalizableMessage.raw(
         "Error retrieving a valid Administration Connector URL in conf file."));
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
          throw new ClientException(ReturnCode.APPLICATION_ERROR, msg);
        }
        userData.setLocalServerUrl(adminConnectorUrl);
@@ -972,17 +983,13 @@
    boolean serverStarted = false;
    Application application = new Application()
    {
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public String getInstallationPath()
      {
        return Installation.getLocal().getRootDirectory().getAbsolutePath();
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public String getInstancePath()
      {
@@ -1025,56 +1032,42 @@
          StaticUtils.close(reader);
        }
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public ProgressStep getCurrentProgressStep()
      {
        return UninstallProgressStep.NOT_STARTED;
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public Integer getRatio(ProgressStep step)
      {
        return 0;
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public LocalizableMessage getSummary(ProgressStep step)
      {
        return null;
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public boolean isFinished()
      {
        return false;
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public boolean isCancellable()
      {
        return false;
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public void cancel()
      {
      }
      /**
       * {@inheritDoc}
       */
      /** {@inheritDoc} */
      @Override
      public void run()
      {
@@ -1182,23 +1175,25 @@
  }
  /**
   * Updates the contents of the UninstallUserData while trying to connect
   * to the remote servers.  It returns <CODE>true</CODE> if we could connect
   * to the remote servers and all the presented certificates were accepted and
   * <CODE>false</CODE> otherwise.
   * continue if
   * @param userData the user data to be updated.
   * @return <CODE>true</CODE> if we could connect
   * to the remote servers and all the presented certificates were accepted and
   * <CODE>false</CODE> otherwise.
   * @throws UserDataException if were are not in interactive mode and not in
   * force on error mode and the operation must be stopped.
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   * Updates the contents of the UninstallUserData while trying to connect to
   * the remote servers. It returns <CODE>true</CODE> if we could connect to the
   * remote servers and all the presented certificates were accepted and
   * <CODE>false</CODE> otherwise. continue if
   *
   * @param userData
   *          the user data to be updated.
   * @return <CODE>true</CODE> if we could connect to the remote servers and all
   *         the presented certificates were accepted and <CODE>false</CODE>
   *         otherwise.
   * @throws UserDataException
   *           if were are not in interactive mode and not in force on error
   *           mode and the operation must be stopped.
   * @throws ClientException
   *           If there is an error processing data in non-interactive mode and
   *           an error must be thrown (not in force on error mode).
   */
  private boolean updateUserUninstallDataWithRemoteServers(
      UninstallUserData userData) throws UserDataException, ApplicationException
      UninstallUserData userData) throws UserDataException, ClientException
  {
    boolean accepted = false;
    boolean interactive = parser.isInteractive();
@@ -1238,7 +1233,7 @@
          userData.getTrustManager());
      ADSContext adsContext = new ADSContext(ctx);
      if (interactive && (userData.getTrustManager() == null))
      if (interactive && userData.getTrustManager() == null)
      {
        // This is required when the user did  connect to the server using SSL
        // or Start TLS in interactive mode.  In this case
@@ -1277,9 +1272,9 @@
      logger.warn(LocalizableMessage.raw("Error connecting to server: "+te, te));
      exceptionMsg = Utils.getMessage(te);
    } catch (ApplicationException ae)
    } catch (ClientException ce)
    {
      throw ae;
      throw ce;
    } catch (Throwable t)
    {
@@ -1344,12 +1339,12 @@
   * @param userData the user data.
   * @throws UserDataException if there is an error with the information
   * provided by the user when we are in non-interactive mode.
   * @throws ApplicationException if there is an error processing data in
   * @throws ClientException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   */
  private boolean handleTopologyCache(TopologyCache cache,
      UninstallUserData userData) throws UserDataException, ApplicationException
      UninstallUserData userData) throws UserDataException, ClientException
  {
    boolean returnValue;
    boolean stopProcessing = false;
@@ -1392,23 +1387,19 @@
        stopProcessing = true;
        break;
      case GENERIC_CREATING_CONNECTION:
        if ((e.getCause() != null) &&
        if (e.getCause() != null &&
            Utils.isCertificateException(e.getCause()))
        {
          if (interactive)
          {
            println();
            stopProcessing = true;
            if (ci.promptForCertificateConfirmation(e.getCause(),
                e.getTrustManager(), e.getLdapUrl(), true, logger))
            {
              stopProcessing = true;
              reloadTopologyCache = true;
              updateTrustManager(userData, ci);
            }
            else
            {
              stopProcessing = true;
            }
          }
          else
          {
@@ -1428,7 +1419,7 @@
    }
    if (interactive)
    {
      if (!stopProcessing && (exceptionMsgs.size() > 0))
      if (!stopProcessing && exceptionMsgs.size() > 0)
      {
        println();
        try
@@ -1476,8 +1467,7 @@
              "--"+parser.forceOnErrorArg.getLongIdentifier(),
              Utils.getMessageFromCollection(exceptionMsgs,
                  Constants.LINE_SEPARATOR));
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
          throw new ClientException(ReturnCode.APPLICATION_ERROR, msg);
        }
      }
      else
@@ -1489,9 +1479,7 @@
    return returnValue;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isAdvancedMode() {
    return false;
@@ -1499,9 +1487,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isInteractive() {
    if (!forceNonInteractive)
@@ -1516,9 +1502,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isMenuDrivenMode() {
    return true;
@@ -1526,9 +1510,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isQuiet() {
    return false;
@@ -1536,9 +1518,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isScriptFriendly() {
    return false;
@@ -1546,9 +1526,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isVerbose() {
    return true;
opendj3-server-dev/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
@@ -64,6 +64,8 @@
import org.opends.server.util.DynamicConstants;
import org.opends.server.util.StaticUtils;
import com.forgerock.opendj.cli.ClientException;
import static org.forgerock.util.Utils.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
@@ -600,30 +602,22 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public UserData createUserData(Launcher launcher)
          throws UserDataException, ApplicationException {
    parser = (UninstallerArgumentParser)launcher.getArgumentParser();
    return cliHelper.createUserData(
        parser,
        launcher.getArguments());
  public UserData createUserData(Launcher launcher) throws UserDataException,
      ApplicationException, ClientException
  {
    parser = (UninstallerArgumentParser) launcher.getArgumentParser();
    return cliHelper.createUserData(parser, launcher.getArguments());
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public String getInstallationPath() {
    return getInstallPathFromClasspath();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public String getInstancePath() {
    return getInstancePathFromInstallPath(getInstallPathFromClasspath());
@@ -641,9 +635,7 @@
    return ue;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public ReturnCode getReturnCode() {
    return null;
@@ -1005,9 +997,7 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public ProgressStep getCurrentProgressStep() {
    return status;
@@ -1039,9 +1029,7 @@
    return hmSummary.get(step);
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isFinished() {
    return getCurrentProgressStep() ==
@@ -1054,25 +1042,19 @@
            UninstallProgressStep.FINISHED_WITH_ERROR_DELETING;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isCancellable() {
    return false;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public void cancel() {
    // do nothing; not cancellable
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public void windowClosing(QuickSetupDialog dlg, WindowEvent evt) {
    if ((dlg.getDisplayedStep() == PROGRESS) ||
@@ -1085,17 +1067,13 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public ButtonName getInitialFocusButtonName() {
    return ButtonName.FINISH;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public Set<? extends WizardStep> getWizardSteps() {
    Set<WizardStep> setSteps = new HashSet<WizardStep>();
@@ -1105,9 +1083,7 @@
    return Collections.unmodifiableSet(setSteps);
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public QuickSetupStepPanel createWizardStepPanel(WizardStep step) {
    QuickSetupStepPanel p = null;
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/CliApplication.java
@@ -22,6 +22,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
package org.opends.quicksetup;
@@ -29,6 +30,8 @@
import org.opends.quicksetup.event.ProgressNotifier;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import com.forgerock.opendj.cli.ClientException;
/**
 * Represents a quick setup CLI application.
 */
@@ -37,14 +40,19 @@
  /**
   * Creates a set of user data from command line arguments and installation
   * status.
   * @param launcher that launched this application
   *
   * @param launcher
   *          that launched this application
   * @return UserData object populated to reflect the input args and status
   * @throws UserDataException if something is wrong with the data provided
   * by the user
   * @throws ApplicationException if there is an application specific problem
   * @throws UserDataException
   *           if something is wrong with the data provided by the user
   * @throws ApplicationException
   *           if there is an application specific problem
   * @throws ClientException
   *           If an error occurs when creating the data.
   */
  UserData createUserData(Launcher launcher)
          throws UserDataException, ApplicationException;
          throws UserDataException, ApplicationException, ClientException;
  /**
   * Gets the user data this application will use when running.
opendj3-server-dev/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -179,78 +179,17 @@
          try
          {
            final SSLContextBuilder sslBuilder = new SSLContextBuilder();
            sslBuilder.setTrustManager((trustManager==null?TrustManagers.trustAll():trustManager));
            sslBuilder.setKeyManager(keyManager);
            sslBuilder.setProtocol(SSLContextBuilder.PROTOCOL_SSL);
            options.setUseStartTLS(false);
            options.setSSLContext(sslBuilder.getSSLContext());
            factory = new LDAPConnectionFactory(hostName, portNumber, options);
            connection = factory.getConnection();
            connection.bind(bindDN, bindPassword.toCharArray());
            break;
          }
          catch (ErrorResultException e)
          {
            if (app.isInteractive()
                && ci.isTrustStoreInMemory()
                && e.getCause() != null
                && e.getCause() instanceof SSLException
                && e.getCause().getCause() instanceof CertificateException)
            {
              String authType = null;
              if (trustManager instanceof ApplicationTrustManager)
              { // FIXME use PromptingTrustManager
                ApplicationTrustManager appTrustManager =
                    (ApplicationTrustManager) trustManager;
                authType = appTrustManager.getLastRefusedAuthType();
                X509Certificate[] cert = appTrustManager.getLastRefusedChain();
                if (ci.checkServerCertificate(cert, authType, hostName))
                {
                  // If the certificate is trusted, update the trust manager.
                  trustManager = ci.getTrustManager();
                  // Try to connect again.
                  continue;
                }
              }
            }
            if (e.getCause() != null && e.getCause() instanceof SSLException)
            {
              LocalizableMessage message =
                  ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED.get(
                      hostName, portNumber);
              throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR,
                  message);
            }
            LocalizableMessage message =
                ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT
                    .get(hostName, portNumber);
            throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR,
                message);
          }
          catch (GeneralSecurityException e)
          {
            LocalizableMessage message =
                ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT
                    .get(hostName, portNumber);
            throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR,
                message);
          }
        }
      }
      else if (ci.useStartTLS())
      {
        while (true)
        {
          try
          {
            final SSLContextBuilder sslBuilder = new SSLContextBuilder();
            sslBuilder.setTrustManager((trustManager == null ? TrustManagers
                .trustAll() : trustManager));
            sslBuilder.setKeyManager(keyManager);
            sslBuilder.setProtocol(SSLContextBuilder.PROTOCOL_SSL);
            options.setUseStartTLS(true);
            if (ci.useStartTLS())
            {
              options.setUseStartTLS(true);
            }
            else
            {
              options.setUseStartTLS(false);
            }
            options.setSSLContext(sslBuilder.getSSLContext());
            factory = new LDAPConnectionFactory(hostName, portNumber, options);
@@ -283,7 +222,7 @@
                }
              }
            }
            if (e.getCause() != null && e.getCause() instanceof SSLException)
            if (e.getCause() instanceof SSLException)
            {
              LocalizableMessage message =
                  ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED.get(
@@ -291,6 +230,19 @@
              throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR,
                  message);
            }
            if (e.getCause() instanceof AuthorizationException)
            {
              LocalizableMessage message =
                  ERR_DSCFG_ERROR_LDAP_SIMPLE_BIND_NOT_SUPPORTED.get();
              throw new ClientException(ReturnCode.AUTH_METHOD_NOT_SUPPORTED,
                  message);
            }
            else if (e.getCause() instanceof AuthenticationException)
            {
              LocalizableMessage message =
                  ERR_DSCFG_ERROR_LDAP_SIMPLE_BIND_FAILED.get(bindDN);
              throw new ClientException(ReturnCode.INVALID_CREDENTIALS, message);
            }
            LocalizableMessage message =
                ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT
                    .get(hostName, portNumber);
opendj3-server-dev/src/server/org/opends/server/tools/status/StatusCli.java
@@ -27,6 +27,15 @@
package org.opends.server.tools.status;
import static com.forgerock.opendj.cli.ArgumentConstants.LIST_TABLE_SEPARATOR;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.ToolMessages.ERR_ERROR_PARSING_ARGS;
import static com.forgerock.opendj.cli.CliMessages.*;
import static org.opends.quicksetup.util.Utils.getCommandLineMaxLineWidth;
import static org.opends.messages.QuickSetupMessages.INFO_NOT_AVAILABLE_LABEL;
import static org.opends.messages.QuickSetupMessages.
INFO_ERROR_READING_SERVER_CONFIGURATION;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
@@ -43,6 +52,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.client.ManagementContext;
import org.forgerock.opendj.config.server.ConfigException;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
@@ -57,11 +68,6 @@
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.admin.AdministrationConnector;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.forgerock.opendj.config.client.ManagementContext;
import org.forgerock.opendj.config.server.ConfigException;
import com.forgerock.opendj.cli.ClientException;
import org.opends.server.tools.dsconfig.LDAPManagementContextFactory;
import org.opends.server.types.DN;
import org.opends.server.types.InitializationException;
@@ -69,20 +75,14 @@
import org.opends.server.types.OpenDsException;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.StaticUtils;
import com.forgerock.opendj.cli.ConsoleApplication;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ClientException;
import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.TableBuilder;
import com.forgerock.opendj.cli.TextTablePrinter;
import com.forgerock.opendj.cli.ArgumentException;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import static org.opends.messages.ToolMessages.*;
import static org.opends.quicksetup.util.Utils.*;
import static com.forgerock.opendj.cli.ArgumentConstants.LIST_TABLE_SEPARATOR;
import com.forgerock.opendj.cli.ReturnCode;
/**
 * The class used to provide some CLI interface to display status.
@@ -98,73 +98,19 @@
  private boolean displayMustStartLegend;
  /** Prefix for log files. */
  static public final String LOG_FILE_PREFIX = "opendj-status-";
  public static final String LOG_FILE_PREFIX = "opendj-status-";
  /** Suffix for log files. */
  static public final String LOG_FILE_SUFFIX = ".log";
  public static final String LOG_FILE_SUFFIX = ".log";
  private ApplicationTrustManager interactiveTrustManager;
  private boolean useInteractiveTrustManager;
  // This CLI is always using the administration connector with SSL
  /** This CLI is always using the administration connector with SSL. */
  private final boolean alwaysSSL = true;
  /**
   * The enumeration containing the different return codes that the command-line
   * can have.
   *
   */
  enum ErrorReturnCode
  {
    /**
     * Successful display of the status.
     */
    SUCCESSFUL(0),
    /**
     * We did no have an error but the status was not displayed (displayed
     * version or usage).
     */
    SUCCESSFUL_NOP(0),
    /**
     * Unexpected error (potential bug).
     */
    ERROR_UNEXPECTED(1),
    /**
     * Cannot parse arguments.
     */
    ERROR_PARSING_ARGS(2),
    /**
     * User cancelled (for instance not accepting the certificate proposed) or
     * could not use the provided connection parameters in interactive mode.
     */
    USER_CANCELLED_OR_DATA_ERROR(3),
    /**
     * This occurs for instance when the authentication provided by the user is
     * not valid.
     */
    ERROR_READING_CONFIGURATION_WITH_LDAP(4);
    private int returnCode;
    private ErrorReturnCode(int returnCode)
    {
      this.returnCode = returnCode;
    }
    /**
     * Get the corresponding return code value.
     *
     * @return The corresponding return code value.
     */
    public int getReturnCode()
    {
      return returnCode;
    }
  }
  /**
   * The Logger.
   */
  /** The Logger. */
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The argument parser. */
@@ -263,9 +209,8 @@
    try {
      argParser.initializeGlobalArguments(getOutputStream());
    } catch (ArgumentException ae) {
      LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
      println(message);
      return ErrorReturnCode.ERROR_UNEXPECTED.getReturnCode();
      println(ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage()));
      return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
    }
    try
@@ -281,18 +226,17 @@
    try {
      argParser.parseArguments(args);
    } catch (ArgumentException ae) {
      LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
      println(message);
      println(ERR_ERROR_PARSING_ARGS.get(ae.getMessage()));
      println();
      println(LocalizableMessage.raw(argParser.getUsage()));
      return ErrorReturnCode.ERROR_PARSING_ARGS.getReturnCode();
      return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
    }
    //  If we should just display usage or version information,
    // then print it and exit.
    if (argParser.usageOrVersionDisplayed()) {
      return ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode();
      return ReturnCode.SUCCESS.get();
    }
    // Checks the version - if upgrade required, the tool is unusable
@@ -307,7 +251,7 @@
    }
    int v = argParser.validateGlobalOptions(getErrorStream());
    if (v != ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode()) {
    if (v != ReturnCode.SUCCESS.get()) {
      println(LocalizableMessage.raw(argParser.getUsage()));
      return v;
    } else {
@@ -366,11 +310,11 @@
            useInteractiveTrustManager = true;
          } catch (ArgumentException e) {
            println(e.getMessageObject());
            return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
            return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
          } catch (ClientException e) {
            println(e.getMessageObject());
            writeStatus(controlInfo);
            return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
            return ReturnCode.ERROR_USER_CANCELLED.get();
          } finally {
            StaticUtils.close(ctx);
          }
@@ -397,23 +341,20 @@
            writeStatus(controlInfo);
            if (!controlInfo.getServerDescriptor().getExceptions().isEmpty()) {
              return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
                getReturnCode();
              return ReturnCode.ERROR_INITIALIZING_SERVER.get();
            }
          } catch (NamingException ne) {
            // This should not happen but this is useful information to
            // diagnose the error.
            println();
            println(INFO_ERROR_READING_SERVER_CONFIGURATION.get(ne));
            return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
              getReturnCode();
            return ReturnCode.ERROR_INITIALIZING_SERVER.get();
          } catch (ConfigReadException cre) {
            // This should not happen but this is useful information to
            // diagnose the error.
            println();
            println(cre.getMessageObject());
            return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
              getReturnCode();
            return ReturnCode.ERROR_INITIALIZING_SERVER.get();
          } finally {
            StaticUtils.close(ctx);
          }
@@ -427,7 +368,7 @@
      }
    }
    return ErrorReturnCode.SUCCESSFUL.getReturnCode();
    return ReturnCode.SUCCESS.get();
  }
  private void writeStatus(ControlPanelInfo controlInfo)
@@ -964,7 +905,7 @@
          for (int j=0; j<tableModel.getColumnCount(); j++)
          {
            LocalizableMessageBuilder line = new LocalizableMessageBuilder();
            line.append(tableModel.getColumnName(j)+": ");
            line.append(tableModel.getColumnName(j)).append(": ");
            if (j == 0)
            {
              // It is the hostName
@@ -1085,7 +1026,7 @@
      LocalizableMessage header = LocalizableMessage.raw(tableModel.getColumnName(i));
      labels[i] = new LocalizableMessageBuilder(header).append(":").toMessage();
      labelWidth = Math.max(labelWidth, labels[i].length());
      if ((i != 4) && (i != 5))
      if (i != 4 && i != 5)
      {
        labelWidthWithoutReplicated =
          Math.max(labelWidthWithoutReplicated, labels[i].length());
@@ -1178,7 +1119,7 @@
        boolean isReplicated =
          replicatedLabel.toString().equals(
              String.valueOf(tableModel.getValueAt(i, 3)));
        if ((j == 4) || (j == 5))
        if (j == 4 || j == 5)
        {
          // If the suffix is not replicated we do not have to display these
          // lines.
@@ -1219,7 +1160,7 @@
      {
        buf.append(" ");
      }
      buf.append("--- "+text+" ---");
      buf.append("--- ").append(text).append(" ---");
      centered = buf.toMessage();
    }
    else
@@ -1245,9 +1186,7 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isAdvancedMode() {
    return false;
@@ -1255,9 +1194,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isInteractive() {
    return argParser.isInteractive();
@@ -1265,9 +1202,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isMenuDrivenMode() {
    return true;
@@ -1275,9 +1210,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isQuiet() {
    return false;
@@ -1285,9 +1218,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isScriptFriendly() {
    return argParser.isScriptFriendly();
@@ -1295,9 +1226,7 @@
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isVerbose() {
    return true;