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

Jean-Noël Rouvignac
26.30.2016 310df200f78f7d98cc52e4ab97d8a5feb744fa52
opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
@@ -18,15 +18,16 @@
import static com.forgerock.opendj.cli.ArgumentConstants.*;
import static com.forgerock.opendj.cli.Utils.*;
import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*;
import static org.forgerock.util.Utils.*;
import static org.opends.messages.ToolMessages.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.INFO_ERROR_READING_SERVER_CONFIGURATION;
import static org.opends.messages.QuickSetupMessages.INFO_NOT_AVAILABLE_LABEL;
import static org.opends.messages.ToolMessages.*;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
@@ -106,9 +107,9 @@
  private boolean displayMustStartLegend;
  /** Prefix for log files. */
  public static final String LOG_FILE_PREFIX = "opendj-status-";
  private static final String LOG_FILE_PREFIX = "opendj-status-";
  /** Suffix for log files. */
  public static final String LOG_FILE_SUFFIX = ".log";
  private static final String LOG_FILE_SUFFIX = ".log";
  private ApplicationTrustManager interactiveTrustManager;
  private boolean useInteractiveTrustManager;
@@ -123,10 +124,8 @@
   *          The print stream to use for standard output.
   * @param err
   *          The print stream to use for standard error.
   * @param in
   *          The input stream to use for standard input.
   */
  public StatusCli(PrintStream out, PrintStream err, InputStream in)
  private StatusCli(PrintStream out, PrintStream err)
  {
    super(out, err);
  }
@@ -138,7 +137,7 @@
   */
  public static void main(String[] args)
  {
    int retCode = mainCLI(args, true, System.out, System.err, System.in);
    int retCode = mainCLI(args, System.out, System.err);
    if(retCode != 0)
    {
      System.exit(retCode);
@@ -146,39 +145,20 @@
  }
  /**
   * Parses the provided command-line arguments and uses that information to
   * run the status tool.
   *
   * @param args the command-line arguments provided to this program.
   *
   * @return The return code.
   */
  public static int mainCLI(String[] args)
  {
    return mainCLI(args, true, System.out, System.err, System.in);
  }
  /**
   * Parses the provided command-line arguments and uses that information to run
   * the status tool.
   *
   * @param args
   *          The command-line arguments provided to this program.
   * @param initializeServer
   *          Indicates whether to initialize the server.
   * @param outStream
   *          The output stream to use for standard output, or {@code null}
   *          if standard output is not needed.
   * @param errStream
   *          The output stream to use for standard error, or {@code null}
   *          if standard error is not needed.
   * @param inStream
   *          The input stream to use for standard input.
   * @return The return code.
   */
  public static int mainCLI(String[] args, boolean initializeServer,
      OutputStream outStream, OutputStream errStream, InputStream inStream)
  public static int mainCLI(String[] args, OutputStream outStream, OutputStream errStream)
  {
    PrintStream out = NullOutputStream.wrapOrNullStream(outStream);
    PrintStream err = NullOutputStream.wrapOrNullStream(errStream);
@@ -192,7 +172,7 @@
      t.printStackTrace();
    }
    final StatusCli statusCli = new StatusCli(out, err, inStream);
    final StatusCli statusCli = new StatusCli(out, err);
    int retCode = statusCli.execute(args);
    if (retCode == 0)
    {
@@ -209,7 +189,7 @@
   *          The command-line arguments provided to this program.
   * @return The return code of the process.
   */
  public int execute(String[] args) {
  private int execute(String[] args) {
    argParser = new StatusCliArgumentParser(StatusCli.class.getName());
    try {
      argParser.initializeGlobalArguments(getOutputStream());
@@ -261,8 +241,6 @@
      String bindDn = null;
      String bindPwd = null;
      ManagementContext mContext = null;
      // This is done because we do not need to ask the user about these
      // parameters. We force their presence in the
      // LDAPConnectionConsoleInteraction, this done, it will not prompt
@@ -301,6 +279,8 @@
        argParser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject());
        return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
      }
      boolean managementContextOpened = false;
      try
      {
        if (argParser.isInteractive())
@@ -315,19 +295,24 @@
        }
        if (bindPwd != null && !bindPwd.isEmpty())
        {
          mContext = getManagementContextFromConnection(ci);
          interactiveTrustManager = ci.getTrustManager();
          controlInfo.setTrustManager(interactiveTrustManager);
          useInteractiveTrustManager = true;
          try (ManagementContext mContext = getManagementContextFromConnection(ci))
          {
            managementContextOpened = true;
            interactiveTrustManager = ci.getTrustManager();
            controlInfo.setTrustManager(interactiveTrustManager);
            useInteractiveTrustManager = true;
          }
          catch (IOException e)
          {
            logger.traceException(e);
          }
        }
      } catch (ClientException e) {
        println(e.getMessageObject());
        return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
      } finally {
        closeSilently(mContext);
      }
      if (mContext != null)
      if (managementContextOpened)
      {
        try (ConnectionWrapper conn = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd))
        {