mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
07.48.2016 a7e5e371915be741db2dac2656b779dba93bf9f9
ConnectionWrapper.java: simplified code
3 files modified
87 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionUtils.java 33 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java 49 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/LDAPConnectionPool.java 5 ●●●●● patch | view | raw | blame | history
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.
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;
  }
  /**
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;
      }