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/guitools/controlpanel/browser/LDAPConnectionPool.java | 5 +-
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java | 33 ----------------
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java | 49 +++++++++---------------
3 files changed, 21 insertions(+), 66 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
index 49c23f3..86c219b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java
@@ -359,39 +359,6 @@
}
/**
- * Returns the LDAP URL used in the provided InitialLdapContext.
- * @param ctx the context to analyze.
- * @return the LDAP URL used in the provided InitialLdapContext.
- */
- static String getLdapUrl(InitialLdapContext ctx)
- {
- return getEnvProperty(ctx, 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;
- }
- }
-
- /**
- * Tells whether we are using StartTLS in the provided InitialLdapContext.
- * @param ctx the context to analyze.
- * @return <CODE>true</CODE> if we are using StartTLS and <CODE>false</CODE>
- * otherwise.
- */
- static boolean isStartTLS(InitialLdapContext ctx)
- {
- return "true".equalsIgnoreCase(getEnvProperty(ctx, STARTTLS_PROPERTY));
- }
-
-
-
- /**
* Method used to know if we are connected as administrator in a server with a
* given InitialLdapContext.
* @param ctx the context.
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;
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
index 607cb99..0728c1a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java
@@ -86,11 +86,10 @@
{
ConnectionRecord cr = connectionTable.get(key);
if (cr.conn != null
- && conn.getHostPort().equals(cr.conn.getHostPort())
+ && cr.conn.getHostPort().equals(conn.getHostPort())
&& cr.conn.getBindDn().equals(conn.getBindDn())
&& cr.conn.getBindPassword().equals(conn.getBindPassword())
- && cr.conn.isSSL() == conn.isSSL()
- && cr.conn.isStartTLS() == conn.isStartTLS())
+ && cr.conn.getConnectionType() == conn.getConnectionType())
{
return true;
}
--
Gitblit v1.10.0