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

jvergara
02.05.2007 a3decf6f3114f51764c1bbe80a892c6e9d1fe2b7
The following modifications are aimed to have the same interaction in the status and dsconfig command lines by sharing the same code.
The formatting of the table in status command-line has also be modified to be consistent with the one provided by dsconfig.
12 files modified
659 ■■■■ changed files
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java 6 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConnectionProtocolPolicy.java 29 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java 509 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java 11 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/admin_tool.properties 5 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java 15 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java 6 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java 3 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java 3 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java 33 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java 3 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java 36 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
@@ -42,8 +42,8 @@
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapName;
import javax.net.ssl.TrustManager;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.util.Utils;
@@ -76,7 +76,7 @@
  private String lastUrl;
  private ConnectionProtocolPolicy policy;
  private ConfigFromFile offlineConf;
  private ApplicationTrustManager trustManager;
  private TrustManager trustManager;
  private InitialLdapContext ctx;
  private String javaVersion;
@@ -105,7 +105,7 @@
   */
  public void setConnectionInfo(ConfigFromFile offlineConf,
      ConnectionProtocolPolicy policy, String dn, String pwd,
      ApplicationTrustManager trustManager) throws ConfigException
      TrustManager trustManager) throws ConfigException
  {
    if (offlineConf == null)
    {
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConnectionProtocolPolicy.java
@@ -49,5 +49,32 @@
  /**
   * Use the less secure available (LDAP, and then LDAPs).
   */
  USE_LESS_SECURE_AVAILABLE,
  USE_LESS_SECURE_AVAILABLE;
  /**
   * Returns the ConnectionPolicy to be used with the parameters provided
   * by the user.
   * @param useSSL whether the user asked to use SSL or not.
   * @param useStartTLS whether the user asked to use Start TLS or not.
   * @return the ConnectionPolicy to be used with the parameters provided
   * by the user.
   */
  public static ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
      boolean useStartTLS)
  {
    ConnectionProtocolPolicy policy;
    if (useStartTLS)
    {
      policy = ConnectionProtocolPolicy.USE_STARTTLS;
    }
    else if (useSSL)
    {
      policy = ConnectionProtocolPolicy.USE_LDAPS;
    }
    else
    {
      policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
    }
    return policy;
  }
}
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -40,22 +40,18 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.net.ssl.TrustManager;
import javax.swing.table.TableModel;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.statuspanel.ui.DatabasesTableModel;
import org.opends.guitools.statuspanel.ui.ListenersTableModel;
import org.opends.quicksetup.CliApplicationHelper;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.util.Utils;
import static org.opends.quicksetup.util.Utils.*;
import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.opends.server.core.DirectoryServer;
import org.opends.messages.Message;
@@ -64,8 +60,15 @@
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.ToolConstants;
import org.opends.server.tools.dsconfig.LDAPManagementContextFactory;
import org.opends.server.types.NullOutputStream;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.cli.ConsoleApplication;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
import org.opends.server.util.table.TableBuilder;
import org.opends.server.util.table.TextTablePrinter;
/**
 * The class used to provide some CLI interface to display status.
@@ -74,7 +77,7 @@
 * in the command line.
 *
 */
class StatusCli extends CliApplicationHelper
class StatusCli extends ConsoleApplication
{
  private boolean displayMustAuthenticateLegend;
@@ -86,8 +89,7 @@
  /** Suffix for log files. */
  static public final String LOG_FILE_SUFFIX = ".log";
  /** Maximum number of connection attempts. */
  private final int MAX_CONNECTION_RETRY =3;
  private TrustManager interactiveTrustManager;
  /**
   * The enumeration containing the different return codes that the command-line
@@ -114,13 +116,10 @@
     */
    ERROR_PARSING_ARGS(2),
    /**
     * User cancelled (for instance not accepting the certificate proposed).
     * User cancelled (for instance not accepting the certificate proposed) or
     * could not use the provided connection parameters in interactive mode.
     */
    USER_CANCELLED(3),
    /**
     * Too many connection failure.
     */
   ERROR_TOO_MANY_CONNECTION_FAILURE(4);
    USER_CANCELLED_OR_DATA_ERROR(3);
    private int returnCode;
    private ErrorReturnCode(int returnCode)
@@ -156,7 +155,7 @@
   */
  public StatusCli(PrintStream out, PrintStream err, InputStream in)
  {
    super(out, err, in);
    super(in, out, err);
  }
  /**
@@ -263,12 +262,12 @@
    argParser = new StatusCliArgumentParser(StatusCli.class.getName());
    try
    {
      argParser.initializeGlobalArguments(err);
      argParser.initializeGlobalArguments(getErrorStream());
    }
    catch (ArgumentException ae)
    {
      Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
      err.println(wrap(message));
      println(message);
      return ErrorReturnCode.ERROR_UNEXPECTED.getReturnCode();
    }
@@ -280,9 +279,9 @@
    catch (ArgumentException ae)
    {
      Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
      printErrorMessage(message);
      printLineBreak();
      printErrorMessage(argParser.getUsage());
      println(message);
      println();
      println(Message.raw(argParser.getUsage()));
      return ErrorReturnCode.ERROR_PARSING_ARGS.getReturnCode();
    }
@@ -293,11 +292,11 @@
    {
      return ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode();
    }
    int v = argParser.validateGlobalOptions(err);
    int v = argParser.validateGlobalOptions(getErrorStream());
    if (v != DsFrameworkCliReturnCode.SUCCESSFUL_NOP.getReturnCode())
    {
      printErrorMessage(argParser.getUsage());
      println(Message.raw(argParser.getUsage()));
      return v;
    }
    else
@@ -319,150 +318,92 @@
          boolean useStartTLS = argParser.useStartTLS();
          if (argParser.isInteractive())
          {
            boolean connected = false;
            boolean cancelled = false;
            boolean prompted = false;
            boolean canUseSSL = offLineConf.getLDAPSURL() != null;
            boolean canUseStartTLS = offLineConf.getStartTLSURL() != null;
            // This is done because we do not need to ask the user about these
            // parameters.  If we force their presence the class
            // LDAPConnectionConsoleInteraction will not prompt the user for
            // them.
            SecureConnectionCliArgs secureArgsList =
              argParser.getSecureArgsList();
            bindDn = argParser.getExplicitBindDn();
            bindPwd = argParser.getBindPassword();
            if (bindDn == null)
            secureArgsList.hostNameArg.setPresent(true);
            secureArgsList.portArg.setPresent(true);
            secureArgsList.hostNameArg.addValue(
                secureArgsList.hostNameArg.getDefaultValue());
            secureArgsList.portArg.addValue(
                secureArgsList.portArg.getDefaultValue());
            // We already know if SSL or StartTLS can be used.  If we cannot
            // use them we will not propose them in the connection parameters
            // and if none of them can be used we will just not ask for the
            // protocol to be used.
            if (!canUseSSL)
            {
              bindDn = promptForString(
                  INFO_CLI_BINDDN_PROMPT.get(), argParser.getDefaultBindDn());
              prompted = true;
              if (useSSL)
              {
                throw new ConfigException(
                    ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
            }
            if (bindPwd == null)
            {
              bindPwd = promptForPassword(
                  INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn));
              prompted = true;
              secureArgsList.useSSLArg.setValueSetByProperty(true);
            }
            if (!useSSL && !useStartTLS)
            if (!canUseStartTLS)
            {
              if (canUseSSL)
              if (useStartTLS)
              {
                printLineBreak();
                useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
                throw new ConfigException(
                    ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
              }
              if (!useSSL && canUseStartTLS)
              {
                printLineBreak();
                useStartTLS =
                  confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
              secureArgsList.useStartTLSArg.setValueSetByProperty(true);
              }
              prompted = true;
            }
            InitialLdapContext ctx = null;
            int remainingRetry = MAX_CONNECTION_RETRY;
            while (!connected && !cancelled && (remainingRetry > 0))
            {
             remainingRetry--;
              if (prompted)
              {
                printLineBreak();
              }
              String host = "localhost";
              int port = 389;
            LDAPConnectionConsoleInteraction ci =
              new LDAPConnectionConsoleInteraction(
                  this, argParser.getSecureArgsList());
              try
              {
              ci.run(canUseSSL, canUseStartTLS);
              bindDn = ci.getBindDN();
              bindPwd = ci.getBindPassword();
              useSSL = ci.useSSL();
              useStartTLS = ci.useStartTLS();
              int port = 389;
                String ldapUrl = offLineConf.getURL(
                    getConnectionPolicy(useSSL, useStartTLS));
                  ConnectionProtocolPolicy.getConnectionPolicy(
                      useSSL, useStartTLS));
                try
                {
                  URI uri = new URI(ldapUrl);
                  host = uri.getHost();
                  port = uri.getPort();
                ci.setPortNumber(port);
                }
                catch (Throwable t)
                {
                  LOG.log(Level.SEVERE, "Error parsing url: "+ldapUrl);
                }
                ctx = createContext(host, port, useSSL, useStartTLS, bindDn,
                    bindPwd, getTrustManager());
                connected = true;
              LDAPManagementContextFactory factory =
                new LDAPManagementContextFactory();
              factory.getManagementContext(this, ci);
              interactiveTrustManager = ci.getTrustManager();
              }
              catch (ConfigException ce)
              {
                LOG.log(Level.WARNING, "Error reading config file: "+ce, ce);
                printLineBreak();
                printErrorMessage(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
                printLineBreak();
                useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
                if (!useSSL)
                {
                  useStartTLS =
                    confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
              println();
              println(ERR_COULD_NOT_FIND_VALID_LDAPURL.get());
              println();
              return
                ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
                }
                prompted = true;
            catch (ArgumentException e) {
              println(e.getMessageObject());
              return
                ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
              }
              catch (NamingException ne)
              {
                LOG.log(Level.WARNING, "Error connecting: "+ne, ne);
                if (Utils.isCertificateException(ne))
                {
                  String usedUrl = ConnectionUtils.getLDAPUrl(host, port,
                      useSSL);
                  if (!promptForCertificateConfirmation(ne, getTrustManager(),
                      usedUrl, getTrustManager()))
                  {
                    cancelled = true;
                  }
                  prompted = true;
                }
                else
                {
                  printLineBreak();
                  printErrorMessage(
                      ERR_STATUS_CLI_ERROR_CONNECTING_PROMPT_AGAIN.get(
                          ne.getMessage()));
                  String defaultValue = (bindDn != null) ? bindDn :
                    argParser.getDefaultBindDn();
                  bindDn = promptForString(
                      INFO_CLI_BINDDN_PROMPT.get(), defaultValue);
                  bindPwd = promptForPassword(
                      INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDn));
                  printLineBreak();
                  useSSL = confirm(INFO_CLI_USESSL_PROMPT.get(), useSSL);
                  if (!useSSL)
                  {
                    printLineBreak();
                    useStartTLS =
                      confirm(INFO_CLI_USESTARTTLS_PROMPT.get(), useStartTLS);
                  }
                  prompted = true;
                }
              }
            }
            if (ctx != null)
            {
              try
              {
                ctx.close();
              }
              catch (Throwable t)
              {
              }
            }
            if (cancelled)
            {
              return ErrorReturnCode.USER_CANCELLED.getReturnCode();
            }
            else
            if (remainingRetry <= 0)
            {
              printErrorMessage(
                  ERR_STATUS_CLI_TOO_MANY_CONNECTION_ATTEMPT.get());
              return ErrorReturnCode.ERROR_TOO_MANY_CONNECTION_FAILURE
                  .getReturnCode();
            catch (ClientException e) {
              println(e.getMessageObject());
              return
                ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
            }
          }
          else
@@ -482,8 +423,8 @@
          ServerStatusDescriptor desc = createServerStatusDescriptor(
              bindDn, bindPwd);
          ConfigFromLDAP onLineConf = new ConfigFromLDAP();
          ConnectionProtocolPolicy policy = getConnectionPolicy(useSSL,
              useStartTLS);
          ConnectionProtocolPolicy policy =
            ConnectionProtocolPolicy.getConnectionPolicy(useSSL, useStartTLS);
          onLineConf.setConnectionInfo(offLineConf, policy, bindDn,
              bindPwd, getTrustManager());
          onLineConf.readConfiguration();
@@ -500,8 +441,8 @@
      }
      catch (ConfigException ce)
      {
        printLineBreak();
        printErrorMessage(ce.getMessageObject());
        println();
        println(ce.getMessageObject());
      }
    }
@@ -585,20 +526,20 @@
      {
        labelWidth = Math.max(labelWidth, labels[i].length());
      }
      out.println();
      out.println(centerTitle(title));
      getOutputStream().println();
      getOutputStream().println(centerTitle(title));
    }
    writeStatusContents(desc, labelWidth);
    writeCurrentConnectionContents(desc, labelWidth);
    if (!isScriptFriendly())
    {
      out.println();
      getOutputStream().println();
    }
    title = INFO_SERVER_DETAILS_TITLE.get();
    if (!isScriptFriendly())
    {
      out.println(centerTitle(title));
      getOutputStream().println(centerTitle(title));
    }
    writeHostnameContents(desc, labelWidth);
    writeAdministrativeUserContents(desc, labelWidth);
@@ -607,13 +548,13 @@
    writeJavaVersionContents(desc, labelWidth);
    if (!isScriptFriendly())
    {
      out.println();
      getOutputStream().println();
    }
    writeListenerContents(desc);
    if (!isScriptFriendly())
    {
      out.println();
      getOutputStream().println();
    }
    writeDatabaseContents(desc);
@@ -624,17 +565,18 @@
    {
      if (displayMustStartLegend)
      {
        out.println();
        out.println(wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
        getOutputStream().println();
        getOutputStream().println(
            wrap(INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND.get()));
      }
      else if (displayMustAuthenticateLegend)
      {
        out.println();
        out.println(
        getOutputStream().println();
        getOutputStream().println(
            wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
      }
    }
    out.println();
    getOutputStream().println();
  }
  /**
@@ -851,7 +793,7 @@
    if (!isScriptFriendly())
    {
      Message title = INFO_LISTENERS_TITLE.get();
      out.println(centerTitle(title));
      getOutputStream().println(centerTitle(title));
    }
    Set<ListenerDescriptor> allListeners = desc.getListeners();
@@ -871,17 +813,17 @@
      {
        if (!desc.isAuthenticated())
        {
          out.println(
          getOutputStream().println(
              wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()));
        }
        else
        {
          out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
          getOutputStream().println(wrap(INFO_NO_LISTENERS_FOUND.get()));
        }
      }
      else
      {
        out.println(wrap(INFO_NO_LISTENERS_FOUND.get()));
        getOutputStream().println(wrap(INFO_NO_LISTENERS_FOUND.get()));
      }
    }
    else
@@ -902,7 +844,7 @@
    Message title = INFO_DATABASES_TITLE.get();
    if (!isScriptFriendly())
    {
      out.println(centerTitle(title));
      getOutputStream().println(centerTitle(title));
    }
    Set<DatabaseDescriptor> databases = desc.getDatabases();
@@ -913,17 +855,17 @@
      {
        if (!desc.isAuthenticated())
        {
          out.println(
          getOutputStream().println(
              wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()));
        }
        else
        {
          out.println(wrap(INFO_NO_DBS_FOUND.get()));
          getOutputStream().println(wrap(INFO_NO_DBS_FOUND.get()));
        }
      }
      else
      {
        out.println(wrap(INFO_NO_DBS_FOUND.get()));
        getOutputStream().println(wrap(INFO_NO_DBS_FOUND.get()));
      }
    }
    else
@@ -951,8 +893,8 @@
    Message errorMsg = desc.getErrorMessage();
    if (errorMsg != null)
    {
      out.println();
      out.println(wrap(errorMsg));
      getOutputStream().println();
      getOutputStream().println(wrap(errorMsg));
    }
  }
@@ -996,123 +938,69 @@
  private void writeTableModel(TableModel tableModel,
      ServerStatusDescriptor desc)
  {
    int[] maxWidths = new int[tableModel.getColumnCount()];
    for (int i=0; i<maxWidths.length; i++)
    {
      maxWidths[i] = tableModel.getColumnName(i).length();
    }
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      for (int j=0; j<maxWidths.length; j++)
      {
        Object v = tableModel.getValueAt(i, j);
        if (v != null)
        {
          if (v instanceof String)
          {
            maxWidths[j] = Math.max(maxWidths[j], ((String)v).length());
          }
          else if (v instanceof Integer)
          {
            Message text;
            int nEntries = ((Integer)v).intValue();
            if (nEntries >= 0)
            {
              text = Message.raw(String.valueOf(nEntries));
            }
            else
            {
              if (!desc.isAuthenticated())
              {
                text = getNotAvailableBecauseAuthenticationIsRequiredText();
              }
              else
              {
                text = getNotAvailableText();
              }
            }
            maxWidths[j] = Math.max(maxWidths[j], text.length());
          }
          else
          {
            throw new IllegalStateException("Unknown object type: "+v);
          }
        }
      }
    }
    int totalWidth = 0;
    for (int i=0; i<maxWidths.length; i++)
    {
      if (i < maxWidths.length - 1)
      {
        maxWidths[i] += 5;
      }
      totalWidth += maxWidths[i];
    }
    MessageBuilder headerLine = new MessageBuilder();
    for (int i=0; i<maxWidths.length; i++)
    {
      String header = tableModel.getColumnName(i);
      headerLine.append(header);
      int extra = maxWidths[i] - header.length();
      for (int j=0; j<extra; j++)
      {
        headerLine.append(" ");
      }
    }
    if (!isScriptFriendly())
    {
      out.println(wrap(headerLine.toMessage()));
      MessageBuilder t = new MessageBuilder();
      for (int i=0; i<headerLine.length(); i++)
      {
        t.append("=");
      }
      out.println(wrap(t.toMessage()));
    }
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      if (isScriptFriendly())
      {
        out.println("-");
      }
      MessageBuilder line = new MessageBuilder();
      for (int i=0; i<tableModel.getRowCount(); i++)
      {
        getOutputStream().println("-");
      for (int j=0; j<tableModel.getColumnCount(); j++)
      {
        if (isScriptFriendly())
        {
          MessageBuilder line = new MessageBuilder();
          line.append(tableModel.getColumnName(j)+": ");
          line.append(getCellValue(tableModel.getValueAt(i, j), desc));
          getOutputStream().println(wrap(line.toMessage()));
        }
        int extra = maxWidths[j];
        Object v = tableModel.getValueAt(i, j);
      }
    }
    else
    {
      TableBuilder table = new TableBuilder();
      for (int i=0; i< tableModel.getColumnCount(); i++)
      {
        table.appendHeading(Message.raw(tableModel.getColumnName(i)));
      }
      for (int i=0; i<tableModel.getRowCount(); i++)
      {
        table.startRow();
        for (int j=0; j<tableModel.getColumnCount(); j++)
        {
          table.appendCell(getCellValue(tableModel.getValueAt(i, j), desc));
        }
      }
      TextTablePrinter printer = new TextTablePrinter(getOutputStream());
      printer.setColumnSeparator(ToolConstants.LIST_TABLE_SEPARATOR);
      table.print(printer);
    }
  }
  private Message getCellValue(Object v, ServerStatusDescriptor desc)
  {
    Message s = null;
        if (v != null)
        {
          if (v instanceof String)
          {
            line.append((String)v);
            extra -= ((String)v).length();
        s = Message.raw((String)v);
          }
          else if (v instanceof Integer)
          {
            int nEntries = ((Integer)v).intValue();
            if (nEntries >= 0)
            {
              line.append(nEntries);
          s = Message.raw(String.valueOf(nEntries));
            }
            else
            {
              if (!desc.isAuthenticated())
              {
                line.append(
                    getNotAvailableBecauseAuthenticationIsRequiredText());
            s = getNotAvailableBecauseAuthenticationIsRequiredText();
              }
              else
              {
                line.append(getNotAvailableText());
            s = getNotAvailableText();
              }
            }
          }
@@ -1120,25 +1008,12 @@
          {
            throw new IllegalStateException("Unknown object type: "+v);
          }
          if (isScriptFriendly())
    }
    else
          {
            out.println(wrap(line.toMessage()));
            line = new MessageBuilder();
      s = getNotAvailableText();
          }
        }
        if (!isScriptFriendly())
        {
          for (int k=0; k<extra; k++)
          {
            line.append(" ");
          }
        }
      }
      if (!isScriptFriendly())
      {
        out.println(wrap(line.toMessage()));
      }
    }
    return s;
  }
  /**
@@ -1154,6 +1029,7 @@
      desc.getStatus() == ServerStatusDescriptor.ServerStatus.STARTED;
    int labelWidth = 0;
    int labelWidthWithoutReplicated = 0;
    Message[] labels = new Message[tableModel.getColumnCount()];
    for (int i=0; i<tableModel.getColumnCount(); i++)
    {
@@ -1168,6 +1044,11 @@
      }
      labels[i] = new MessageBuilder(header).append(":").toMessage();
      labelWidth = Math.max(labelWidth, labels[i].length());
      if ((i != 4) && (i != 5))
      {
        labelWidthWithoutReplicated =
          Math.max(labelWidthWithoutReplicated, labels[i].length());
      }
    }
    Message replicatedLabel = INFO_BASEDN_REPLICATED_LABEL.get();
@@ -1175,11 +1056,11 @@
    {
      if (isScriptFriendly())
      {
        out.println("-");
        getOutputStream().println("-");
      }
      else if (i > 0)
      {
        out.println();
        getOutputStream().println();
      }
      for (int j=0; j<tableModel.getColumnCount(); j++)
      {
@@ -1241,18 +1122,18 @@
        }
        boolean doWrite = true;
        boolean isReplicated =
          replicatedLabel.equals(tableModel.getValueAt(i, 3));
        if ((j == 4) || (j == 5))
        {
          // If the suffix is not replicated we do not have to display these
          // lines.
          if (!replicatedLabel.equals(tableModel.getValueAt(i, 3)))
          {
            doWrite = false;
          }
          doWrite = isReplicated;
        }
        if (doWrite)
        {
          writeLabelValue(labels[j], value, labelWidth);
          writeLabelValue(labels[j], value,
              isReplicated?labelWidth:labelWidthWithoutReplicated);
        }
      }
    }
@@ -1269,8 +1150,7 @@
      buf.append(" ");
    }
    buf.append(" ").append(String.valueOf(value));
    out.println(wrap(buf.toMessage()));
    getOutputStream().println(wrap(buf.toMessage()));
  }
  private Message centerTitle(Message text)
@@ -1299,19 +1179,68 @@
   * Returns the trust manager to be used by this application.
   * @return the trust manager to be used by this application.
   */
  private ApplicationTrustManager getTrustManager()
  private TrustManager getTrustManager()
  {
    if (interactiveTrustManager == null)
  {
    return argParser.getTrustManager();
  }
    else
    {
      return interactiveTrustManager;
    }
  }
  /**
   * Tells whether the user specified to have a script-friendly output or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have a script-friendly
   * output and <CODE>false</CODE> otherwise.
   * {@inheritDoc}
   */
  private boolean isScriptFriendly()
  {
  public boolean isAdvancedMode() {
    return false;
  }
  /**
   * {@inheritDoc}
   */
  public boolean isInteractive() {
    return argParser.isInteractive();
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isMenuDrivenMode() {
    return true;
  }
  /**
   * {@inheritDoc}
   */
  public boolean isQuiet() {
    return false;
  }
  /**
   * {@inheritDoc}
   */
  public boolean isScriptFriendly() {
    return argParser.isScriptFriendly();
  }
  /**
   * {@inheritDoc}
   */
  public boolean isVerbose() {
    return true;
  }
}
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -36,6 +36,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.opends.server.admin.client.cli.SecureConnectionCliParser;
import org.opends.server.tools.ToolConstants;
import org.opends.server.util.args.Argument;
@@ -120,6 +121,16 @@
  }
  /**
   * Returns the SecureConnectionCliArgs object containing the arguments
   * of this parser.
   * @return the SecureConnectionCliArgs object containing the arguments
   * of this parser.
   */
  SecureConnectionCliArgs getSecureArgsList()
  {
    return secureArgsList;
  }
  /**
   * Tells whether the user specified to have an interactive uninstall or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have an interactive
opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -552,10 +552,6 @@
MILD_ERR_ERROR_CONNECTING_TO_SERVER_PROMPT_AGAIN=Could not connect to the \
 Directory Server %s with the provided credentials.%nError details: %s%n%n\
 Provide again the required information to connect to the server:
MILD_ERR_STATUS_CLI_ERROR_CONNECTING_PROMPT_AGAIN=Could not connect to the \
 Directory Server with the provided credentials.%nError details: %s%nProvide \
 again the required information to connect to the server:
SEVERE_ERR_STATUS_CLI_TOO_MANY_CONNECTION_ATTEMPT=Too many authentication failures - Exit
INFO_REPLICATION_ENABLE_HOSTNAME1_PROMPT=Host name of the first server
INFO_REPLICATION_ENABLE_PORT1_PROMPT=LDAP port of the first server
INFO_REPLICATION_ENABLE_REPLICATIONPORT1_PROMPT=Replication port for the first \
@@ -602,7 +598,6 @@
 the destination server?
INFO_REPLICATION_INITIALIZE_USESTARTTLSDESTINATION_PROMPT=Use StartTLS to \
 connect to the destination server?
INFO_CLI_BINDDN_PROMPT=Bind DN
INFO_CLI_USESSL_PROMPT=Use SSL to connect?
INFO_CLI_INVALID_PORT=The provided value is not a valid port
INFO_CLI_USESTARTTLS_PROMPT=Use StartTLS to connect?
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplicationHelper.java
@@ -864,20 +864,7 @@
  protected ConnectionProtocolPolicy getConnectionPolicy(boolean useSSL,
      boolean useStartTLS)
  {
    ConnectionProtocolPolicy policy;
    if (useStartTLS)
    {
      policy = ConnectionProtocolPolicy.USE_STARTTLS;
    }
    else if (useSSL)
    {
      policy = ConnectionProtocolPolicy.USE_LDAPS;
    }
    else
    {
      policy = ConnectionProtocolPolicy.USE_LESS_SECURE_AVAILABLE;
    }
    return policy;
    return ConnectionProtocolPolicy.getConnectionPolicy(useSSL, useStartTLS);
  }
  /**
opendj-sdk/opends/src/server/org/opends/server/tools/ToolConstants.java
@@ -902,5 +902,11 @@
   * Value placeholder for options taking actions.
   */
  public static final String OPTION_VALUE_ACTION = "{action}";
  /**
   * The default separator to be used in tables.
   */
  public static final String LIST_TABLE_SEPARATOR = ":";
}
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/CreateSubCommandHandler.java
@@ -77,6 +77,7 @@
import org.opends.server.admin.condition.ContainsCondition;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.ToolConstants;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.SubCommand;
@@ -285,7 +286,7 @@
      TextTablePrinter printer = new TextTablePrinter(app.getErrorStream());
      printer.setColumnWidth(1, 0);
      printer.setColumnSeparator(":");
      printer.setColumnSeparator(ToolConstants.LIST_TABLE_SEPARATOR);
      builder.print(printer);
      app.println();
      app.pressReturnToContinue();
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/GetPropSubCommandHandler.java
@@ -62,6 +62,7 @@
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.ToolConstants;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.SubCommand;
@@ -295,7 +296,7 @@
      builder.print(printer);
    } else {
      TextTablePrinter printer = new TextTablePrinter(out);
      printer.setColumnSeparator(":");
      printer.setColumnSeparator(ToolConstants.LIST_TABLE_SEPARATOR);
      printer.setColumnWidth(1, 0);
      builder.print(printer);
    }
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/LDAPManagementContextFactory.java
@@ -84,11 +84,40 @@
    // Lazily create the LDAP management context.
    if (context == null)
    {
      // Interact with the user though the console to get
      // LDAP connection information
      LDAPConnectionConsoleInteraction ci =
              new LDAPConnectionConsoleInteraction(app, secureArgsList);
      ci.run();
      context = getManagementContext(app, ci);
    }
    return context;
  }
  /**
   * Gets the management context which sub-commands should use in
   * order to manage the directory server. Implementations can use the
   * application instance for retrieving passwords interactively.
   *
   * @param app
   *          The application instance.
   * @param ci the LDAPConsoleInteraction object to be used.  The code assumes
   *        that the LDAPConsoleInteraction has already been run.
   * @return Returns the management context which sub-commands should
   *         use in order to manage the directory server.
   * @throws ArgumentException
   *           If a management context related argument could not be
   *           parsed successfully.
   * @throws ClientException
   *           If the management context could not be created.
   */
  public ManagementContext getManagementContext(ConsoleApplication app,
      LDAPConnectionConsoleInteraction ci)
      throws ArgumentException, ClientException
  {
    // Lazily create the LDAP management context.
    if (context == null)
    {
      // Interact with the user though the console to get
      // LDAP connection information
      String hostName = ci.getHostName();
      Integer portNumber = ci.getPortNumber();
      String bindDN = ci.getBindDN();
opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ListSubCommandHandler.java
@@ -54,6 +54,7 @@
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.ToolConstants;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.args.StringArgument;
import org.opends.server.util.args.SubCommand;
@@ -385,7 +386,7 @@
        }
        TextTablePrinter printer = new TextTablePrinter(out);
        printer.setColumnSeparator(":");
        printer.setColumnSeparator(ToolConstants.LIST_TABLE_SEPARATOR);
        builder.print(printer);
      }
    }
opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -263,7 +263,23 @@
  public void run()
          throws ArgumentException
  {
    boolean secureConnection =
    run(true, true);
  }
  /**
   * Interact with the user though the console to get information
   * necessary to establish an LDAP connection.
   * @param canUseSSL whether we can propose to connect using SSL or not.
   * @param canUseStartTLS whether we can propose to connect using Start TLS or
   * not.
   *
   * @throws ArgumentException if there is a problem with the arguments
   */
  public void run(boolean canUseSSL, boolean canUseStartTLS)
          throws ArgumentException
  {
    boolean secureConnection = (canUseSSL || canUseStartTLS) &&
      (
          secureArgsList.useSSLArg.isPresent()
          ||
@@ -382,6 +398,14 @@
        {
          continue ;
        }
        if (!canUseSSL && p.equals(Protocols.SSL))
        {
          continue;
        }
        if (!canUseStartTLS && p.equals(Protocols.START_TLS))
        {
          continue;
        }
        int i = builder.addNumberedOption(p.getMenuMessage(), MenuResult
            .success(p.getChoice()));
        if (p.equals(defaultProtocol))
@@ -1083,6 +1107,16 @@
  }
  /**
   * Sets the port number name that should be used for connections based on
   * this interaction.
   *
   * @param portNumber port number for connections
   */
  public void setPortNumber(int portNumber) {
    this.portNumber = portNumber;
  }
  /**
   * Gets the bind DN name that should be used for connections based on
   * this interaction.
   *