From a7e5e371915be741db2dac2656b779dba93bf9f9 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 07 Jul 2016 13:03:33 +0000
Subject: [PATCH] ConnectionWrapper.java: simplified code

---
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java |   49 +++++++++++++++++++------------------------------
 1 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
index 0507018..fbb71bd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
@@ -29,6 +29,7 @@
 import java.security.GeneralSecurityException;
 import java.util.concurrent.TimeUnit;
 
+import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.naming.NoPermissionException;
 import javax.naming.ldap.InitialLdapContext;
@@ -257,7 +258,21 @@
    */
   public String getLdapUrl()
   {
-    return ConnectionUtils.getLdapUrl(ldapContext);
+    return getEnvProperty(ldapContext, Context.PROVIDER_URL);
+  }
+
+  private static String getEnvProperty(InitialLdapContext ctx, String property)
+  {
+    try
+    {
+      return (String) ctx.getEnvironment().get(property);
+    }
+    catch (NamingException ne)
+    {
+      // This is really strange. Seems like a bug somewhere.
+      logger.warn(LocalizableMessage.raw("Naming exception getting environment of " + ctx, ne));
+      return null;
+    }
   }
 
   /**
@@ -267,18 +282,7 @@
    */
   public boolean isSSL()
   {
-    // FIXME the code down below is what the code was doing in the control-panel / dsreplication
-    // We might as well just return this.connectionType == LDAPS;
-    try
-    {
-      return ConnectionUtils.getLdapUrl(ldapContext).toLowerCase().startsWith("ldaps");
-    }
-    catch (Throwable t)
-    {
-      // This is really strange. Seems like a bug somewhere.
-      logger.warn(LocalizableMessage.raw("Error getting if is SSL " + t, t));
-      return false;
-    }
+    return getConnectionType() == LDAPS;
   }
 
   /**
@@ -288,9 +292,7 @@
    */
   public boolean isStartTLS()
   {
-    // FIXME the code down below is what the code was doing in the control-panel / dsreplication
-    // We might as well just return this.connectionType == START_TLS;
-    return ConnectionUtils.isStartTLS(ldapContext);
+    return getConnectionType() == START_TLS;
   }
 
   private InitialLdapContext createAdministrativeContext(Options options) throws NamingException
@@ -350,20 +352,7 @@
    */
   public PreferredConnection.Type getConnectionType()
   {
-    // FIXME the code down below is what the code was doing in the control-panel / dsreplication
-    // We might as well just return this.connectionType;
-    if (isSSL())
-    {
-      return LDAPS;
-    }
-    else if (isStartTLS())
-    {
-      return START_TLS;
-    }
-    else
-    {
-      return LDAP;
-    }
+    return this.connectionType;
   }
 
   /**

--
Gitblit v1.10.0