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

jvergara
15.24.2008 f420f952326f7a82c7c18b7a21cc975c55e2ecfc
Fix for issue 2886 (Cannot get status from running server without authenticating)

The code has been modified (with no new arguments) in order to work in a best-effort mode. If the user does not provide authentication we will display the same information independently of whether the server is running or not. We still display the messages informing that authentication is required to display some monitoring data.

The status panel code has also been updated to have the same behavior.

However it will be required anyhow to provide authentication to display monitoring information since this information is available only through LDAP.

In addition to this changes the following issues have been fixed:

1. Close the ManagementContext created by the LDAPConsoleInteraction object so that we have only one open connection to the server.
2. Fix a bug when the user chose to accept automatically certificates (the default trust manager was used in this case and we could not connect).
5 files modified
135 ■■■■■ changed files
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java 16 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ServerStatusPooler.java 9 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java 100 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/admin_tool.properties 8 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
@@ -223,6 +223,22 @@
      {
        errorMessage = ERR_READING_CONFIG_LDAP.get(detail);
      }
      /*
       *  Display the information that we find in the off line configuration.
       */
      if (listeners.isEmpty())
      {
        listeners.addAll(offlineConf.getListeners());
      }
      if (databases.isEmpty())
      {
        databases.addAll(offlineConf.getDatabases());
      }
      if (administrativeUsers.isEmpty())
      {
        administrativeUsers.addAll(offlineConf.getAdministrativeUsers());
      }
    }
    catch (Throwable t)
    {
opendj-sdk/opends/src/guitools/org/opends/guitools/statuspanel/ServerStatusPooler.java
@@ -338,20 +338,17 @@
      {
        if ((dn == null) || (pwd == null))
        {
          desc.setAdministrativeUsers(new HashSet<String>());
          desc.setDatabases(new HashSet<DatabaseDescriptor>());
          desc.setListeners(new HashSet<ListenerDescriptor>());
          desc.setOpenConnections(-1);
          updateDescriptorWithOffLineInfo(desc);
        }
        else
        {
          updateDescriptorWithOnLineInfo(desc);
        }
      }
      catch (Exception ex)
      catch (Throwable t)
      {
        // Bug
        ex.printStackTrace();
        t.printStackTrace();
      }
    }
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();
    }
  }
opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -233,14 +233,14 @@
INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL=<not available> (*)
INFO_NOT_AVAILABLE_SHORT_LABEL=N/A
INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND=* Information only \
 available if you provide authentication information when launching the status \
 command.
 available if you provide valid authentication information when launching the \
 status command.
INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_TOOLTIP=<html>Information is only \
 available if you are authenticated<br>as an administrative user.
INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LABEL=<not available> (*)
INFO_NOT_AVAILABLE_SERVER_DOWN_CLI_LEGEND=* Information only available if \
 server is running and you provide authentication information when launching \
 the status command.
 server is running and you provide valid authentication information when \
 launching the status command.
INFO_NOT_AVAILABLE_SERVER_DOWN_TOOLTIP=<html>Information is only available if \
 server is running and you are authenticated<br>as an administrative user.
INFO_NOTHING_SELECTED_TO_UNINSTALL=You must select something to be \
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -2213,8 +2213,8 @@
      if ((isADS || isSchema) && isVerbose())
      {
        notifyListeners(getFormattedDone());
        notifyListeners(getLineBreak());
      }
      notifyListeners(getLineBreak());
      checkAbort();
    }
  }