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

Jean-Noel Rouvignac
04.51.2014 ca8147aeff4b18e95d0782d4d5b4a049ec3f3813
Code cleanup.

Utils.java, SetupUtils.java:
Renamed isPriviledgedPort() to isPrivilegedPort().
6 files modified
702 ■■■■■ changed files
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/installer/Installer.java 23 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/installer/ui/SecurityOptionsDialog.java 59 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/util/Utils.java 147 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/InstallDS.java 436 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java 2 ●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/util/SetupUtils.java 35 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -142,7 +142,6 @@
 *
 * Note that we can use freely the class org.opends.server.util.SetupUtils as
 * it is included in quicksetup.jar.
 *
 */
public abstract class Installer extends GuiApplication {
@@ -289,7 +288,7 @@
          String sTimeout = userArguments[i+1];
          try
          {
            ud.setConnectTimeout(new Integer(sTimeout));
            ud.setConnectTimeout(Integer.valueOf(sTimeout));
          }
          catch (Throwable t)
          {
@@ -2406,9 +2405,7 @@
        int replicationId = replica.getReplicationId();
        if (replicationId == -1)
        {
          /**
           * This occurs if the remote server had not replication configured.
           */
          // This occurs if the remote server had not replication configured.
          InitialLdapContext rCtx = null;
          try
          {
@@ -3213,7 +3210,7 @@
  private LocalizableMessage getCannotBindErrorMessage(int port)
  {
    if (isPriviledgedPort(port))
    if (isPrivilegedPort(port))
    {
      return INFO_CANNOT_BIND_PRIVILEDGED_PORT.get(port);
    }
@@ -3982,22 +3979,16 @@
  }
  /**
   * Update the userData object according to the content of the runtime options
   * panel.
   */
  /** Update the userData object according to the content of the runtime options panel. */
  private void updateUserDataForRuntimeOptionsPanel(QuickSetup qs)
  {
    getUserData().setJavaArguments(UserData.SERVER_SCRIPT_NAME,
        ((JavaArguments)qs.getFieldValue(FieldName.SERVER_JAVA_ARGUMENTS)));
        (JavaArguments) qs.getFieldValue(FieldName.SERVER_JAVA_ARGUMENTS));
    getUserData().setJavaArguments(UserData.IMPORT_SCRIPT_NAME,
        ((JavaArguments)qs.getFieldValue(FieldName.IMPORT_JAVA_ARGUMENTS)));
        (JavaArguments) qs.getFieldValue(FieldName.IMPORT_JAVA_ARGUMENTS));
  }
  /**
   * Update the userData object according to the content of the review
   * panel.
   */
  /** Update the userData object according to the content of the review panel. */
  private void updateUserDataForReviewPanel(QuickSetup qs)
  {
    Boolean b = (Boolean) qs.getFieldValue(FieldName.SERVER_START_INSTALLER);
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/installer/ui/SecurityOptionsDialog.java
@@ -674,11 +674,8 @@
      public ArrayList<LocalizableMessage> processBackgroundTask()
      {
        ArrayList<LocalizableMessage> errorMsgs = new ArrayList<LocalizableMessage>();
        errorMsgs.addAll(checkPort());
        errorMsgs.addAll(checkKeystore());
        return errorMsgs;
      }
@@ -706,45 +703,42 @@
            displayError(Utils.getMessageFromCollection(returnValue, "\n"),
                INFO_ERROR_TITLE.get());
          }
          else
          else if (rbUseExistingCertificate.isSelected()
              && (cbEnableSSL.isSelected() || cbEnableStartTLS.isSelected()))
          {
            if (rbUseExistingCertificate.isSelected() &&
                (cbEnableSSL.isSelected() || cbEnableStartTLS.isSelected()))
            if (!certificateHasAlias)
            {
              if (!certificateHasAlias)
              selectedAlias = null;
              isCanceled = false;
              dispose();
            }
            else if (aliases.length > 1)
            {
              if (aliasDlg == null)
              {
                selectedAlias = null;
                isCanceled = false;
                dispose();
                aliasDlg = new SelectAliasDialog(SecurityOptionsDialog.this);
              }
              else if (aliases.length > 1)
              {
                if (aliasDlg == null)
                {
                  aliasDlg = new SelectAliasDialog(SecurityOptionsDialog.this);
                }
                aliasDlg.display(aliases);
              aliasDlg.display(aliases);
                if (!aliasDlg.isCanceled())
                {
                  selectedAlias = aliasDlg.getSelectedAlias();
                  isCanceled = false;
                  dispose();
                }
              }
              else
              if (!aliasDlg.isCanceled())
              {
                selectedAlias = aliases[0];
                selectedAlias = aliasDlg.getSelectedAlias();
                isCanceled = false;
                dispose();
              }
            }
            else
            {
              selectedAlias = aliases[0];
              isCanceled = false;
              dispose();
            }
          }
          else
          {
            isCanceled = false;
            dispose();
          }
        }
      }
    };
@@ -911,16 +905,15 @@
      try
      {
        port = Integer.parseInt(sPort);
        if ((port < Installer.MIN_PORT_VALUE) ||
            (port > Installer.MAX_PORT_VALUE))
        if (port < Installer.MIN_PORT_VALUE
            || port > Installer.MAX_PORT_VALUE)
        {
          errorMsgs.add(INFO_INVALID_SECURE_PORT_VALUE_RANGE.get(
              Installer.MIN_PORT_VALUE, Installer.MAX_PORT_VALUE));
        }
        else if (!Utils.canUseAsPort(port))
        {
          if (Utils.isPriviledgedPort(port))
          if (Utils.isPrivilegedPort(port))
          {
            errorMsgs.add(INFO_CANNOT_BIND_PRIVILEDGED_PORT.get(port));
          }
@@ -928,9 +921,7 @@
          {
            errorMsgs.add(INFO_CANNOT_BIND_PORT.get(port));
          }
        }
      }
      catch (NumberFormatException nfe)
      {
@@ -961,7 +952,7 @@
      if (rbJKS.isSelected() || rbJCEKS.isSelected() || rbPKCS12.isSelected())
      {
        /* Check the path */
        if ((path == null) || (path.length() == 0))
        if (path == null || path.length() == 0)
        {
          errorMsgs.add(INFO_KEYSTORE_PATH_NOT_PROVIDED.get());
        }
@@ -1020,7 +1011,7 @@
            throw new IllegalStateException("No keystore type selected.");
          }
          aliases = certManager.getCertificateAliases();
          if ((aliases == null) || (aliases.length == 0))
          if (aliases == null || aliases.length == 0)
          {
            // Could not retrieve any certificate
            if (rbPKCS11.isSelected())
opendj3-server-dev/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -87,14 +87,12 @@
   * The class name that contains the control panel customizations for
   * products.
   */
  private final static String CUSTOMIZATION_CLASS_NAME =
  private static final String CUSTOMIZATION_CLASS_NAME =
    "org.opends.server.util.ReleaseDefinition";
  /**
   * The service name required by the JNLP downloader.
   */
  public static String JNLP_SERVICE_NAME = "javax.jnlp.DownloadService";
  /** The service name required by the JNLP downloader. */
  public final static String JNLP_SERVICE_NAME = "javax.jnlp.DownloadService";
  /**
   * Returns <CODE>true</CODE> if the provided port is free and we can use it,
@@ -109,15 +107,15 @@
  }
  /**
   * Returns <CODE>true</CODE> if the provided port is a priviledged port,
   * Returns <CODE>true</CODE> if the provided port is a privileged port,
   * <CODE>false</CODE> otherwise.
   * @param port the port we are analyzing.
   * @return <CODE>true</CODE> if the provided port is a priviledged port,
   * @return <CODE>true</CODE> if the provided port is a privileged port,
   * <CODE>false</CODE> otherwise.
   */
  public static boolean isPriviledgedPort(int port)
  public static boolean isPrivilegedPort(int port)
  {
    return SetupUtils.isPriviledgedPort(port);
    return SetupUtils.isPrivilegedPort(port);
  }
@@ -301,7 +299,7 @@
    boolean isDescendant = false;
    if (descendant != null && path != null) {
      File parent = descendant.getParentFile();
      while ((parent != null) && !isDescendant) {
      while (parent != null && !isDescendant) {
        isDescendant = path.equals(parent);
        if (!isDescendant) {
          parent = parent.getParentFile();
@@ -352,17 +350,13 @@
   */
  public static boolean directoryExistsAndIsNotEmpty(String path)
  {
    boolean directoryExistsAndIsNotEmpty = false;
    File f = new File(path);
    final File f = new File(path);
    if (f.isDirectory())
    {
      String[] ch = f.list();
      directoryExistsAndIsNotEmpty = (ch != null) && (ch.length > 0);
      final String[] ch = f.list();
      return ch != null && ch.length > 0;
    }
    return directoryExistsAndIsNotEmpty;
    return false;
  }
  /**
@@ -413,11 +407,11 @@
   * @return boolean indicating whether or not the input <code>f</code>
   * has a parent after this method is invoked.
   */
  static public boolean insureParentsExist(File f) {
    File parent = f.getParentFile();
    boolean b = parent.exists();
  public static boolean insureParentsExist(File f) {
    final File parent = f.getParentFile();
    final boolean b = parent.exists();
    if (!b) {
      b = parent.mkdirs();
      return parent.mkdirs();
    }
    return b;
  }
@@ -519,20 +513,14 @@
   */
  public static LocalizableMessage getMessageFromCollection(Collection<LocalizableMessage> col,
                                                 String separator) {
    LocalizableMessage message = null;
    if (col != null) {
      LocalizableMessageBuilder mb = null;
      final LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
      for (LocalizableMessage m : col) {
        if (mb == null) {
          mb = new LocalizableMessageBuilder(m);
        } else {
          mb.append(separator).append(m);
        }
        mb.append(separator).append(m);
      }
      if (mb == null) mb = new LocalizableMessageBuilder();
      message = mb.toMessage();
      return mb.toMessage();
    }
    return message;
    return null;
  }
  /**
@@ -934,7 +922,7 @@
   * update properly the progress bar ratio.
   * @return the number of entries contained in the zip file.
   */
  static public int getNumberZipEntries()
  public static int getNumberZipEntries()
  {
    // TODO  we should get this dynamically during build
    return 165;
@@ -951,7 +939,7 @@
   *        adding to the returned string.
   * @return String representing the list
   */
  static public String listToString(List<?> list, String separator,
  public static String listToString(List<?> list, String separator,
                                    String prefix, String suffix) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < list.size(); i++) {
@@ -974,32 +962,30 @@
   * @param file the file for which we want the file permissions.
   * @return the file system permissions for the file.
   */
  static public String getFileSystemPermissions(File file)
  public static String getFileSystemPermissions(File file)
  {
    String perm;
    String name = file.getName();
    if (file.getParent().endsWith(
        File.separator + Installation.WINDOWS_BINARIES_PATH_RELATIVE) ||
        file.getParent().endsWith(
        File.separator + Installation.UNIX_BINARIES_PATH_RELATIVE)) {
      if (name.endsWith(".bat")) {
        perm = "644";
        return "644";
      }
      else {
        perm = "755";
        return "755";
      }
    } else if (name.endsWith(".sh")) {
      perm = "755";
      return "755";
    } else if (name.endsWith(Installation.UNIX_SETUP_FILE_NAME) ||
            name.endsWith(Installation.UNIX_UNINSTALL_FILE_NAME) ||
            name.endsWith(Installation.UNIX_UPGRADE_FILE_NAME)) {
      perm = "755";
      return "755";
    } else if (name.endsWith(Installation.MAC_JAVA_APP_STUB_NAME)) {
      perm = "755";
      return "755";
    } else {
      perm = "644";
      return "644";
    }
    return perm;
  }
  /**
@@ -1016,12 +1002,14 @@
   * @return String representing <code>d</code> with HTML break
   *         tags inserted
   */
  static public String breakHtmlString(CharSequence cs, int maxll) {
  public static String breakHtmlString(CharSequence cs, int maxll) {
    if (cs != null) {
      String d = cs.toString();
      int len = d.length();
      if (len <= 0)
      {
        return d;
      }
      if (len > maxll) {
        // First see if there are any tags that would cause a
@@ -1066,7 +1054,7 @@
   * @param s string to convert
   * @return converted string
   */
  static public String convertHtmlBreakToLineSeparator(String s) {
  public static String convertHtmlBreakToLineSeparator(String s) {
    return s.replaceAll("<br>", Constants.LINE_SEPARATOR);
  }
@@ -1075,21 +1063,17 @@
   * @param s string to strip
   * @return resulting string
   */
  static public String stripHtml(String s) {
    String o = null;
  public static String stripHtml(String s) {
    if (s != null) {
      // This is not a comprehensive solution but addresses
      // the few tags that we have in Resources.properties
      // at the moment.  Note that the following might strip
      // out more than is intended for non-tags like
      // '<your name here>' or for funky tags like
      // '<tag attr="1 > 0">'. See test class for cases that
      // might cause problems.
      o = s.replaceAll("<.*?>","");
      // This is not a comprehensive solution but addresses the few tags
      // that we have in Resources.properties at the moment.
      // Note that the following might strip out more than is intended for non-tags
      // like '<your name here>' or for funky tags like '<tag attr="1 > 0">'.
      // See test class for cases that might cause problems.
      return s.replaceAll("<.*?>","");
    }
    return o;
    return null;
  }
  /**
@@ -1097,7 +1081,7 @@
   * @param text String to test
   * @return true if the string contains HTML
   */
  static public boolean containsHtml(String text) {
  public static boolean containsHtml(String text) {
    return text != null && text.indexOf('<') != -1 && text.indexOf('>') != -1;
  }
@@ -1227,28 +1211,26 @@
   */
  public static boolean isLocalHost(String host)
  {
    boolean isLocalHost = false;
    if (!"localhost".equalsIgnoreCase(host))
    if ("localhost".equalsIgnoreCase(host))
    {
      try
      {
        InetAddress localAddress = InetAddress.getLocalHost();
        InetAddress[] addresses = InetAddress.getAllByName(host);
        for (int i=0; i<addresses.length && !isLocalHost; i++)
        {
          isLocalHost = localAddress.equals(addresses[i]);
      return true;
    }
    try
    {
      InetAddress localAddress = InetAddress.getLocalHost();
      InetAddress[] addresses = InetAddress.getAllByName(host);
      for (InetAddress address : addresses) {
        if (localAddress.equals(address)) {
          return true;
        }
      }
      catch (Throwable t)
      {
        logger.warn(LocalizableMessage.raw("Failing checking host names: "+t, t));
      }
    }
    else
    catch (Throwable t)
    {
      isLocalHost = true;
      logger.warn(LocalizableMessage.raw("Failing checking host names: " + t, t));
    }
    return isLocalHost;
    return false;
  }
  /**
@@ -1260,7 +1242,7 @@
   * representation.
   * @return the HTML representation of the plain text string.
   */
  static String escapeHtml(String rawString)
  private static String escapeHtml(String rawString)
  {
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < rawString.length(); i++)
@@ -1373,11 +1355,11 @@
      {
        insideTag = true;
      }
      else if ((c == '>') && insideTag)
      else if (c == '>' && insideTag)
      {
        insideTag = false;
      }
      if (!insideTag && (c != '>'))
      if (!insideTag && c != '>')
      {
        addedChars ++;
        totalAddedChars ++;
@@ -1612,8 +1594,8 @@
    return builder.toString();
  }
  //Chars that require special treatment when passing them to command-line.
  private final static char[] charsToEscape = {' ', '\t', '\n', '|', ';', '<',
  /** Chars that require special treatment when passing them to command-line. */
  private static final char[] charsToEscape = {' ', '\t', '\n', '|', ';', '<',
    '>', '(', ')', '$', '`', '\\', '"', '\''};
  /**
@@ -1988,8 +1970,7 @@
      {
        installDir = f.getAbsolutePath();
      }
      if (installDir.lastIndexOf(File.separatorChar) !=
        (installDir.length() - 1))
      if (installDir.lastIndexOf(File.separatorChar) != installDir.length() - 1)
      {
        installDir += File.separatorChar;
      }
@@ -2208,9 +2189,7 @@
    super(new ByteArrayOutputStream(), true);
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public void println(String msg)
  {
opendj3-server-dev/src/server/org/opends/server/tools/InstallDS.java
@@ -105,7 +105,7 @@
  private final PlainTextProgressMessageFormatter formatter =
    new PlainTextProgressMessageFormatter();
  /** Prefix for log files. */
  static public final String TMP_FILE_PREFIX = "opendj-setup-";
  public static final String TMP_FILE_PREFIX = "opendj-setup-";
  /** Suffix for log files. */
  public static final String LOG_FILE_SUFFIX = ".log";
@@ -183,13 +183,13 @@
   */
  private enum ConfirmCode
  {
    // Continue with the install
    /** Continue with the install. */
    CONTINUE(1),
    // Provide information again
    /** Provide information again. */
    PROVIDE_INFORMATION_AGAIN(2),
    // Display equivalent command-line
    /** Display equivalent command-line. */
    PRINT_EQUIVALENT_COMMAND_LINE(3),
    // Cancel the install
    /** Cancel the install. */
    CANCEL(3);
    private int returnCode;
@@ -215,28 +215,22 @@
   */
  public static final int LIMIT_KEYSTORE_PASSWORD_PROMPT = 7;
  // Different variables we use when the user decides to provide data again.
  private NewSuffixOptions.Type lastResetPopulateOption = null;
  /** Different variables we use when the user decides to provide data again. */
  private NewSuffixOptions.Type lastResetPopulateOption;
  private String lastResetImportFile = null;
  private String lastResetImportFile;
  private String lastResetRejectedFile;
  private String lastResetSkippedFile;
  private String lastResetRejectedFile = null;
  private Integer lastResetNumEntries;
  private Boolean lastResetEnableSSL;
  private Boolean lastResetEnableStartTLS;
  private String lastResetSkippedFile = null;
  private SecurityOptions.CertificateType lastResetCertType;
  private String lastResetKeyStorePath;
  private Integer lastResetNumEntries = null;
  private Boolean lastResetEnableSSL = null;
  private Boolean lastResetEnableStartTLS = null;
  private SecurityOptions.CertificateType lastResetCertType = null;
  private String lastResetKeyStorePath = null;
  private Boolean lastResetEnableWindowsService = null;
  private Boolean lastResetStartServer = null;
  private Boolean lastResetEnableWindowsService;
  private Boolean lastResetStartServer;
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -427,12 +421,12 @@
            try
            {
              String response = in.readLine();
              if ((response == null) || (response.equalsIgnoreCase(no))
                  || (response.equalsIgnoreCase(noShort))
                  || (response.length() == 0))
              if (response == null
                  || response.equalsIgnoreCase(no)
                  || response.equalsIgnoreCase(noShort)
                  || response.length() == 0)
              {
                return ErrorReturnCode.ERROR_LICENSE_NOT_ACCEPTED
                    .getReturnCode();
                return ErrorReturnCode.ERROR_LICENSE_NOT_ACCEPTED.getReturnCode();
              }
              else if (response.equalsIgnoreCase(yes)
                  || response.equalsIgnoreCase(yesShort))
@@ -641,52 +635,40 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isQuiet()
  {
    return argParser.quietArg.isPresent();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isInteractive()
  {
    return !argParser.noPromptArg.isPresent();
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isMenuDrivenMode() {
    return true;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isScriptFriendly() {
    return false;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isAdvancedMode() {
    return false;
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public boolean isVerbose() {
    return argParser.verboseArg.isPresent();
@@ -793,22 +775,14 @@
        errorMessages.add(ERR_INSTALLDS_NO_SUCH_LDIF_FILE.get(joinAsString(", ", nonExistingFiles)));
      }
      String rejectedFile = argParser.rejectedImportFileArg.getValue();
      if (rejectedFile != null)
      if (rejectedFile != null && !canWrite(rejectedFile))
      {
        if (!canWrite(rejectedFile))
        {
          errorMessages.add(
              ERR_INSTALLDS_CANNOT_WRITE_REJECTED.get(rejectedFile));
        }
        errorMessages.add(ERR_INSTALLDS_CANNOT_WRITE_REJECTED.get(rejectedFile));
      }
      String skippedFile = argParser.skippedImportFileArg.getValue();
      if (skippedFile != null)
      if (skippedFile != null && !canWrite(skippedFile))
      {
        if (!canWrite(skippedFile))
        {
          errorMessages.add(ERR_INSTALLDS_CANNOT_WRITE_SKIPPED.get(
              skippedFile));
        }
        errorMessages.add(ERR_INSTALLDS_CANNOT_WRITE_SKIPPED.get(skippedFile));
      }
      dataOptions = NewSuffixOptions.createImportFromLDIF(baseDNs,
          argParser.importLDIFArg.getValues(),
@@ -821,7 +795,7 @@
    else if (argParser.sampleDataArg.isPresent())
    {
      dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
          new Integer(argParser.sampleDataArg.getValue()));
          Integer.valueOf(argParser.sampleDataArg.getValue()));
    }
    else
    {
@@ -861,7 +835,7 @@
      String path = argParser.useJavaKeyStoreArg.getValue();
      checkCertificateInKeystore(SecurityOptions.CertificateType.JKS, path, pwd,
          certNickname, errorMessages, keystoreAliases);
      if ((certNickname == null) && !keystoreAliases.isEmpty())
      if (certNickname == null && !keystoreAliases.isEmpty())
      {
        certNickname = keystoreAliases.getFirst();
      }
@@ -873,7 +847,7 @@
      String path = argParser.useJCEKSArg.getValue();
      checkCertificateInKeystore(SecurityOptions.CertificateType.JCEKS, path,
          pwd, certNickname, errorMessages, keystoreAliases);
      if ((certNickname == null) && !keystoreAliases.isEmpty())
      if (certNickname == null && !keystoreAliases.isEmpty())
      {
        certNickname = keystoreAliases.getFirst();
      }
@@ -885,7 +859,7 @@
      String path = argParser.usePkcs12Arg.getValue();
      checkCertificateInKeystore(SecurityOptions.CertificateType.PKCS12, path,
          pwd, certNickname, errorMessages, keystoreAliases);
      if ((certNickname == null) && !keystoreAliases.isEmpty())
      if (certNickname == null && !keystoreAliases.isEmpty())
      {
        certNickname = keystoreAliases.getFirst();
      }
@@ -896,7 +870,7 @@
    {
      checkCertificateInKeystore(SecurityOptions.CertificateType.PKCS11, null,
          pwd, certNickname, errorMessages, keystoreAliases);
      if ((certNickname == null) && !keystoreAliases.isEmpty())
      if (certNickname == null && !keystoreAliases.isEmpty())
      {
        certNickname = keystoreAliases.getFirst();
      }
@@ -932,7 +906,7 @@
  private LocalizableMessage getCannotBindErrorMessage(int port)
  {
    if (SetupUtils.isPriviledgedPort(port))
    if (SetupUtils.isPrivilegedPort(port))
    {
      return ERR_INSTALLDS_CANNOT_BIND_TO_PRIVILEGED_PORT.get(port);
    }
@@ -995,7 +969,7 @@
      while (pwd1 == null)
      {
        pwd1 = readPassword(INFO_INSTALLDS_PROMPT_ROOT_PASSWORD.get());
        if ((pwd1 == null) || "".equals(pwd1))
        if (pwd1 == null || "".equals(pwd1))
        {
          pwd1 = null;
          println();
@@ -1197,31 +1171,26 @@
          usedProvided = true;
        }
        if (!argParser.skipPortCheckArg.isPresent())
        if (!argParser.skipPortCheckArg.isPresent()
            && !SetupUtils.canUseAsPort(portNumber))
        {
          if (!SetupUtils.canUseAsPort(portNumber))
          LocalizableMessage message = getCannotBindErrorMessage(portNumber);
          if (prompted || includeLineBreak)
          {
            LocalizableMessage message = getCannotBindErrorMessage(portNumber);
            if (prompted || includeLineBreak)
            {
              println();
            }
            println(message);
            if (!SetupUtils.isPriviledgedPort(portNumber))
            {
              println();
            }
            portNumber = -1;
          }
        }
        if (portNumber != -1)
        {
          if (usedPorts.contains(portNumber))
          {
            println(ERR_CONFIGDS_PORT_ALREADY_SPECIFIED.get(portNumber));
            println();
            portNumber = -1;
          }
          println(message);
          if (!SetupUtils.isPrivilegedPort(portNumber))
          {
            println();
          }
          portNumber = -1;
        }
        if (portNumber != -1 && usedPorts.contains(portNumber))
        {
          println(ERR_CONFIGDS_PORT_ALREADY_SPECIFIED.get(portNumber));
          println();
          portNumber = -1;
        }
      }
      catch (ArgumentException ae)
@@ -1536,13 +1505,13 @@
      {
        LocalizableMessage message = INFO_INSTALLDS_PROMPT_NUM_ENTRIES.get();
        int defaultValue;
        if (lastResetNumEntries == null)
        if (lastResetNumEntries != null)
        {
          defaultValue = 2000;
          defaultValue = lastResetNumEntries;
        }
        else
        {
          defaultValue = lastResetNumEntries;
          defaultValue = 2000;
        }
        int numUsers = promptForInteger(message, defaultValue, 0,
            Integer.MAX_VALUE);
@@ -1674,127 +1643,124 @@
        createSecurityOptionsPrompting(SecurityOptions.CertificateType.PKCS11,
            enableSSL, enableStartTLS, ldapsPort);
    }
    else if (!enableSSL && !enableStartTLS)
    {
      // If the user did not want to enable SSL or start TLS do not ask
      // to create a certificate.
      securityOptions = SecurityOptions.createNoCertificateOptions();
    }
    else
    {
      if (!enableSSL && !enableStartTLS)
      final int SELF_SIGNED = 1;
      final int JKS = 2;
      final int JCEKS = 3;
      final int PKCS12 = 4;
      final int PKCS11 = 5;
      int[] indexes = {SELF_SIGNED, JKS, JCEKS, PKCS12, PKCS11};
      LocalizableMessage[] msgs = {
          INFO_INSTALLDS_CERT_OPTION_SELF_SIGNED.get(),
          INFO_INSTALLDS_CERT_OPTION_JKS.get(),
          INFO_INSTALLDS_CERT_OPTION_JCEKS.get(),
          INFO_INSTALLDS_CERT_OPTION_PKCS12.get(),
          INFO_INSTALLDS_CERT_OPTION_PKCS11.get()
      };
      MenuBuilder<Integer> builder = new MenuBuilder<Integer>(this);
      builder.setPrompt(INFO_INSTALLDS_HEADER_CERT_TYPE.get());
      for (int i=0; i<indexes.length; i++)
      {
        // If the user did not want to enable SSL or start TLS do not ask
        // to create a certificate.
        securityOptions = SecurityOptions.createNoCertificateOptions();
        builder.addNumberedOption(msgs[i], MenuResult.success(indexes[i]));
      }
      if (lastResetCertType == null)
      {
        builder.setDefault(LocalizableMessage.raw(String.valueOf(SELF_SIGNED)),
          MenuResult.success(SELF_SIGNED));
      }
      else
      {
        final int SELF_SIGNED = 1;
        final int JKS = 2;
        final int JCEKS = 3;
        final int PKCS12 = 4;
        final int PKCS11 = 5;
        int[] indexes = {SELF_SIGNED, JKS, JCEKS, PKCS12, PKCS11};
        LocalizableMessage[] msgs = {
            INFO_INSTALLDS_CERT_OPTION_SELF_SIGNED.get(),
            INFO_INSTALLDS_CERT_OPTION_JKS.get(),
            INFO_INSTALLDS_CERT_OPTION_JCEKS.get(),
            INFO_INSTALLDS_CERT_OPTION_PKCS12.get(),
            INFO_INSTALLDS_CERT_OPTION_PKCS11.get()
        };
        MenuBuilder<Integer> builder = new MenuBuilder<Integer>(this);
        builder.setPrompt(INFO_INSTALLDS_HEADER_CERT_TYPE.get());
        for (int i=0; i<indexes.length; i++)
        switch (lastResetCertType)
        {
          builder.addNumberedOption(msgs[i], MenuResult.success(indexes[i]));
        }
        if (lastResetCertType == null)
        {
        case JKS:
          builder.setDefault(LocalizableMessage.raw(String.valueOf(JKS)),
              MenuResult.success(JKS));
          break;
        case JCEKS:
          builder.setDefault(LocalizableMessage.raw(String.valueOf(JCEKS)),
              MenuResult.success(JCEKS));
          break;
        case PKCS11:
          builder.setDefault(LocalizableMessage.raw(String.valueOf(PKCS11)),
              MenuResult.success(PKCS11));
          break;
        case PKCS12:
          builder.setDefault(LocalizableMessage.raw(String.valueOf(PKCS12)),
              MenuResult.success(PKCS12));
          break;
        default:
          builder.setDefault(LocalizableMessage.raw(String.valueOf(SELF_SIGNED)),
            MenuResult.success(SELF_SIGNED));
              MenuResult.success(SELF_SIGNED));
        }
        else
        {
          switch (lastResetCertType)
          {
          case JKS:
            builder.setDefault(LocalizableMessage.raw(String.valueOf(JKS)),
                MenuResult.success(JKS));
            break;
          case JCEKS:
            builder.setDefault(LocalizableMessage.raw(String.valueOf(JCEKS)),
                MenuResult.success(JCEKS));
            break;
          case PKCS11:
            builder.setDefault(LocalizableMessage.raw(String.valueOf(PKCS11)),
                MenuResult.success(PKCS11));
            break;
          case PKCS12:
            builder.setDefault(LocalizableMessage.raw(String.valueOf(PKCS12)),
                MenuResult.success(PKCS12));
            break;
          default:
            builder.setDefault(LocalizableMessage.raw(String.valueOf(SELF_SIGNED)),
                MenuResult.success(SELF_SIGNED));
          }
        }
      }
        Menu<Integer> menu = builder.toMenu();
        int certType;
        try
      Menu<Integer> menu = builder.toMenu();
      int certType;
      try
      {
        MenuResult<Integer> m = menu.run();
        if (m.isSuccess())
        {
          MenuResult<Integer> m = menu.run();
          if (m.isSuccess())
          {
            certType = m.getValue();
          }
          else
          {
            // Should never happen.
            throw new RuntimeException();
          }
        }
        catch (ClientException ce)
        {
          logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
          certType = SELF_SIGNED;
        }
        if (certType == SELF_SIGNED)
        {
          securityOptions = SecurityOptions.createSelfSignedCertificateOptions(
                enableSSL, enableStartTLS, ldapsPort);
        }
        else if (certType == JKS)
        {
          securityOptions =
            createSecurityOptionsPrompting(SecurityOptions.CertificateType.JKS,
                enableSSL, enableStartTLS, ldapsPort);
        }
        else if (certType == JCEKS)
        {
          securityOptions =
            createSecurityOptionsPrompting(
                SecurityOptions.CertificateType.JCEKS,
                enableSSL, enableStartTLS, ldapsPort);
        }
        else if (certType == PKCS12)
        {
          securityOptions =
            createSecurityOptionsPrompting(
                SecurityOptions.CertificateType.PKCS12, enableSSL,
                enableStartTLS, ldapsPort);
        }
        else if (certType == PKCS11)
        {
          securityOptions =
            createSecurityOptionsPrompting(
                SecurityOptions.CertificateType.PKCS11, enableSSL,
                enableStartTLS, ldapsPort);
          certType = m.getValue();
        }
        else
        {
          throw new IllegalStateException("Unexpected cert type: "+ certType);
          // Should never happen.
          throw new RuntimeException();
        }
      }
      catch (ClientException ce)
      {
        logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
        certType = SELF_SIGNED;
      }
      if (certType == SELF_SIGNED)
      {
        securityOptions = SecurityOptions.createSelfSignedCertificateOptions(
              enableSSL, enableStartTLS, ldapsPort);
      }
      else if (certType == JKS)
      {
        securityOptions =
          createSecurityOptionsPrompting(SecurityOptions.CertificateType.JKS,
              enableSSL, enableStartTLS, ldapsPort);
      }
      else if (certType == JCEKS)
      {
        securityOptions =
          createSecurityOptionsPrompting(
              SecurityOptions.CertificateType.JCEKS,
              enableSSL, enableStartTLS, ldapsPort);
      }
      else if (certType == PKCS12)
      {
        securityOptions =
          createSecurityOptionsPrompting(
              SecurityOptions.CertificateType.PKCS12, enableSSL,
              enableStartTLS, ldapsPort);
      }
      else if (certType == PKCS11)
      {
        securityOptions =
          createSecurityOptionsPrompting(
              SecurityOptions.CertificateType.PKCS11, enableSSL,
              enableStartTLS, ldapsPort);
      }
      else
      {
        throw new IllegalStateException("Unexpected cert type: "+ certType);
      }
    }
    return securityOptions;
  }
@@ -1938,7 +1904,7 @@
            throw new IllegalArgumentException("Invalid type: "+type);
        }
        String[] aliases = certManager.getCertificateAliases();
        if ((aliases == null) || (aliases.length == 0))
        if (aliases == null || aliases.length == 0)
        {
          // Could not retrieve any certificate
          switch (type)
@@ -2039,12 +2005,9 @@
    String path;
    String certNickname = argParser.certNicknameArg.getValue();
    String pwd = argParser.getKeyStorePassword();
    if (pwd != null)
    if (pwd != null && pwd.length() == 0)
    {
      if (pwd.length() == 0)
      {
        pwd = null;
      }
      pwd = null;
    }
    LocalizableMessage pathPrompt;
    String defaultPathValue;
@@ -2092,7 +2055,7 @@
    boolean firstTry = true;
    int nPasswordPrompts = 0;
    while ((errorMessages.size() > 0) || firstTry)
    while (errorMessages.size() > 0 || firstTry)
    {
      boolean prompted = false;
      if (errorMessages.size() > 0)
@@ -2102,38 +2065,35 @@
            formatter.getLineBreak().toString()));
      }
      if (type != SecurityOptions.CertificateType.PKCS11)
      if (type != SecurityOptions.CertificateType.PKCS11
          && (containsKeyStorePathErrorMessage(errorMessages) || path == null))
      {
        if (containsKeyStorePathErrorMessage(errorMessages) || (path == null))
        println();
        try
        {
          println();
          try
          {
            path = readInput(pathPrompt, defaultPathValue);
          }
          catch (ClientException ce)
          {
            path = "";
            logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
          }
          path = readInput(pathPrompt, defaultPathValue);
        }
        catch (ClientException ce)
        {
          path = "";
          logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
        }
          prompted = true;
          if (pwd != null)
        prompted = true;
        if (pwd != null)
        {
          errorMessages.clear();
          keystoreAliases.clear();
          checkCertificateInKeystore(type, path, pwd, certNickname,
              errorMessages, keystoreAliases);
          if (!errorMessages.isEmpty())
          {
            errorMessages.clear();
            keystoreAliases.clear();
            checkCertificateInKeystore(type, path, pwd, certNickname,
                errorMessages, keystoreAliases);
            if (!errorMessages.isEmpty())
            {
              // Reset password: this might be a new keystore
              pwd = null;
            }
            // Reset password: this might be a new keystore
            pwd = null;
          }
        }
      }
      if (containsKeyStorePasswordErrorMessage(errorMessages) ||
          (pwd == null))
      if (containsKeyStorePasswordErrorMessage(errorMessages) || pwd == null)
      {
        if (!prompted)
        {
@@ -2165,7 +2125,7 @@
          keystoreAliases);
      firstTry = false;
    }
    if ((certNickname == null) && !keystoreAliases.isEmpty())
    if (certNickname == null && !keystoreAliases.isEmpty())
    {
      certNickname = keystoreAliases.getFirst();
    }
@@ -2325,12 +2285,11 @@
        s = "";
        logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
      }
      if (s.equals(""))
      if ("".equals(s))
      {
        if (defaultValue == null)
        {
          LocalizableMessage message = ERR_INSTALLDS_INVALID_INTEGER_RESPONSE.get();
          println(message);
          println(ERR_INSTALLDS_INVALID_INTEGER_RESPONSE.get());
          println();
        }
        else
@@ -2343,18 +2302,14 @@
        try
        {
          int intValue = Integer.parseInt(s);
          if ((lowerBound != null) && (intValue < lowerBound))
          if (lowerBound != null && intValue < lowerBound)
          {
            LocalizableMessage message =
                ERR_INSTALLDS_INTEGER_BELOW_LOWER_BOUND.get(lowerBound);
            println(message);
            println(ERR_INSTALLDS_INTEGER_BELOW_LOWER_BOUND.get(lowerBound));
            println();
          }
          else if ((upperBound != null) && (intValue > upperBound))
          else if (upperBound != null && intValue > upperBound)
          {
            LocalizableMessage message =
                ERR_INSTALLDS_INTEGER_ABOVE_UPPER_BOUND.get(upperBound);
            println(message);
            println(ERR_INSTALLDS_INTEGER_ABOVE_UPPER_BOUND.get(upperBound));
            println();
          }
          else
@@ -2364,8 +2319,7 @@
        }
        catch (NumberFormatException nfe)
        {
          LocalizableMessage message = ERR_INSTALLDS_INVALID_INTEGER_RESPONSE.get();
          println(message);
          println(ERR_INSTALLDS_INVALID_INTEGER_RESPONSE.get());
          println();
        }
      }
@@ -2446,7 +2400,7 @@
      if (values[i] != null)
      {
        LocalizableMessage l = labels[i];
        sb.append(l.toString()).append(" ");
        sb.append(l).append(" ");
        String[] lines = values[i].toString().split(Constants.LINE_SEPARATOR);
        for (int j=0; j<lines.length; j++)
opendj3-server-dev/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -8043,7 +8043,7 @@
   */
  private LocalizableMessage getCannotBindToPortError(int port)
  {
    if (SetupUtils.isPriviledgedPort(port))
    if (SetupUtils.isPrivilegedPort(port))
    {
      return ERR_CANNOT_BIND_TO_PRIVILEGED_PORT.get(port);
    }
opendj3-server-dev/src/server/org/opends/server/util/SetupUtils.java
@@ -113,7 +113,7 @@
  public static final String POINT_VERSION = "Point Version";
  /** Revision number in SVN. */
  public static final String REVISION_NUMBER = "Revision Number";
  /** the SVN url repository. */
  /** The SVN url repository. */
  public static final String URL_REPOSITORY = "URL Repository";
  /** The version qualifier. */
  public static final String VERSION_QUALIFIER = "Version Qualifier";
@@ -207,7 +207,7 @@
      }
    }
    if (!baseDNs.isEmpty() && (numEntries > 0))
    if (!baseDNs.isEmpty() && numEntries > 0)
    {
      lines.add("template: person");
      lines.add("rdnAttr: uid");
@@ -347,9 +347,9 @@
   * @return {@code true} if the provided port is a privileged port,
   * {@code false} otherwise.
   */
  public static boolean isPriviledgedPort(int port)
  public static boolean isPrivilegedPort(int port)
  {
    return (port <= 1024) && !OperatingSystem.isWindows();
    return port <= 1024 && !OperatingSystem.isWindows();
  }
  /**
@@ -373,15 +373,10 @@
  public static String getScriptPath(String script)
  {
    String s = script;
    if (OperatingSystem.isWindows())
    if (OperatingSystem.isWindows()
        && s != null && (!s.startsWith("\"") || !s.endsWith("\"")))
    {
      if (s != null)
      {
        if (!s.startsWith("\"") || !s.endsWith("\""))
        {
          s = "\""+script+"\"";
        }
      }
      return "\"" + script + "\"";
    }
    return s;
  }
@@ -472,8 +467,10 @@
    }
  }
  /* The next two methods are used to generate the random password for the
   * self-signed certificate. */
  /**
   * The next two methods are used to generate the random password for the
   * self-signed certificate.
   */
  private static char getRandomChar(Random random, int type)
  {
    char generatedChar;
@@ -487,7 +484,7 @@
      d = next % 10;
      if (d < 0)
      {
        d = d * (-1);
        d = d * -1;
      }
      generatedChar = (char) (d+48);
      break;
@@ -496,16 +493,16 @@
      d = next % 26;
      if (d < 0)
      {
        d = d * (-1);
        d = d * -1;
      }
      generatedChar =  (char) (d + 97);
      break;
    default:
      // Will return a capital letter
      d = (next % 26);
      d = next % 26;
      if (d < 0)
      {
        d = d * (-1);
        d = d * -1;
      }
      generatedChar = (char) (d + 65) ;
    }
@@ -515,7 +512,7 @@
  private static int getRandomInt(Random random,int modulo)
  {
    return (random.nextInt() & modulo);
    return random.nextInt() & modulo;
  }
  /**