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

jvergara
18.46.2009 d780c3e5eacc6278222a767913c4414e116becb4
Fix for issue 3256 (Add certificate settings options in setup CLI)
When the user chooses to generate a self-signed certificate in the command-line setup, prompt to provide the host name that will be used to generate the certificate.
3 files modified
53 ■■■■■ changed files
opends/src/messages/messages/tools.properties 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 37 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java 10 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties
@@ -2540,4 +2540,10 @@
 argument '%s'
INFO_DESCRIPTION_SUBENTRIES_1702=Use subentries control to specify that \
 subentries are visible and normal entries are not
INFO_INSTALLDS_DESCRIPTION_HOST_NAME_1703=Directory server host name or IP \
 address that will be used to generate the self-signed certificate.  This \
 argument will be taken into account only if the self-signed certificate \
 argument %s is specified
INFO_INSTALLDS_PROMPT_HOST_NAME_1704=Provide the fully-qualified host name or \
 IP address that will be used to generate the self-signed certificate
opends/src/server/org/opends/server/tools/InstallDS.java
@@ -949,6 +949,7 @@
    }
    SecurityOptions securityOptions;
    LinkedList<String> keystoreAliases = new LinkedList<String>();
    uData.setHostName(argParser.hostNameArg.getValue());
    if (argParser.generateSelfSignedCertificateArg.isPresent())
    {
      securityOptions = SecurityOptions.createSelfSignedCertificateOptions(
@@ -1739,6 +1740,8 @@
    {
      securityOptions = SecurityOptions.createSelfSignedCertificateOptions(
          enableSSL, enableStartTLS, ldapsPort);
      String hostName = promptForHostNameIfRequired();
      uData.setHostName(hostName);
    }
    else if (argParser.useJavaKeyStoreArg.isPresent())
    {
@@ -1850,6 +1853,8 @@
        }
        if (certType == SELF_SIGNED)
        {
          String hostName = promptForHostNameIfRequired();
          uData.setHostName(hostName);
          securityOptions = SecurityOptions.createSelfSignedCertificateOptions(
                enableSSL, enableStartTLS, ldapsPort);
        }
@@ -2711,4 +2716,36 @@
      LOG.log(Level.WARNING, "Error resetting arguments: "+t, t);
    }
  }
  private String promptForHostNameIfRequired() throws UserDataException
  {
    String hostName = null;
    if (argParser.hostNameArg.isPresent())
    {
      hostName = argParser.hostNameArg.getValue();
    }
    else
    {
      int nTries = 0;
      while (hostName == null)
      {
        if (nTries >= CONFIRMATION_MAX_TRIES)
        {
          throw new UserDataException(null,
              ERR_TRIES_LIMIT_REACHED.get(CONFIRMATION_MAX_TRIES));
        }
        try
        {
          hostName = readInput(INFO_INSTALLDS_PROMPT_HOST_NAME.get(),
              argParser.hostNameArg.getDefaultValue());
        }
        catch (CLIException ce)
        {
          LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
        }
      }
    }
    return hostName;
  }
}
opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
@@ -75,6 +75,7 @@
  BooleanArgument   doNotStartArg;
  BooleanArgument   enableStartTLSArg;
  BooleanArgument   generateSelfSignedCertificateArg;
  StringArgument    hostNameArg;
  BooleanArgument   usePkcs11Arg;
  FileBasedArgument directoryManagerPwdFileArg;
  FileBasedArgument keyStorePasswordFileArg;
@@ -351,6 +352,15 @@
        "generateSelfSignedCertificate");
    addArgument(generateSelfSignedCertificateArg);
    hostNameArg = new StringArgument(OPTION_LONG_HOST.toLowerCase(),
        OPTION_SHORT_HOST,
        OPTION_LONG_HOST, false, false, true, INFO_HOST_PLACEHOLDER.get(),
        UserData.getDefaultHostName(),
        null, INFO_INSTALLDS_DESCRIPTION_HOST_NAME.get(
            generateSelfSignedCertificateArg.getLongIdentifier()));
    hostNameArg.setPropertyName(OPTION_LONG_HOST);
    addArgument(hostNameArg);
    usePkcs11Arg = new BooleanArgument("usePkcs11Keystore".toLowerCase(),
        null, "usePkcs11Keystore",
        INFO_INSTALLDS_DESCRIPTION_USE_PKCS11.get());