From a12eb578b2b06f6ba9d929f4a2c7b81e13eae7cc Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 01 Jul 2016 14:30:12 +0000
Subject: [PATCH] Partial OPENDJ-2625 Convert all code that uses JNDI to use the SDK instead

---
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 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 66ce546..0507018 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
@@ -36,6 +36,8 @@
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.config.LDAPProfile;
 import org.forgerock.opendj.ldap.Connection;
 import org.forgerock.opendj.ldap.DN;
@@ -60,6 +62,8 @@
  */
 public class ConnectionWrapper implements Closeable
 {
+  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
+
   private final LDAPConnectionFactory connectionFactory;
   private final Connection connection;
   private final InitialLdapContext ldapContext;
@@ -263,7 +267,18 @@
    */
   public boolean isSSL()
   {
-    return ConnectionUtils.isSSL(ldapContext);
+    // 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;
+    }
   }
 
   /**
@@ -273,6 +288,8 @@
    */
   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);
   }
 
@@ -327,6 +344,29 @@
   }
 
   /**
+   * Returns the connection type used by this connection wrapper.
+   *
+   * @return the connection type used by this connection wrapper
+   */
+  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;
+    }
+  }
+
+  /**
    * Returns the ldap context (JNDI).
    *
    * @return the ldap context

--
Gitblit v1.10.0