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

Jean-Noël Rouvignac
29.15.2016 08154804f671e1c471df14ac999e6d6bb18bbd37
Partial OPENDJ-2625 Convert all code that uses JNDI to use the SDK instead

Changed bindDn's type from String to DN.
8 files modified
88 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java 27 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java 15 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java 4 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java 9 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
@@ -34,6 +34,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.DN;
import org.opends.admin.ads.ADSContext.ServerProperty;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
@@ -57,7 +58,7 @@
  private final ADSContext adsContext;
  private final ApplicationTrustManager trustManager;
  private final int timeout;
  private final String bindDN;
  private final DN bindDN;
  private final String bindPwd;
  private final Set<ServerDescriptor> servers = new HashSet<>();
  private final Set<SuffixDescriptor> suffixes = new HashSet<>();
@@ -83,8 +84,9 @@
    this.adsContext = adsContext;
    this.trustManager = trustManager;
    this.timeout = timeout;
    bindDN = ConnectionUtils.getBindDN(adsContext.getDirContext());
    bindPwd = ConnectionUtils.getBindPassword(adsContext.getDirContext());
    ConnectionWrapper conn = adsContext.getConnection();
    bindDN = conn.getBindDn();
    bindPwd = conn.getBindPassword();
  }
  /**
@@ -357,8 +359,7 @@
  {
    return new ServerLoader(serverProperties, bindDN, bindPwd,
        trustManager == null ? null : trustManager.createCopy(),
        timeout,
        getPreferredConnections(), getFilter());
        timeout, getPreferredConnections(), getFilter());
  }
  /**
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
@@ -24,10 +24,10 @@
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
import javax.naming.TimeLimitExceededException;
import javax.naming.ldap.LdapName;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.DN;
import org.opends.admin.ads.ADSContext;
import org.opends.admin.ads.ADSContext.ServerProperty;
import org.opends.admin.ads.ServerDescriptor;
@@ -53,7 +53,7 @@
  private ServerDescriptor serverDescriptor;
  private final ApplicationTrustManager trustManager;
  private final int timeout;
  private final String dn;
  private final DN dn;
  private final String pwd;
  private final LinkedHashSet<PreferredConnection> preferredLDAPURLs;
  private final TopologyCacheFilter filter;
@@ -77,8 +77,7 @@
   * to retrieve all the information.
   */
  public ServerLoader(Map<ServerProperty,Object> serverProperties,
      String dn, String pwd, ApplicationTrustManager trustManager,
      int timeout,
      DN dn, String pwd, ApplicationTrustManager trustManager, int timeout,
      Set<PreferredConnection> preferredLDAPURLs,
      TopologyCacheFilter filter)
  {
@@ -215,7 +214,8 @@
    for (PreferredConnection connection : getLDAPURLsByPreference())
    {
      lastLdapUrl = connection.getLDAPURL();
      ConnectionWrapper conn = new ConnectionWrapper(lastLdapUrl, connection.getType(), dn, pwd, timeout, trustManager);
      ConnectionWrapper conn =
          new ConnectionWrapper(lastLdapUrl, connection.getType(), dn.toString(), pwd, timeout, trustManager);
      if (conn.getLdapContext() != null)
      {
        return conn;
@@ -345,10 +345,8 @@
  {
    try
    {
      LdapName theDn = new LdapName(dn);
      LdapName containerDn =
        new LdapName(ADSContext.getAdministratorContainerDN());
      return theDn.startsWith(containerDn);
      DN containerDn = DN.valueOf(ADSContext.getAdministratorContainerDN());
      return dn.isSubordinateOrEqualTo(containerDn);
    }
    catch (Throwable t)
    {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -176,7 +176,7 @@
   * issues).  We also pass the server descriptor corresponding to the
   * connections to have a proper rendering of the root node.
   * @param server the server descriptor.
   * @param ctxConfiguration the connection to be used to retrieve the data in
   * @param connConfiguration the connection to be used to retrieve the data in
   * the configuration base DNs.
   * @param ctxUserData the connection to be used to retrieve the data in the
   * user base DNs.
@@ -184,16 +184,15 @@
   */
  public void setConnections(
      ServerDescriptor server,
      ConnectionWrapper ctxConfiguration,
      ConnectionWrapper connConfiguration,
      InitialLdapContext ctxUserData) throws NamingException {
    String rootNodeName;
    if (ctxConfiguration != null)
    if (connConfiguration != null)
    {
      this.connConfig = ctxConfiguration;
      this.ctxConfiguration = connConfig.getLdapContext();
      this.connConfig = connConfiguration;
      this.ctxUserData = ctxUserData;
      this.ctxConfiguration.setRequestControls(getConfigurationRequestControls());
      connConfig.getLdapContext().setRequestControls(getConfigurationRequestControls());
      this.ctxUserData.setRequestControls(getRequestControls());
      rootNodeName = new HostPort(server.getHostname(), connConfig.getHostPort().getPort()).toString();
    }
@@ -210,7 +209,7 @@
   * @return the connection for accessing the directory configuration.
   */
  public InitialLdapContext getConfigurationConnection() {
    return ctxConfiguration;
    return connConfig.getLdapContext();
  }
  /**
@@ -418,7 +417,7 @@
    this.followReferrals = followReferrals;
    stopRefresh();
    removeAllChildNodes(rootNode, true /* Keep suffixes */);
    ctxConfiguration.setRequestControls(getConfigurationRequestControls());
    connConfig.getLdapContext().setRequestControls(getConfigurationRequestControls());
    ctxUserData.setRequestControls(getRequestControls());
    connectionPool.setRequestControls(getRequestControls());
    startRefresh(null);
@@ -446,7 +445,7 @@
    stopRefresh();
    removeAllChildNodes(rootNode, true /* Keep suffixes */);
    this.sorted = sorted;
    ctxConfiguration.setRequestControls(getConfigurationRequestControls());
    connConfig.getLdapContext().setRequestControls(getConfigurationRequestControls());
    ctxUserData.setRequestControls(getRequestControls());
    connectionPool.setRequestControls(getRequestControls());
    startRefresh(null);
@@ -939,7 +938,7 @@
      boolean isConfigurationNode) throws NamingException
  {
    if (node == rootNode) {
      return ctxConfiguration;
      return connConfig.getLdapContext();
    }
    final BasicNode parent = (BasicNode) node.getParent();
@@ -947,7 +946,7 @@
    {
      return findConnectionForDisplayedEntry(parent, isConfigurationNode);
    }
    return isConfigurationNode ? ctxConfiguration : ctxUserData;
    return isConfigurationNode ? connConfig.getLdapContext() : ctxUserData;
  }
  /**
@@ -1019,7 +1018,7 @@
   * @param ctx the connection to be released.
   */
  void releaseLDAPConnection(InitialLdapContext ctx) {
    if (ctx != this.ctxConfiguration && ctx != this.ctxUserData)
    if (ctx != connConfig.getLdapContext() && ctx != this.ctxUserData)
    {
      // Thus it comes from the connection pool
      connectionPool.releaseConnection(ctx);
@@ -1034,7 +1033,7 @@
   */
  LDAPURL findUrlForLocalEntry(BasicNode node) {
    if (node == rootNode) {
      return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), "", isSSL(ctxConfiguration));
      return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), "", isSSL(connConfig.getLdapContext()));
    }
    final BasicNode parent = (BasicNode) node.getParent();
    if (parent != null)
@@ -1042,7 +1041,7 @@
      final LDAPURL parentUrl = findUrlForDisplayedEntry(parent);
      return LDAPConnectionPool.makeLDAPUrl(parentUrl, node.getDN());
    }
    return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), node.getDN(), isSSL(ctxConfiguration));
    return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), node.getDN(), isSSL(connConfig.getLdapContext()));
  }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -74,7 +74,7 @@
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.guitools.controlpanel.browser.BrowserController;
import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
@@ -1189,16 +1189,16 @@
      {
        try
        {
          InitialLdapContext ctx = getInfo().getConnection().getLdapContext();
          ConnectionWrapper conn = getInfo().getConnection();
          InitialLdapContext ctx1 = controller.getConfigurationConnection();
          boolean setConnection = ctx != ctx1;
          boolean setConnection = conn.getLdapContext() != ctx1;
          updateNumSubordinateHacker(desc);
          if (setConnection)
          {
            if (getInfo().getUserDataDirContext() == null)
            {
              InitialLdapContext ctxUserData =
                  createUserDataDirContext(ConnectionUtils.getBindDN(ctx), ConnectionUtils.getBindPassword(ctx));
                  createUserDataDirContext(conn.getBindDn().toString(), conn.getBindPassword());
              getInfo().setUserDataDirContext(ctxUserData);
            }
            final NamingException[] fNe = { null };
@@ -1427,7 +1427,8 @@
        throw ne;
      }
      ApplicationTrustManager.Cause cause = getInfo().getTrustManager().getLastRefusedCause();
      ApplicationTrustManager trustManager = getInfo().getTrustManager();
      ApplicationTrustManager.Cause cause = trustManager.getLastRefusedCause();
      logger.info(LocalizableMessage.raw("Certificate exception cause: " + cause));
      UserDataCertificateException.Type excType = null;
@@ -1457,8 +1458,8 @@
          p = -1;
        }
        final UserDataCertificateException udce = new UserDataCertificateException(
            null, INFO_CERTIFICATE_EXCEPTION.get(h, p), ne, h, p, getInfo().getTrustManager().getLastRefusedChain(),
            getInfo().getTrustManager().getLastRefusedAuthType(), excType);
            null, INFO_CERTIFICATE_EXCEPTION.get(h, p), ne, h, p, trustManager.getLastRefusedChain(),
            trustManager.getLastRefusedAuthType(), excType);
        if (SwingUtilities.isEventDispatchThread())
        {
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
@@ -44,6 +44,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.ConfigurationFramework;
import org.forgerock.opendj.config.ManagedObjectNotFoundException;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
import org.forgerock.opendj.server.config.client.ReplicationServerCfgClient;
import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
@@ -1829,7 +1830,7 @@
    logger.info(LocalizableMessage.raw("Updating references in: " + server.getHostPort(true)));
    notifyListeners(getFormattedWithPoints(INFO_PROGRESS_REMOVING_REFERENCES.get(server.getHostPort(true))));
    String dn = ADSContext.getAdministratorDN(uData.getAdminUID());
    DN dn = DN.valueOf(ADSContext.getAdministratorDN(uData.getAdminUID()));
    String pwd = uData.getAdminPwd();
    try (ConnectionWrapper connWrapper =
        getRemoteConnection(server, dn, pwd, getConnectTimeout(), new LinkedHashSet<PreferredConnection>()))
opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
@@ -32,6 +32,7 @@
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.DN;
import org.opends.admin.ads.ADSContext;
import org.opends.admin.ads.ServerDescriptor;
import org.opends.admin.ads.TopologyCacheException;
@@ -603,7 +604,7 @@
   * @return the InitialLdapContext to the remote server.
   * @throws ApplicationException if something goes wrong.
   */
  protected ConnectionWrapper getRemoteConnection(ServerDescriptor server, String dn, String pwd, int timeout,
  protected ConnectionWrapper getRemoteConnection(ServerDescriptor server, DN dn, String pwd, int timeout,
      Set<PreferredConnection> cnx) throws ApplicationException
  {
    Map<ADSContext.ServerProperty, Object> adsProperties =
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -70,6 +70,7 @@
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.ManagedObjectDefinition;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.server.config.client.BackendCfgClient;
import org.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.admin.ads.ADSContext;
@@ -4139,7 +4140,8 @@
      }
      server.setAdsProperties(adsProperties);
    }
    return getRemoteConnection(server, auth.getDn(), auth.getPwd(), getConnectTimeout(), getPreferredConnections());
    return getRemoteConnection(server, DN.valueOf(auth.getDn()), auth.getPwd(), getConnectTimeout(),
        getPreferredConnections());
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -5839,7 +5839,7 @@
          }
        }
      }
      String bindDn = conn.getBindDn().toString();
      DN bindDn = conn.getBindDn();
      String pwd = conn.getBindPassword();
      for (ServerDescriptor s : serversToUpdate)
      {
@@ -7526,7 +7526,7 @@
   * configuration.
   */
  private void removeReferencesInServer(ServerDescriptor server,
      String replicationServer, String bindDn, String pwd,
      String replicationServer, DN bindDn, String pwd,
      Collection<String> baseDNs, boolean updateReplicationServers,
      Set<PreferredConnection> cnx)
  throws ReplicationCliException
@@ -9507,8 +9507,9 @@
  private ConnectionWrapper getConnection(TopologyCache cache, ServerDescriptor server) throws NamingException
  {
    String dn = getBindDN(cache.getAdsContext().getDirContext());
    String pwd = getBindPassword(cache.getAdsContext().getDirContext());
    ConnectionWrapper conn = cache.getAdsContext().getConnection();
    DN dn = conn.getBindDn();
    String pwd = conn.getBindPassword();
    TopologyCacheFilter filter = new TopologyCacheFilter();
    filter.setSearchMonitoringInformation(false);
    filter.setSearchBaseDNInformation(false);