From 08154804f671e1c471df14ac999e6d6bb18bbd37 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/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java | 15 ++++---
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java | 9 ++--
opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java | 3 +
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 4 +
opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java | 16 +++----
opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java | 3 +
opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java | 11 +++--
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java | 27 ++++++-------
8 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
index 6100447..9de7170 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/TopologyCache.java
+++ b/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());
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
index 15e6673..f5adcd7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java
+++ b/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)
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
index 978c091..2b8ebce 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
+++ b/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()));
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
index 42c0de0..93ef43d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
+++ b/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())
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
index eeb3463..b82f673 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/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>()))
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
index decbb66..01ed639 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java
+++ b/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 =
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index b7efdc2..9c1861a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/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());
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index 37f01a1..a574f38 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/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);
--
Gitblit v1.10.0