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

jvergara
15.24.2008 f420f952326f7a82c7c18b7a21cc975c55e2ecfc
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -50,6 +50,7 @@
import static org.opends.quicksetup.util.Utils.*;
import org.opends.server.admin.client.ManagementContext;
import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.opends.server.core.DirectoryServer;
@@ -91,6 +92,8 @@
  private TrustManager interactiveTrustManager;
  private boolean useInteractiveTrustManager;
  /**
   * The enumeration containing the different return codes that the command-line
   * can have.
@@ -313,6 +316,7 @@
       */
      ConfigFromFile offLineConf = new ConfigFromFile();
      offLineConf.readConfiguration();
      boolean authProvided = false;
      try
      {
        if (isServerRunning)
@@ -323,6 +327,8 @@
          boolean useStartTLS = argParser.useStartTLS();
          if (argParser.isInteractive())
          {
            ManagementContext ctx = null;
            boolean canUseSSL = offLineConf.getLDAPSURL() != null;
            boolean canUseStartTLS = offLineConf.getStartTLSURL() != null;
            // This is done because we do not need to ask the user about these
@@ -388,8 +394,9 @@
              }
              LDAPManagementContextFactory factory =
                new LDAPManagementContextFactory();
              factory.getManagementContext(this, ci);
              ctx = factory.getManagementContext(this, ci);
              interactiveTrustManager = ci.getTrustManager();
              useInteractiveTrustManager = true;
            }
            catch (ConfigException ce)
            {
@@ -407,39 +414,72 @@
            }
            catch (ClientException e) {
              println(e.getMessageObject());
              // Display the information in the config file
              ServerStatusDescriptor desc = createServerStatusDescriptor(null,
                  null);
              updateDescriptorWithOffLineInfo(desc, offLineConf);
              writeStatus(desc);
              return
                ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
            }
            finally
            {
              if (ctx != null)
              {
                try
                {
                  ctx.close();
                }
                catch (Throwable t)
                {
                }
              }
            }
          }
          else
          {
            bindDn = argParser.getBindDN();
            bindPwd = argParser.getBindPassword();
          }
            if (bindDn == null)
          authProvided = bindPwd != null;
          if (bindDn == null)
          {
            bindDn = "";
          }
          if (bindPwd == null)
          {
            bindPwd = "";
          }
          if (authProvided)
          {
            ServerStatusDescriptor desc = createServerStatusDescriptor(
                bindDn, bindPwd);
            ConfigFromLDAP onLineConf = new ConfigFromLDAP();
            ConnectionProtocolPolicy policy =
              ConnectionProtocolPolicy.getConnectionPolicy(useSSL, useStartTLS);
            onLineConf.setConnectionInfo(offLineConf, policy, bindDn,
                bindPwd, getTrustManager());
            onLineConf.readConfiguration();
            updateDescriptorWithOnLineInfo(desc, onLineConf);
            writeStatus(desc);
            if (desc.getErrorMessage() != null)
            {
              bindDn = "";
            }
            if (bindPwd == null)
            {
              bindPwd = "";
              return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
              getReturnCode();
            }
          }
          ServerStatusDescriptor desc = createServerStatusDescriptor(
              bindDn, bindPwd);
          ConfigFromLDAP onLineConf = new ConfigFromLDAP();
          ConnectionProtocolPolicy policy =
            ConnectionProtocolPolicy.getConnectionPolicy(useSSL, useStartTLS);
          onLineConf.setConnectionInfo(offLineConf, policy, bindDn,
              bindPwd, getTrustManager());
          onLineConf.readConfiguration();
          updateDescriptorWithOnLineInfo(desc, onLineConf);
          writeStatus(desc);
          if (desc.getErrorMessage() != null)
          else
          {
            return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
            getReturnCode();
            // The user did not provide authentication: just display the
            // information we can get reading the config file.
            ServerStatusDescriptor desc = createServerStatusDescriptor(null,
                null);
            updateDescriptorWithOffLineInfo(desc, offLineConf);
            writeStatus(desc);
          }
        }
        else
@@ -647,7 +687,7 @@
      }
      else
      {
        if (!desc.isAuthenticated())
        if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
        {
          text = getNotAvailableBecauseAuthenticationIsRequiredText();
        }
@@ -714,7 +754,7 @@
    {
      if (desc.getStatus() == ServerStatusDescriptor.ServerStatus.STARTED)
      {
        if (!desc.isAuthenticated())
        if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
        {
          text = getNotAvailableBecauseAuthenticationIsRequiredText();
        }
@@ -778,7 +818,7 @@
      text = Message.raw(desc.getJavaVersion());
      if (text == null)
      {
        if (!desc.isAuthenticated())
        if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
        {
          text = getNotAvailableBecauseAuthenticationIsRequiredText();
        }
@@ -1006,7 +1046,7 @@
        }
        else
        {
          if (!desc.isAuthenticated())
          if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
          {
            s = getNotAvailableBecauseAuthenticationIsRequiredText();
          }
@@ -1101,7 +1141,7 @@
              {
                value = getNotAvailableBecauseServerIsDownText();
              }
              if (!desc.isAuthenticated())
              if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
              {
                value = getNotAvailableBecauseAuthenticationIsRequiredText();
              }
@@ -1127,7 +1167,7 @@
          {
            value = getNotAvailableBecauseServerIsDownText();
          }
          if (!desc.isAuthenticated())
          if (!desc.isAuthenticated() || (desc.getErrorMessage() != null))
          {
            value = getNotAvailableBecauseAuthenticationIsRequiredText();
          }
@@ -1193,13 +1233,13 @@
   */
  private TrustManager getTrustManager()
  {
    if (interactiveTrustManager == null)
    if (useInteractiveTrustManager)
    {
      return argParser.getTrustManager();
      return interactiveTrustManager;
    }
    else
    {
      return interactiveTrustManager;
      return argParser.getTrustManager();
    }
  }