From 6b91643447398f13e01a4e02f8431e5263fc9bff Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 20 Feb 2008 09:22:09 +0000
Subject: [PATCH] Fix for issue 2962 (Setup should allow non-secure replication port while LDAP access is SSL-enabled)

---
 opends/src/ads/org/opends/admin/ads/ServerDescriptor.java |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
index 9ac105c..9100d85 100644
--- a/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
+++ b/opends/src/ads/org/opends/admin/ads/ServerDescriptor.java
@@ -84,6 +84,10 @@
      */
     LDAPS_ENABLED,
     /**
+     * The associated value is an ArrayList of Boolean.
+     */
+    STARTTLS_ENABLED,
+    /**
      * The associated value is an ArrayList of Integer.
      */
     JMX_PORT,
@@ -297,6 +301,80 @@
   }
 
   /**
+   * Returns the URL to access this server using LDAP.  Returns
+   * <CODE>null</CODE> if the server is not configured to listen on an LDAP
+   * port.
+   * @return the URL to access this server using LDAP.
+   */
+  public String getLDAPURL()
+  {
+    String ldapUrl = null;
+    String host = getHostName();
+    int port = -1;
+
+    if (!serverProperties.isEmpty())
+    {
+      ArrayList s = (ArrayList)serverProperties.get(
+          ServerProperty.LDAP_ENABLED);
+      ArrayList p = (ArrayList)serverProperties.get(
+          ServerProperty.LDAP_PORT);
+      if (s != null)
+      {
+        for (int i=0; i<s.size(); i++)
+        {
+          if (Boolean.TRUE.equals(s.get(i)))
+          {
+            port = (Integer)p.get(i);
+            break;
+          }
+        }
+      }
+    }
+    if (port != -1)
+    {
+      ldapUrl = ConnectionUtils.getLDAPUrl(host, port, false);
+    }
+    return ldapUrl;
+  }
+
+  /**
+   * Returns the URL to access this server using LDAPS.  Returns
+   * <CODE>null</CODE> if the server is not configured to listen on an LDAPS
+   * port.
+   * @return the URL to access this server using LDAP.
+   */
+  public String getLDAPsURL()
+  {
+    String ldapsUrl = null;
+    String host = getHostName();
+    int port = -1;
+
+    if (!serverProperties.isEmpty())
+    {
+      ArrayList s = (ArrayList)serverProperties.get(
+          ServerProperty.LDAPS_ENABLED);
+      ArrayList p = (ArrayList)serverProperties.get(
+          ServerProperty.LDAPS_PORT);
+      if (s != null)
+      {
+        for (int i=0; i<s.size(); i++)
+        {
+          if (Boolean.TRUE.equals(s.get(i)))
+          {
+            port = (Integer)p.get(i);
+            break;
+          }
+        }
+      }
+    }
+    if (port != -1)
+    {
+      ldapsUrl = ConnectionUtils.getLDAPUrl(host, port, true);
+    }
+    return ldapsUrl;
+  }
+
+  /**
    * Returns a String of type host-name:port-number for the server.  If
    * the provided securePreferred is set to true the port that will be used
    * (if LDAPS is enabled) will be the LDAPS port.
@@ -517,6 +595,16 @@
         adsProperties.put(adsProps[i][1], String.valueOf(port));
       }
     }
+
+    ArrayList array = (ArrayList)serverProperties.get(
+        ServerProperty.STARTTLS_ENABLED);
+    boolean startTLSEnabled = false;
+    if ((array != null) && !array.isEmpty())
+    {
+      startTLSEnabled = Boolean.TRUE.equals(array.get(array.size() -1));
+    }
+    adsProperties.put(ADSContext.ServerProperty.STARTTLS_ENABLED,
+        startTLSEnabled ? "true" : "false");
     adsProperties.put(ADSContext.ServerProperty.ID, getHostPort(true));
     adsProperties.put(ADSContext.ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE,
                       getInstancePublicKeyCertificate());
@@ -576,6 +664,7 @@
             "ds-cfg-listen-address",
             "ds-cfg-listen-port",
             "ds-cfg-use-ssl",
+            "ds-cfg-allow-start-tls",
             "objectclass"
         });
     String filter = "(objectclass=ds-cfg-ldap-connection-handler)";
@@ -587,11 +676,13 @@
     ArrayList<Integer> ldapsPorts = new ArrayList<Integer>();
     ArrayList<Boolean> ldapEnabled = new ArrayList<Boolean>();
     ArrayList<Boolean> ldapsEnabled = new ArrayList<Boolean>();
+    ArrayList<Boolean> startTLSEnabled = new ArrayList<Boolean>();
 
     desc.serverProperties.put(ServerProperty.LDAP_PORT, ldapPorts);
     desc.serverProperties.put(ServerProperty.LDAPS_PORT, ldapsPorts);
     desc.serverProperties.put(ServerProperty.LDAP_ENABLED, ldapEnabled);
     desc.serverProperties.put(ServerProperty.LDAPS_ENABLED, ldapsEnabled);
+    desc.serverProperties.put(ServerProperty.STARTTLS_ENABLED, startTLSEnabled);
 
     while(listeners.hasMore())
     {
@@ -613,6 +704,9 @@
       {
         ldapPorts.add(new Integer(port));
         ldapEnabled.add(enabled);
+        enabled = "true".equalsIgnoreCase(
+            getFirstValue(sr, "ds-cfg-allow-start-tls"));
+        startTLSEnabled.add(enabled);
       }
     }
   }

--
Gitblit v1.10.0