From d65316c746990cbe4c2b433b007afe00e9492c36 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 30 Jul 2007 15:53:44 +0000
Subject: [PATCH] The following modifications are done in order to be able to handle properly secure connections in both the status command-line and the status panel.  Some options to specify a keystore, a trustore, etc. have been added to the status command-line so that is consistent with the other command-lines that use LDAP.  As for these command-lines if the user does not specify to use Start TLS or LDAPS, the command-line will try to use LDAP to connect. But if there is no LDAP port enabled, the command-line will try to connect to the LDAPS port.

---
 opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java |   69 +++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java b/opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java
index aed3f03..9652cbe 100644
--- a/opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java
+++ b/opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java
@@ -29,7 +29,10 @@
 
 import java.io.File;
 import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
+import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.util.Utils;
 import org.opends.statuspanel.event.ServerStatusChangeEvent;
@@ -47,6 +50,7 @@
 {
   private String dn;
   private String pwd;
+  private ApplicationTrustManager trustManager;
   private ServerStatusDescriptor lastDescriptor;
   private boolean stopPooling;
   private Thread poolingThread;
@@ -56,23 +60,28 @@
   private boolean stopping;
   private ConfigFromFile offLineConf = new ConfigFromFile();
   private ConfigFromLDAP onLineConf = new ConfigFromLDAP();
-  private String ldapUrl;
   private int nTriesWithErrorOnline;
+  private ConnectionProtocolPolicy policy;
 
   /* The pooling periods */
   private static final int OFFLINE_POOLING_PERIOD = 6000;
   private static final int ONLINE_POOLING_PERIOD = 4000;
 
+  private static final Logger LOG =
+    Logger.getLogger(ServerStatusPooler.class.getName());
+
   /**
    * Default constructor.
+   * @param policy the configuration policy to be used (whether we prefer the
+   * most secure, the less secure, a specific method...).
    */
-  public ServerStatusPooler()
+  public ServerStatusPooler(ConnectionProtocolPolicy policy)
   {
     /* This is required to retrieve the ldap url to be used by the
      * ConfigFromLDAP class.
      */
     offLineConf.readConfiguration();
-    ldapUrl = offLineConf.getLDAPURL();
+    this.policy = policy;
   }
 
   /**
@@ -232,13 +241,18 @@
    * information using LDAP.
    * @param dn the authentication Distinguished Name to bind.
    * @param pwd the authentication password to bind.
+   * @param trustManager the trust manager to be used for the secure
+   * connections.
+   * @throws ConfigException if a valid URL could not be found with the provided
+   * parameters.
    */
-  public void setAuthentication(String dn, String pwd)
+  public void setAuthentication(String dn, String pwd,
+      ApplicationTrustManager trustManager) throws ConfigException
   {
     this.dn = dn;
     this.pwd = pwd;
-    if ((ldapUrl != null) && (poolingThread != null) &&
-        poolingThread.isAlive() && !stopPooling)
+    this.trustManager = trustManager;
+    if ((poolingThread != null) && poolingThread.isAlive() && !stopPooling)
     {
       /* If we are pooling, stop the pooling update the connection information
        * and restart the pooling.  Set the stopPooling boolean to true to
@@ -258,12 +272,12 @@
         t.printStackTrace();
       }
       poolingThread = null;
-      onLineConf.setConnectionInfo(ldapUrl, dn, pwd);
+      onLineConf.setConnectionInfo(offLineConf, policy, dn, pwd, trustManager);
       startPooling();
     }
-    else if (ldapUrl != null)
+    else
     {
-      onLineConf.setConnectionInfo(ldapUrl, dn, pwd);
+      onLineConf.setConnectionInfo(offLineConf, policy, dn, pwd, trustManager);
     }
   }
 
@@ -330,20 +344,9 @@
           desc.setListeners(new HashSet<ListenerDescriptor>());
           desc.setOpenConnections(-1);
         }
-        else if (ldapUrl != null)
-        {
-          updateDescriptorWithOnLineInfo(desc);
-        }
         else
         {
-          /* We cannot retrieve an ldapurl from the config file.  Display
-           * what we got in the config file.
-           */
-          updateDescriptorWithOffLineInfo(desc);
-          if (desc.getErrorMessage() != null)
-          {
-            desc.setErrorMessage(getMsg("could-not-find-valid-ldapurl"));
-          }
+          updateDescriptorWithOnLineInfo(desc);
         }
       }
       catch (Exception ex)
@@ -372,10 +375,17 @@
     desc.setDatabases(offLineConf.getDatabases());
     desc.setListeners(offLineConf.getListeners());
     desc.setErrorMessage(offLineConf.getErrorMessage());
-    ldapUrl = offLineConf.getLDAPURL();
-    if ((ldapUrl != null) && (dn != null) && (pwd != null))
+    if ((dn != null) && (pwd != null))
     {
-      onLineConf.setConnectionInfo(ldapUrl, dn, pwd);
+      try
+      {
+        onLineConf.setConnectionInfo(offLineConf, policy, dn, pwd,
+            trustManager);
+      }
+      catch (ConfigException ce)
+      {
+        LOG.log(Level.WARNING, "Error retrieving LDAP URL: "+ce, ce);
+      }
     }
     desc.setOpenConnections(-1);
     desc.setJavaVersion(null);
@@ -406,8 +416,15 @@
       if (nTriesWithErrorOnline >= 5)
       {
         offLineConf.readConfiguration();
-        ldapUrl = offLineConf.getLDAPURL();
-        onLineConf.setConnectionInfo(ldapUrl, dn, pwd);
+        try
+        {
+          onLineConf.setConnectionInfo(offLineConf, policy, dn, pwd,
+              trustManager);
+        }
+        catch (ConfigException ce)
+        {
+          desc.setErrorMessage(ce.getMessage());
+        }
         nTriesWithErrorOnline = 0;
       }
     }

--
Gitblit v1.10.0