From c30a14be35ba387e61b960740f6afc1b9774bb3d Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 04 Apr 2016 13:38:34 +0000
Subject: [PATCH] Add ConnectionWrapper to replace all uses of InitialLdapContext

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java           |    8 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LoginPanel.java                   |    9 
 opendj-server-legacy/src/main/java/org/opends/quicksetup/Application.java                                |   16 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java                |   21 
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ServerLoader.java                           |  115 +--
 opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java               |    5 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java   |    6 
 opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java         |  491 +++++++++++-------
 opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/ui/LoginDialog.java                   |   22 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java              |   10 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java             |   20 
 opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java                        |  122 ++--
 opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java                                  |   25 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java      |   62 +-
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java                |   20 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java                   |   22 
 opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java                      |  150 +++++
 opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java                            |   10 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java       |   97 +-
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ControlCenterMainPane.java        |    6 
 opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java                  |   59 -
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java |   84 +-
 opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java                         |   11 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java               |   31 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java           |    6 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteIndexTask.java            |   21 
 opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java                      |   85 +--
 27 files changed, 864 insertions(+), 670 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
index 765e571..e34ec18 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContext.java
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2007-2010 Sun Microsystems, Inc.
- * Portions Copyright 2012-2015 ForgeRock AS.
+ * Portions Copyright 2012-2016 ForgeRock AS.
  */
 package org.opends.admin.ads;
 
@@ -54,6 +54,7 @@
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.opends.admin.ads.ADSContextException.ErrorType;
 import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.quicksetup.Constants;
 import org.opends.server.schema.SchemaConstants;
 
@@ -320,16 +321,18 @@
 
   /** The context used to retrieve information. */
   private final InitialLdapContext dirContext;
+  private final ConnectionWrapper connectionWrapper;
 
   /**
    * Constructor of the ADSContext.
    *
-   * @param dirContext
-   *          the DirContext that must be used to retrieve information.
+   * @param connectionWrapper
+   *          provide connection either via JNDI or Ldap Connection
    */
-  public ADSContext(InitialLdapContext dirContext)
+  public ADSContext(ConnectionWrapper connectionWrapper)
   {
-    this.dirContext = dirContext;
+    this.connectionWrapper = connectionWrapper;
+    this.dirContext = connectionWrapper.getLdapContext();
   }
 
   /**
@@ -343,6 +346,16 @@
   }
 
   /**
+   * Returns the connection used to retrieve information by this ADSContext.
+   *
+   * @return the connection
+   */
+  public ConnectionWrapper getConnection()
+  {
+    return connectionWrapper;
+  }
+
+  /**
    * Method called to register a server in the ADS.
    *
    * @param serverProperties
@@ -2228,7 +2241,7 @@
     {
       ben = getDefaultBackendName();
     }
-    helper.createAdministrationSuffix(getDirContext(), ben);
+    helper.createAdministrationSuffix(connectionWrapper, ben);
   }
 
   /**
diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java
index 1d3dbf4..a82cbc4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/ADSContextHelper.java
@@ -32,10 +32,8 @@
 
 import org.opends.admin.ads.ADSContext.ServerProperty;
 import org.opends.admin.ads.ADSContextException.ErrorType;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.forgerock.opendj.config.ManagedObjectNotFoundException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.LDIFBackendCfgClient;
 import org.forgerock.opendj.server.config.client.RootCfgClient;
 import org.forgerock.opendj.server.config.meta.BackendCfgDefn;
@@ -69,14 +67,12 @@
    * @throws ADSContextException if the administration suffix could not be
    * created.
    */
-  void createAdministrationSuffix(InitialLdapContext ctx, String backendName)
+  void createAdministrationSuffix(ConnectionWrapper conn, String backendName)
   throws ADSContextException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = conn.getRootConfiguration();
       LDIFBackendCfgClient backend = null;
       try
       {
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
new file mode 100644
index 0000000..8816c03
--- /dev/null
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/util/ConnectionWrapper.java
@@ -0,0 +1,150 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development and
+ * Distribution License (the License). You may not use this file except in compliance with the
+ * License.
+ *
+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
+ * specific language governing permission and limitations under the License.
+ *
+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
+ * information: "Portions Copyright [year] [name of copyright owner]".
+ *
+ * Copyright 2016 ForgeRock AS.
+ */
+package org.opends.admin.ads.util;
+
+import static org.forgerock.opendj.ldap.LDAPConnectionFactory.AUTHN_BIND_REQUEST;
+import static org.forgerock.opendj.ldap.LDAPConnectionFactory.CONNECT_TIMEOUT;
+import static org.forgerock.opendj.ldap.LDAPConnectionFactory.SSL_CONTEXT;
+import static org.forgerock.opendj.ldap.LDAPConnectionFactory.SSL_USE_STARTTLS;
+import static org.opends.admin.ads.util.ConnectionUtils.getBindDN;
+import static org.opends.admin.ads.util.ConnectionUtils.getBindPassword;
+import static org.opends.admin.ads.util.ConnectionUtils.getHostName;
+import static org.opends.admin.ads.util.ConnectionUtils.getPort;
+import static org.opends.admin.ads.util.ConnectionUtils.isSSL;
+import static org.opends.admin.ads.util.ConnectionUtils.isStartTLS;
+
+import java.io.Closeable;
+import java.security.GeneralSecurityException;
+import java.util.concurrent.TimeUnit;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+
+import org.forgerock.opendj.config.LDAPProfile;
+import org.forgerock.opendj.config.client.ManagementContext;
+import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
+import org.forgerock.opendj.ldap.Connection;
+import org.forgerock.opendj.ldap.LDAPConnectionFactory;
+import org.forgerock.opendj.ldap.LdapException;
+import org.forgerock.opendj.ldap.SSLContextBuilder;
+import org.forgerock.opendj.ldap.requests.Requests;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
+import org.forgerock.util.Options;
+import org.forgerock.util.time.Duration;
+import org.opends.server.util.StaticUtils;
+
+/**
+ * Wraps a connection to a directory, either relying on JNDI or relying on OpenDJ Connection.
+ * <p>
+ * You can either:
+ * <ul>
+ *  <li>call {@code getLdapContext()} method to obtain an {@code InitialLdapContext} for JNDI.</li>
+ *  <li>or call the {@code getConnection()} method to obtain a {@code Connection} object.</li>
+ * </ul>
+ */
+public class ConnectionWrapper implements Closeable
+{
+  private final LDAPConnectionFactory connectionFactory;
+  private final Connection connection;
+  private final InitialLdapContext ldapContext;
+
+  /**
+   * Creates a connection wrapper from JNDI context and connection data.
+   *
+   * @param ctx
+   *          the initial ldap context for JNDI
+   * @param connectTimeout
+   *            connect timeout to use for the connection
+   * @param trustManager
+   *            trust manager to use for a secure connection
+   * @throws NamingException
+   *           If an error occurs
+   */
+  public ConnectionWrapper(InitialLdapContext ctx, long connectTimeout, TrustManager trustManager)
+      throws NamingException
+  {
+    ldapContext = ctx;
+
+    Options options = Options.defaultOptions();
+    options.set(CONNECT_TIMEOUT, new Duration(connectTimeout, TimeUnit.MILLISECONDS));
+    if (isSSL(ctx) || isStartTLS(ctx))
+    {
+      options.set(SSL_CONTEXT, getSSLContext(trustManager)).set(SSL_USE_STARTTLS, isStartTLS(ctx));
+    }
+    options.set(AUTHN_BIND_REQUEST, Requests.newSimpleBindRequest(getBindDN(ctx), getBindPassword(ctx).toCharArray()));
+    connectionFactory = new LDAPConnectionFactory(getHostName(ctx), getPort(ctx), options);
+    try
+    {
+      connection = connectionFactory.getConnection();
+    }
+    catch (LdapException e)
+    {
+      throw new NamingException("Unable to get a connection from connection factory:" + e.getMessage());
+    }
+  }
+
+  /**
+   * Returns the connection.
+   *
+   * @return the connection
+   */
+  public Connection getConnection()
+  {
+    return connection;
+  }
+
+  /**
+   * Returns the root configuration client by using the inrnal Connection.
+   *
+   * @return the root configuration client
+   */
+  public RootCfgClient getRootConfiguration()
+  {
+    ManagementContext ctx = LDAPManagementContext.newManagementContext(getConnection(), LDAPProfile.getInstance());
+    return ctx.getRootConfiguration();
+  }
+
+  /**
+   * Returns the ldap context (JNDI).
+   *
+   * @return the ldap context
+   */
+  public InitialLdapContext getLdapContext()
+  {
+    return ldapContext;
+  }
+
+  private SSLContext getSSLContext(TrustManager trustManager) throws NamingException
+  {
+    try
+    {
+      return new SSLContextBuilder().setTrustManager(trustManager).getSSLContext();
+    }
+    catch (GeneralSecurityException e)
+    {
+      throw new NamingException("Unable to perform SSL initialization:" + e.getMessage());
+    }
+  }
+
+  @Override
+  public void close()
+  {
+    StaticUtils.close(connectionFactory, connection);
+    StaticUtils.close(ldapContext);
+  }
+}
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 2c6df23..e8e17dc 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
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
  */
 package org.opends.admin.ads.util;
 
@@ -159,51 +159,32 @@
       serverDescriptor.setAdsProperties(serverProperties);
       serverDescriptor.updateAdsPropertiesWithServerProperties();
     }
-    catch (NoPermissionException npe)
+    catch (NoPermissionException e)
     {
       logger.warn(LocalizableMessage.raw(
-          "Permissions error reading server: "+getLastLdapUrl(), npe));
-      if (!isAdministratorDn())
-      {
-        lastException = new TopologyCacheException(
-                TopologyCacheException.Type.NOT_GLOBAL_ADMINISTRATOR, npe,
-                trustManager, getLastLdapUrl());
-      }
-      else
-      {
-        lastException =
-          new TopologyCacheException(
-              TopologyCacheException.Type.NO_PERMISSIONS, npe,
-              trustManager, getLastLdapUrl());
-      }
+          "Permissions error reading server: " + getLastLdapUrl(), e));
+      Type type = isAdministratorDn()
+          ? TopologyCacheException.Type.NO_PERMISSIONS
+          : TopologyCacheException.Type.NOT_GLOBAL_ADMINISTRATOR;
+      lastException = new TopologyCacheException(type, e, trustManager, getLastLdapUrl());
     }
-    catch (AuthenticationException ae)
+    catch (AuthenticationException e)
     {
       logger.warn(LocalizableMessage.raw(
-          "Authentication exception: "+getLastLdapUrl(), ae));
-      if (!isAdministratorDn())
-      {
-        lastException = new TopologyCacheException(
-                TopologyCacheException.Type.NOT_GLOBAL_ADMINISTRATOR, ae,
-                trustManager, getLastLdapUrl());
-      }
-      else
-      {
-        lastException =
-          new TopologyCacheException(
-              TopologyCacheException.Type.GENERIC_READING_SERVER, ae,
-              trustManager, getLastLdapUrl());
-      }
+          "Authentication exception: " + getLastLdapUrl(), e));
+      Type type = isAdministratorDn()
+          ? TopologyCacheException.Type.GENERIC_READING_SERVER
+          : TopologyCacheException.Type.NOT_GLOBAL_ADMINISTRATOR;
+      lastException = new TopologyCacheException(type, e, trustManager, getLastLdapUrl());
     }
-    catch (NamingException ne)
+    catch (NamingException e)
     {
       logger.warn(LocalizableMessage.raw(
-          "NamingException error reading server: "+getLastLdapUrl(), ne));
-      Type type = ctx == null
-          ? TopologyCacheException.Type.GENERIC_CREATING_CONNECTION
-          : TopologyCacheException.Type.GENERIC_READING_SERVER;
-      lastException = new TopologyCacheException(
-          type, ne, trustManager, getLastLdapUrl());
+          "NamingException error reading server: " + getLastLdapUrl(), e));
+      Type type = ctx != null
+          ? TopologyCacheException.Type.GENERIC_READING_SERVER
+          : TopologyCacheException.Type.GENERIC_CREATING_CONNECTION;
+      lastException = new TopologyCacheException(type, e, trustManager, getLastLdapUrl());
     }
     catch (Throwable t)
     {
@@ -256,13 +237,11 @@
         {
         case LDAPS:
           ctx = ConnectionUtils.createLdapsContext(lastLdapUrl, dn, pwd,
-              timeout, null, trustManager,
-              null);
+              timeout, null, trustManager, null);
           break;
         case START_TLS:
           ctx = ConnectionUtils.createStartTLSContext(lastLdapUrl, dn, pwd,
-              timeout, null, trustManager,
-              null, null);
+              timeout, null, trustManager, null, null);
           break;
         default:
           ctx = ConnectionUtils.createLdapContext(lastLdapUrl, dn, pwd,
@@ -274,6 +253,18 @@
   }
 
   /**
+   * Returns a Connection Wrapper.
+   *
+   * @return the connection wrapper
+   * @throws NamingException
+   *            If an error occurs.
+   */
+  public ConnectionWrapper createConnectionWrapper() throws NamingException
+  {
+    return new ConnectionWrapper(createContext(), timeout, trustManager);
+  }
+
+  /**
    * Returns the last LDAP URL to which we tried to connect.
    * @return the last LDAP URL to which we tried to connect.
    */
@@ -310,7 +301,7 @@
    */
   private String getStartTlsLdapUrl(Map<ServerProperty,Object> serverProperties)
   {
-    if (isLdapEnabled(serverProperties) && isStartTlsEnabled(serverProperties))
+    if (isStartTlsEnabled(serverProperties))
     {
       return "ldap://" + getHostNameForLdapUrl(serverProperties) + ":"
           + serverProperties.get(ServerProperty.LDAP_PORT);
@@ -328,8 +319,7 @@
    */
   private String getLdapsUrl(Map<ServerProperty,Object> serverProperties)
   {
-    boolean ldapsEnabled = isLdapsEnabled(serverProperties);
-    if (ldapsEnabled)
+    if (isLdapsEnabled(serverProperties))
     {
       return "ldaps://" + getHostNameForLdapUrl(serverProperties) + ":"
           + serverProperties.get(ServerProperty.LDAPS_PORT);
@@ -348,21 +338,13 @@
   private String getAdminConnectorUrl(
     Map<ServerProperty,Object> serverProperties)
   {
-    boolean portDefined;
     if (isPropertyEnabled(serverProperties, ServerProperty.ADMIN_ENABLED))
     {
-      Object v = serverProperties.get(ServerProperty.ADMIN_PORT);
-      portDefined = v != null;
-    }
-    else
-    {
-      portDefined = false;
-    }
-
-    if (portDefined)
-    {
-      return "ldaps://" + getHostNameForLdapUrl(serverProperties) + ":"
-          + serverProperties.get(ServerProperty.ADMIN_PORT);
+      Object adminPort = serverProperties.get(ServerProperty.ADMIN_PORT);
+      if (adminPort != null)
+      {
+        return "ldaps://" + getHostNameForLdapUrl(serverProperties) + ":" + adminPort;
+      }
     }
     return null;
   }
@@ -379,7 +361,7 @@
 
   private boolean isStartTlsEnabled(Map<ServerProperty, Object> serverProperties)
   {
-    return isPropertyEnabled(serverProperties, ServerProperty.STARTTLS_ENABLED);
+    return isLdapEnabled(serverProperties) && isPropertyEnabled(serverProperties, ServerProperty.STARTTLS_ENABLED);
   }
 
   private boolean isPropertyEnabled(Map<ServerProperty, Object> serverProperties, ServerProperty property)
@@ -420,8 +402,8 @@
     catch (Throwable t)
     {
       logger.warn(LocalizableMessage.raw("Error parsing authentication DNs.", t));
+      return false;
     }
-    return false;
   }
 
   /**
@@ -466,24 +448,19 @@
 
     if (adminConnectorUrl != null)
     {
-      ldapUrls.add(
-          new PreferredConnection(adminConnectorUrl,
-          PreferredConnection.Type.LDAPS));
+      ldapUrls.add(new PreferredConnection(adminConnectorUrl, PreferredConnection.Type.LDAPS));
     }
     if (ldapsUrl != null)
     {
-      ldapUrls.add(
-          new PreferredConnection(ldapsUrl, PreferredConnection.Type.LDAPS));
+      ldapUrls.add(new PreferredConnection(ldapsUrl, PreferredConnection.Type.LDAPS));
     }
     if (startTLSUrl != null)
     {
-      ldapUrls.add(new PreferredConnection(startTLSUrl,
-              PreferredConnection.Type.START_TLS));
+      ldapUrls.add(new PreferredConnection(startTLSUrl, PreferredConnection.Type.START_TLS));
     }
     if (ldapUrl != null)
     {
-      ldapUrls.add(new PreferredConnection(ldapUrl,
-          PreferredConnection.Type.LDAP));
+      ldapUrls.add(new PreferredConnection(ldapUrl, PreferredConnection.Type.LDAP));
     }
     return ldapUrls;
   }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
index b1b0b93..b959892 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
@@ -12,14 +12,13 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
  */
 package org.opends.guitools.controlpanel.datamodel;
 
 import static org.opends.admin.ads.util.ConnectionUtils.*;
 import static org.opends.guitools.controlpanel.util.Utilities.*;
 import static org.opends.server.tools.ConfigureWindowsService.*;
-
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.OperatingSystem.*;
 
@@ -42,6 +41,7 @@
 import org.forgerock.opendj.config.server.ConfigException;
 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.IconPool;
 import org.opends.guitools.controlpanel.browser.LDAPConnectionPool;
 import org.opends.guitools.controlpanel.datamodel.ServerDescriptor.ServerStatus;
@@ -77,7 +77,7 @@
 
   private ServerDescriptor serverDesc;
   private Set<Task> tasks = new HashSet<>();
-  private InitialLdapContext ctx;
+  private ConnectionWrapper connWrapper;
   private InitialLdapContext userDataCtx;
   private final LDAPConnectionPool connectionPool = new LDAPConnectionPool();
   /** Used by the browsers. */
@@ -288,13 +288,14 @@
   /**
    * Sets the dir context to be used by the ControlPanelInfo to retrieve
    * monitoring and configuration information.
-   * @param ctx the connection.
+   * @param connWrapper the connection.
    */
-  public void setDirContext(InitialLdapContext ctx)
+  public void setConnection(ConnectionWrapper connWrapper)
   {
-    this.ctx = ctx;
-    if (ctx != null)
+    this.connWrapper = connWrapper;
+    if (connWrapper != null)
     {
+      InitialLdapContext ctx = connWrapper.getLdapContext();
       lastWorkingBindDN = ConnectionUtils.getBindDN(ctx);
       lastWorkingBindPwd = ConnectionUtils.getBindPassword(ctx);
       lastRemoteHostName = ConnectionUtils.getHostName(ctx);
@@ -303,14 +304,14 @@
   }
 
   /**
-   * Returns the dir context to be used by the ControlPanelInfo to retrieve
+   * Returns the connection to be used by the ControlPanelInfo to retrieve
    * monitoring and configuration information.
-   * @return the dir context to be used by the ControlPanelInfo to retrieve
+   * @return the connection to be used by the ControlPanelInfo to retrieve
    * monitoring and configuration information.
    */
-  public InitialLdapContext getDirContext()
+  public ConnectionWrapper getConnection()
   {
-    return ctx;
+    return connWrapper;
   }
 
   /**
@@ -443,7 +444,7 @@
 
     ServerDescriptor desc = createNewServerDescriptorInstance();
     desc.setIsLocal(isLocal);
-    InitialLdapContext ctx = getDirContext();
+    ConnectionWrapper connWrapper = getConnection();
     if (isLocal)
     {
       desc.setOpenDSVersion(
@@ -465,11 +466,11 @@
       desc.setStatus(status);
       if (status == ServerStatus.STOPPING)
       {
-        StaticUtils.close(ctx);
-        this.ctx = null;
+        StaticUtils.close(connWrapper);
+        this.connWrapper = null;
         if (userDataCtx != null)
         {
-          unregisterConnection(connectionPool, ctx);
+          unregisterConnection(connectionPool, connWrapper.getLdapContext());
           StaticUtils.close(userDataCtx);
           userDataCtx = null;
         }
@@ -490,41 +491,42 @@
     {
       desc.setStatus(ServerStatus.STARTED);
 
-      if (ctx == null && lastWorkingBindDN != null)
+      if (connWrapper == null && lastWorkingBindDN != null)
       {
         // Try with previous credentials.
         try
         {
+          InitialLdapContext context = null;
           if (isLocal)
           {
-            ctx = Utilities.getAdminDirContext(this, lastWorkingBindDN,
-              lastWorkingBindPwd);
+            context = Utilities.getAdminDirContext(this, lastWorkingBindDN, lastWorkingBindPwd);
           }
           else if (lastRemoteAdministrationURL != null)
           {
-            ctx = createLdapsContext(lastRemoteAdministrationURL,
+            context = createLdapsContext(lastRemoteAdministrationURL,
                 lastWorkingBindDN,
                 lastWorkingBindPwd,
                 getConnectTimeout(), null,
                 getTrustManager(), null);
           }
+          connWrapper = new ConnectionWrapper(context, getConnectTimeout(), getTrustManager());
         }
         catch (ConfigReadException | NamingException cre)
         {
           // Ignore: we will ask the user for credentials.
         }
-        if (ctx != null)
+        if (connWrapper != null)
         {
-          this.ctx = ctx;
+          this.connWrapper = connWrapper;
         }
       }
 
-      if (isLocal && ctx == null)
+      if (isLocal && connWrapper == null)
       {
         reader = createNewConfigFromFileReader();
         ((ConfigFromFile)reader).readConfiguration();
       }
-      else if (!isLocal && ctx == null)
+      else if (!isLocal && connWrapper == null)
       {
         desc.setStatus(ServerStatus.NOT_CONNECTED_TO_REMOTE);
         reader = null;
@@ -533,9 +535,9 @@
       {
         Utilities.initializeLegacyConfigurationFramework();
         reader = createNewConfigFromDirContextReader();
-        ((ConfigFromDirContext) reader).readConfiguration(ctx);
+        ((ConfigFromDirContext) reader).readConfiguration(connWrapper);
 
-        boolean connectionWorks = checkConnections(ctx, userDataCtx);
+        boolean connectionWorks = checkConnections(connWrapper.getLdapContext(), userDataCtx);
         if (!connectionWorks)
         {
           if (isLocal)
@@ -549,9 +551,9 @@
             desc.setStatus(ServerStatus.NOT_CONNECTED_TO_REMOTE);
             reader = null;
           }
-          StaticUtils.close(ctx);
-          this.ctx = null;
-          unregisterConnection(connectionPool, ctx);
+          StaticUtils.close(connWrapper);
+          this.connWrapper = null;
+          unregisterConnection(connectionPool, connWrapper.getLdapContext());
           StaticUtils.close(userDataCtx);
           userDataCtx = null;
         }
@@ -1226,9 +1228,9 @@
       adminPort1 = server.getAdminConnector().getPort();
     }
 
-    if (getDirContext() != null)
+    if (getConnection() != null)
     {
-      adminPort2 = ConnectionUtils.getPort(getDirContext());
+      adminPort2 = ConnectionUtils.getPort(getConnection().getLdapContext());
     }
     return adminPort1 == adminPort2;
   }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
index 8ce4d95..362b5c0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
@@ -17,7 +17,7 @@
 package org.opends.guitools.controlpanel.task;
 
 import static org.opends.messages.AdminToolMessages.*;
-import static org.opends.messages.ConfigMessages.*;
+import static org.opends.server.config.ConfigConstants.ATTR_BACKEND_BASE_DN;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,11 +31,11 @@
 import java.util.TreeSet;
 import java.util.concurrent.atomic.AtomicReference;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.SwingUtilities;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.config.server.ConfigException;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
@@ -43,10 +43,9 @@
 import org.opends.guitools.controlpanel.ui.ProgressDialog;
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
-import org.forgerock.opendj.config.server.ServerManagementContext;
+import org.forgerock.opendj.ldap.schema.AttributeType;
+import org.forgerock.opendj.ldap.schema.CoreSchema;
+import org.forgerock.opendj.ldap.schema.Schema;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
 import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
 import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
@@ -54,11 +53,14 @@
 import org.forgerock.opendj.server.config.server.ReplicationDomainCfg;
 import org.forgerock.opendj.server.config.server.ReplicationSynchronizationProviderCfg;
 import org.forgerock.opendj.server.config.server.RootCfg;
-import org.opends.server.config.ConfigConstants;
-import org.opends.server.types.Entry;
-import org.opends.server.config.DNConfigAttribute;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
+import org.forgerock.opendj.ldap.AttributeDescription;
 import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.Entry;
+import org.forgerock.opendj.ldap.LinkedAttribute;
+import org.forgerock.opendj.ldap.LinkedHashMapEntry;
+import org.opends.server.types.DirectoryException;
 import org.opends.server.types.OpenDsException;
 
 /** The task used to delete a set of base DNs or backends. */
@@ -213,7 +215,7 @@
    * Update the configuration in the server.
    * @throws OpenDsException if an error occurs.
    */
-  private void updateConfiguration() throws OpenDsException, ConfigException
+  private void updateConfiguration() throws Exception
   {
     boolean configHandlerUpdated = false;
     final int totalNumber = baseDNsToDelete.size() + backendsToDelete.size();
@@ -228,8 +230,7 @@
         {
           DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
         }
-        DirectoryServer.getInstance().initializeConfiguration(
-            org.opends.server.extensions.ConfigFileHandler.class.getName(),
+        DirectoryServer.getInstance().initializeConfiguration(ConfigurationHandler.class.getName(),
             ConfigReader.configFile);
         getInfo().setMustDeregisterConfig(true);
       }
@@ -300,7 +301,7 @@
         });
         if (isServerRunning())
         {
-          deleteBaseDNs(getInfo().getDirContext(), baseDNs);
+          deleteBaseDNs(getInfo().getConnection(), baseDNs);
         }
         else
         {
@@ -369,7 +370,7 @@
         });
         if (isServerRunning())
         {
-          deleteBackend(getInfo().getDirContext(), backend);
+          deleteBackend(getInfo().getConnection(), backend);
         }
         else
         {
@@ -427,31 +428,34 @@
     newBaseDNs.removeAll(dnsToRemove);
 
     String backendName = backend.getBackendID();
-    DN dn = DN.valueOf("ds-cfg-backend-id" + "=" + backendName + ",cn=Backends,cn=config");
-    Entry configEntry = DirectoryServer.getConfigurationHandler().getConfigEntry(dn);
+    DN dn = DN.valueOf("ds-cfg-backend-id=" + backendName + ",cn=Backends,cn=config");
+    updateConfigEntryWithAttribute(dn, ATTR_BACKEND_BASE_DN, newBaseDNs);
+  }
 
-    DNConfigAttribute baseDNAttr =
-      new DNConfigAttribute(
-          ConfigConstants.ATTR_BACKEND_BASE_DN,
-          INFO_CONFIG_BACKEND_ATTR_DESCRIPTION_BASE_DNS.get(),
-          true, true, false, newBaseDNs);
-    configEntry.putConfigAttribute(baseDNAttr);
-    DirectoryServer.getConfigurationHandler().writeUpdatedConfig();
+  /** Update a config entry with the provided attribute parameters. */
+  private void updateConfigEntryWithAttribute(DN entryDn, String attrName, List<DN> newBaseDNs)
+      throws DirectoryException, ConfigException
+  {
+    ConfigurationHandler configHandler = DirectoryServer.getConfigurationHandler();
+    final Entry configEntry = configHandler.getEntry(entryDn);
+    final Entry newEntry = new LinkedHashMapEntry(configEntry);
+    AttributeType attrType = Schema.getDefaultSchema().getAttributeType(
+        attrName, CoreSchema.getDirectoryStringSyntax());
+    newEntry.replaceAttribute(new LinkedAttribute(AttributeDescription.create(attrType), newBaseDNs));
+    configHandler.replaceEntry(configEntry, newEntry);
   }
 
   /**
    * Deletes a set of base DNs.  The code assumes that the server is running
    * and that the provided connection is active.
    * @param baseDNs the list of base DNs.
-   * @param ctx the connection to the server.
+   * @param connWrapper the connection to the server.
    * @throws OpenDsException if an error occurs.
    */
-  private void deleteBaseDNs(InitialLdapContext ctx,
-      Set<BaseDNDescriptor> baseDNs) throws OpenDsException
+  private void deleteBaseDNs(ConnectionWrapper connWrapper,
+      Set<BaseDNDescriptor> baseDNs) throws Exception
   {
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(
-        JNDIDirContextAdaptor.adapt(ctx));
-    RootCfgClient root = mCtx.getRootConfiguration();
+    RootCfgClient root = connWrapper.getRootConfiguration();
     PluggableBackendCfgClient backend =
       (PluggableBackendCfgClient)root.getBackend(
           baseDNs.iterator().next().getBackend().getBackendID());
@@ -483,15 +487,13 @@
    * Deletes a backend.  The code assumes that the server is running
    * and that the provided connection is active.
    * @param backend the backend to be deleted.
-   * @param ctx the connection to the server.
+   * @param connWrapper the connection to the server.
    * @throws OpenDsException if an error occurs.
    */
-  private void deleteBackend(InitialLdapContext ctx,
-      BackendDescriptor backend) throws OpenDsException
+  private void deleteBackend(ConnectionWrapper connWrapper,
+      BackendDescriptor backend) throws Exception
   {
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(
-        JNDIDirContextAdaptor.adapt(ctx));
-    RootCfgClient root = mCtx.getRootConfiguration();
+    RootCfgClient root = connWrapper.getRootConfiguration();
     root.removeBackend(backend.getBackendID());
     root.commit();
   }
@@ -590,7 +592,7 @@
    * @throws OpenDsException if an error occurs.
    */
   private void disableReplicationIfRequired(final BaseDNDescriptor baseDN)
-  throws OpenDsException, ConfigException
+  throws Exception
   {
     if (baseDN.getType() == BaseDNDescriptor.Type.REPLICATED)
     {
@@ -600,17 +602,15 @@
       {
         if (isServerRunning())
         {
-          InitialLdapContext ctx = getInfo().getDirContext();
-          ManagementContext mCtx = LDAPManagementContext.createFromContext(
-              JNDIDirContextAdaptor.adapt(ctx));
-          RootCfgClient root = mCtx.getRootConfiguration();
+          ConnectionWrapper connWrapper = getInfo().getConnection();
+          RootCfgClient root = connWrapper.getRootConfiguration();
           ReplicationSynchronizationProviderCfgClient sync = null;
           try
           {
             sync = (ReplicationSynchronizationProviderCfgClient)
             root.getSynchronizationProvider("Multimaster Synchronization");
           }
-          catch (OpenDsException oe)
+          catch (Exception oe)
           {
             // Ignore this one
           }
@@ -636,7 +636,7 @@
         else
         {
           RootCfg root =
-            ServerManagementContext.getInstance().getRootConfiguration();
+              DirectoryServer.getInstance().getServerContext().getServerManagementContext().getRootConfiguration();
           ReplicationSynchronizationProviderCfg sync = null;
           try
           {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteIndexTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteIndexTask.java
index 203fc35..941be69 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteIndexTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteIndexTask.java
@@ -26,10 +26,10 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.SwingUtilities;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor;
@@ -37,12 +37,10 @@
 import org.opends.guitools.controlpanel.ui.ProgressDialog;
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
 import org.forgerock.opendj.server.config.client.RootCfgClient;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.forgerock.opendj.ldap.DN;
 import org.opends.server.types.OpenDsException;
@@ -128,7 +126,7 @@
    * @throws OpenDsException
    *           if an error occurs.
    */
-  private void updateConfiguration() throws OpenDsException
+  private void updateConfiguration() throws Exception
   {
     boolean configHandlerUpdated = false;
     final int totalNumber = indexesToDelete.size();
@@ -144,7 +142,7 @@
           DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
         }
         DirectoryServer.getInstance().initializeConfiguration(
-            org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile);
+            ConfigurationHandler.class.getName(), ConfigReader.configFile);
         getInfo().setMustDeregisterConfig(true);
       }
       boolean isFirst = true;
@@ -197,7 +195,7 @@
         });
         if (isServerRunning())
         {
-          deleteIndex(getInfo().getDirContext(), index);
+          deleteIndex(getInfo().getConnection(), index);
         }
         else
         {
@@ -263,7 +261,7 @@
     {
       dn = "ds-cfg-attribute" + "=" + index.getName() + ",cn=Index," + backendId + ",cn=Backends,cn=config";
     }
-    DirectoryServer.getConfigurationHandler().deleteEntry(DN.valueOf(dn), null);
+    DirectoryServer.getConfigurationHandler().deleteEntry(DN.valueOf(dn));
   }
 
   /**
@@ -277,10 +275,9 @@
    * @throws OpenDsException
    *           if an error occurs.
    */
-  private void deleteIndex(final InitialLdapContext ctx, final AbstractIndexDescriptor index) throws OpenDsException
+  private void deleteIndex(final ConnectionWrapper connWrapper, final AbstractIndexDescriptor index) throws Exception
   {
-    final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-    final RootCfgClient root = mCtx.getRootConfiguration();
+    final RootCfgClient root = connWrapper.getRootConfiguration();
     final BackendCfgClient backend = root.getBackend(index.getBackend().getBackendID());
 
     removeBackendIndex((PluggableBackendCfgClient) backend, index);
@@ -288,7 +285,7 @@
   }
 
   private void removeBackendIndex(final PluggableBackendCfgClient backend, final AbstractIndexDescriptor index)
-      throws OpenDsException
+      throws Exception
   {
     final String indexName = index.getName();
     if (isVLVIndex(index))
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 6abe795..0953cb6 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
@@ -18,7 +18,6 @@
 
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
-
 import static com.forgerock.opendj.cli.Utils.*;
 
 import java.awt.Component;
@@ -1195,7 +1194,7 @@
       {
         try
         {
-          InitialLdapContext ctx = getInfo().getDirContext();
+          InitialLdapContext ctx = getInfo().getConnection().getLdapContext();
           InitialLdapContext ctx1 = controller.getConfigurationConnection();
           boolean setConnection = ctx != ctx1;
           updateNumSubordinateHacker(desc);
@@ -1216,7 +1215,8 @@
                 try
                 {
                   controller.setConnections(
-                      getInfo().getServerDescriptor(), getInfo().getDirContext(), getInfo().getUserDataDirContext());
+                      getInfo().getServerDescriptor(), getInfo().getConnection().getLdapContext(),
+                      getInfo().getUserDataDirContext());
                   applyButtonClicked();
                 }
                 catch (NamingException ne)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ControlCenterMainPane.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ControlCenterMainPane.java
index afde3d9..b679577 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ControlCenterMainPane.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ControlCenterMainPane.java
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
  */
 
 package org.opends.guitools.controlpanel.ui;
@@ -88,6 +88,7 @@
     {
       private boolean lastStatusStopped;
       /** {@inheritDoc} */
+      @Override
       public void configurationChanged(final ConfigurationChangeEvent ev)
       {
         final boolean displayLogin;
@@ -109,6 +110,7 @@
         SwingUtilities.invokeLater(new Runnable()
         {
           /** {@inheritDoc} */
+          @Override
           public void run()
           {
             updateAuthenticationLabel(ev.getNewDescriptor());
@@ -179,7 +181,7 @@
         try
         {
          String bindDN = ConnectionUtils.getBindDN(
-             statusPane.getInfo().getDirContext());
+             statusPane.getInfo().getConnection().getLdapContext());
          lAuthenticatedAs.setText(
              INFO_CTRL_PANEL_AUTHENTICATED_AS.get(bindDN).toString());
         }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
index dea9baa..0755923 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ImportLDIFPanel.java
@@ -16,6 +16,7 @@
  */
 package org.opends.guitools.controlpanel.ui;
 
+import static org.opends.admin.ads.util.ConnectionUtils.getHostPort;
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
 import static com.forgerock.opendj.cli.Utils.OBFUSCATED_VALUE;
@@ -30,6 +31,7 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import javax.naming.ldap.InitialLdapContext;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
@@ -816,12 +818,12 @@
           INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_INITIALIZE_ALL.get()+ "<br><b>"+cmd+"</b><br><br>",
           ColorAndFontConstants.progressFont));
 
+      InitialLdapContext ctx = getInfo().getConnection().getLdapContext();
       for (DN baseDN : replicatedBaseDNs)
       {
-        LocalizableMessage msg = INFO_PROGRESS_INITIALIZING_SUFFIX.get(baseDN,
-            ConnectionUtils.getHostPort(getInfo().getDirContext()));
+        LocalizableMessage msg = INFO_PROGRESS_INITIALIZING_SUFFIX.get(baseDN, getHostPort(ctx));
         getProgressDialog().appendProgressHtml(Utilities.applyFont(msg + "<br>", ColorAndFontConstants.progressFont));
-        repl.initializeAllSuffix(baseDN.toString(), getInfo().getDirContext(), true);
+        repl.initializeAllSuffix(baseDN.toString(), ctx, true);
       }
     }
 
@@ -833,7 +835,7 @@
       args.add("--hostName");
       args.add(getInfo().getServerDescriptor().getHostname());
       args.add("--port");
-      args.add(String.valueOf(ConnectionUtils.getPort(getInfo().getDirContext())));
+      args.add(String.valueOf(ConnectionUtils.getPort(getInfo().getConnection().getLdapContext())));
       for (DN baseDN : replicatedBaseDNs)
       {
         args.add("--baseDN");
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
index 92d206c..a839973 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
@@ -32,7 +32,6 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.Box;
 import javax.swing.JCheckBox;
 import javax.swing.JComponent;
@@ -45,6 +44,7 @@
 import javax.swing.event.DocumentListener;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.guitools.controlpanel.datamodel.IndexDescriptor;
@@ -56,16 +56,13 @@
 import org.opends.guitools.controlpanel.task.Task;
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.OpenDsException;
 
 /**
  * The panel that displays an existing index (it appears on the right of the
@@ -549,7 +546,7 @@
      * @throws OpenDsException
      *           if there is an error updating the configuration.
      */
-    private void updateConfiguration() throws OpenDsException
+    private void updateConfiguration() throws Exception
     {
       boolean configHandlerUpdated = false;
       try
@@ -563,7 +560,7 @@
             DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
           }
           DirectoryServer.getInstance().initializeConfiguration(
-              org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile);
+              ConfigurationHandler.class.getName(), ConfigReader.configFile);
           getInfo().setMustDeregisterConfig(true);
         }
         else
@@ -598,7 +595,7 @@
 
         if (isServerRunning())
         {
-          modifyIndexOnline(getInfo().getDirContext());
+          modifyIndexOnline(getInfo().getConnection());
         }
         else
         {
@@ -628,19 +625,18 @@
     /**
      * Modifies index using the provided connection.
      *
-     * @param ctx
+     * @param connWrapper
      *          the connection to be used to update the index configuration.
      * @throws OpenDsException
      *           if there is an error updating the server.
      */
-    private void modifyIndexOnline(final InitialLdapContext ctx) throws OpenDsException
+    private void modifyIndexOnline(final ConnectionWrapper connWrapper) throws Exception
     {
-      final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      final BackendCfgClient backend = mCtx.getRootConfiguration().getBackend(backendName);
+      final BackendCfgClient backend = connWrapper.getRootConfiguration().getBackend(backendName);
       modifyBackendIndexOnline((PluggableBackendCfgClient) backend);
     }
 
-    private void modifyBackendIndexOnline(final PluggableBackendCfgClient backend) throws OpenDsException
+    private void modifyBackendIndexOnline(final PluggableBackendCfgClient backend) throws Exception
     {
       final BackendIndexCfgClient index = backend.getBackendIndex(attributeName);
       if (!indexTypes.equals(indexToModify.getTypes()))
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
index 422db83..bba580f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -48,6 +48,7 @@
 import org.opends.admin.ads.ServerDescriptor;
 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.ControlPanelArgumentParser;
 import org.opends.guitools.controlpanel.datamodel.ConfigReadException;
 import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
@@ -68,7 +69,6 @@
 import org.opends.server.util.StaticUtils;
 
 import static com.forgerock.opendj.cli.Utils.*;
-
 import static org.opends.admin.ads.util.ConnectionUtils.*;
 import static org.opends.guitools.controlpanel.util.Utilities.*;
 import static org.opends.messages.AdminToolMessages.*;
@@ -582,7 +582,8 @@
             });
             closeInfoConnections();
             getInfo().setIsLocal(isLocal);
-            getInfo().setDirContext(ctx);
+            getInfo().setConnection(
+                new ConnectionWrapper(ctx, getInfo().getConnectTimeout(), getInfo().getTrustManager()));
             getInfo().setUserDataDirContext(null);
             getInfo().regenerateDescriptor();
             return ctx;
@@ -972,6 +973,7 @@
 
   private void closeInfoConnections()
   {
-    StaticUtils.close(getInfo().getDirContext(), getInfo().getUserDataDirContext());
+    StaticUtils.close(getInfo().getConnection());
+    StaticUtils.close(getInfo().getUserDataDirContext());
   }
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LoginPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LoginPanel.java
index a69787f..c8dfdf0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LoginPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LoginPanel.java
@@ -34,6 +34,7 @@
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.ConfigReadException;
 import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
 import org.opends.guitools.controlpanel.util.BackgroundTask;
@@ -46,7 +47,6 @@
 import org.opends.server.util.StaticUtils;
 
 import static com.forgerock.opendj.cli.Utils.*;
-
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
 
@@ -204,11 +204,11 @@
             ctx = Utilities.getAdminDirContext(getInfo(), dn.getText(),
                 String.valueOf(pwd.getPassword()));
 
-            if (getInfo().getDirContext() != null)
+            if (getInfo().getConnection() != null)
             {
               try
               {
-                getInfo().getDirContext().close();
+                getInfo().getConnection().close();
               }
               catch (Throwable t)
               {
@@ -240,7 +240,8 @@
                     INFO_CTRL_PANEL_READING_CONFIGURATION_SUMMARY.get());
               }
             });
-            getInfo().setDirContext(ctx);
+            getInfo().setConnection(
+                new ConnectionWrapper(ctx, getInfo().getConnectTimeout(), getInfo().getTrustManager()));
             getInfo().setUserDataDirContext(null);
             getInfo().regenerateDescriptor();
             return ctx;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
index 3b48b0b..f4a8850 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -77,9 +77,7 @@
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.installer.InstallerHelper;
 import org.opends.quicksetup.util.Utils;
-import org.forgerock.opendj.config.AdminException;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
+import org.forgerock.opendj.ldap.LdapException;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
@@ -87,8 +85,8 @@
 import org.forgerock.opendj.server.config.meta.BackendCfgDefn;
 import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn;
 import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.extensions.ConfigFileHandler;
 import org.opends.server.tools.BackendCreationHelper;
 import org.opends.server.tools.BackendCreationHelper.DefaultIndex;
 import org.opends.server.tools.BackendTypeHelper;
@@ -853,7 +851,7 @@
       return args;
     }
 
-    private void updateConfigurationOnline() throws OpenDsException
+    private void updateConfigurationOnline() throws Exception
     {
       SwingUtilities.invokeLater(new Runnable()
       {
@@ -876,7 +874,7 @@
       refreshProgressBar();
     }
 
-    private void updateConfigurationOffline() throws OpenDsException
+    private void updateConfigurationOffline() throws Exception
     {
       boolean configHandlerUpdated = false;
       try
@@ -887,7 +885,7 @@
           DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
         }
         DirectoryServer.getInstance().initializeConfiguration(
-            ConfigFileHandler.class.getName(), ConfigReader.configFile);
+            ConfigurationHandler.class.getName(), ConfigReader.configFile);
         getInfo().setMustDeregisterConfig(true);
         configHandlerUpdated = true;
 
@@ -919,7 +917,7 @@
       });
     }
 
-    private void performTask() throws OpenDsException
+    private void performTask() throws Exception
     {
       final String backendName = getBackendName();
       if (isNewBackend())
@@ -934,7 +932,7 @@
       }
     }
 
-    private void createBackend(String backendName) throws OpenDsException
+    private void createBackend(String backendName) throws Exception
     {
       if (!isServerRunning())
       {
@@ -959,11 +957,11 @@
     }
 
     @RemoveOnceNewConfigFrameworkIsUsed("Use BackendCreationHelper.createBackend(...)")
-    private void createBackendOnline(String backendName) throws OpenDsException
+    private void createBackendOnline(String backendName) throws Exception
     {
       final RootCfgClient root = getRootConfigurationClient();
       final BackendCfgClient backend =
-          root.createBackend(getSelectedBackendType().getLegacyConfigurationFrameworkBackend(), backendName, null);
+          root.createBackend(getSelectedBackendType().getBackend(), backendName, null);
       backend.setEnabled(true);
       backend.setBaseDN(Collections.singleton(DN.valueOf(newBaseDN)));
       backend.setBackendId(backendName);
@@ -971,13 +969,12 @@
       backend.commit();
     }
 
-    private RootCfgClient getRootConfigurationClient()
+    private RootCfgClient getRootConfigurationClient() throws LdapException
     {
-      final JNDIDirContextAdaptor jndiContext = JNDIDirContextAdaptor.adapt(getInfo().getDirContext());
-      return LDAPManagementContext.createFromContext(jndiContext).getRootConfiguration();
+      return getInfo().getConnection().getRootConfiguration();
     }
 
-    private void addNewBaseDN(String backendName) throws OpenDsException
+    private void addNewBaseDN(String backendName) throws Exception
     {
       if (!isServerRunning())
       {
@@ -1014,7 +1011,7 @@
       }
     }
 
-    private void createAdditionalIndexes() throws OpenDsException
+    private void createAdditionalIndexes() throws Exception
     {
       final String backendName = getBackendName();
       displayCreateAdditionalIndexesDsConfigCmdLine();
@@ -1023,7 +1020,7 @@
       displayCreateAdditionalIndexesDone();
     }
 
-    private void addBackendDefaultIndexes(PluggableBackendCfgClient backendCfgClient) throws AdminException
+    private void addBackendDefaultIndexes(PluggableBackendCfgClient backendCfgClient) throws Exception
     {
       for (DefaultIndex defaultIndex : BackendCreationHelper.DEFAULT_INDEXES)
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
index c9c3c0a..5a4a59c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -31,12 +31,12 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JCheckBox;
 import javax.swing.SwingUtilities;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
@@ -48,18 +48,15 @@
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.forgerock.opendj.config.PropertyException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
 import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.opends.server.schema.SomeSchemaElement;
 import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.OpenDsException;
 import org.opends.server.types.Schema;
 
 /**
@@ -395,7 +392,7 @@
       return canLaunch;
     }
 
-    private void updateConfiguration() throws OpenDsException
+    private void updateConfiguration() throws Exception
     {
       boolean configHandlerUpdated = false;
       try
@@ -409,7 +406,7 @@
             DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
           }
           DirectoryServer.getInstance().initializeConfiguration(
-              org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile);
+              ConfigurationHandler.class.getName(), ConfigReader.configFile);
           getInfo().setMustDeregisterConfig(true);
         }
         else
@@ -438,7 +435,7 @@
 
         if (isServerRunning())
         {
-          createIndexOnline(getInfo().getDirContext());
+          createIndexOnline(getInfo().getConnection());
         }
         else
         {
@@ -463,14 +460,13 @@
       }
     }
 
-    private void createIndexOnline(final InitialLdapContext ctx) throws OpenDsException
+    private void createIndexOnline(final ConnectionWrapper connWrapper) throws Exception
     {
-      final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      final BackendCfgClient backend = mCtx.getRootConfiguration().getBackend(backendName.getText());
+      final BackendCfgClient backend = connWrapper.getRootConfiguration().getBackend(backendName.getText());
       createBackendIndexOnline((PluggableBackendCfgClient) backend);
     }
 
-    private void createBackendIndexOnline(final PluggableBackendCfgClient backend) throws OpenDsException
+    private void createBackendIndexOnline(final PluggableBackendCfgClient backend) throws Exception
     {
       final List<PropertyException> exceptions = new ArrayList<>();
       final BackendIndexCfgClient index = backend.createBackendIndex(
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
index 2cd1692..6b8f973 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewVLVIndexPanel.java
@@ -28,12 +28,12 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.SwingUtilities;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.ldap.DN;
 import org.forgerock.opendj.ldap.SearchScope;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
@@ -44,15 +44,12 @@
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.forgerock.opendj.config.PropertyException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.BackendVLVIndexCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
 import org.forgerock.opendj.server.config.meta.BackendVLVIndexCfgDefn;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.OpenDsException;
 
 /**
  * Panel that appears when the user defines a new VLV index.
@@ -217,7 +214,7 @@
       return true;
     }
 
-    private void updateConfiguration() throws OpenDsException
+    private void updateConfiguration() throws Exception
     {
       boolean configHandlerUpdated = false;
       try
@@ -231,7 +228,7 @@
             DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
           }
           DirectoryServer.getInstance().initializeConfiguration(
-              org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile);
+              ConfigurationHandler.class.getName(), ConfigReader.configFile);
           getInfo().setMustDeregisterConfig(true);
         }
         else
@@ -260,7 +257,7 @@
 
         if (isServerRunning())
         {
-          createVLVIndexOnline(getInfo().getDirContext());
+          createVLVIndexOnline(getInfo().getConnection());
         }
         else
         {
@@ -286,14 +283,13 @@
       }
     }
 
-    private void createVLVIndexOnline(InitialLdapContext ctx) throws OpenDsException
+    private void createVLVIndexOnline(ConnectionWrapper ctx) throws Exception
     {
-      final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      final BackendCfgClient backend = mCtx.getRootConfiguration().getBackend(backendName.getText());
+      final BackendCfgClient backend = ctx.getRootConfiguration().getBackend(backendName.getText());
       createBackendVLVIndexOnline((PluggableBackendCfgClient) backend);
     }
 
-    private void createBackendVLVIndexOnline(final PluggableBackendCfgClient backend) throws OpenDsException
+    private void createBackendVLVIndexOnline(final PluggableBackendCfgClient backend) throws Exception
     {
       final List<PropertyException> exceptions = new ArrayList<>();
       final BackendVLVIndexCfgClient index =
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
index a650edc..51c63d5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2013-2015 ForgeRock AS.
+ * Portions Copyright 2013-2016 ForgeRock AS.
  */
 package org.opends.guitools.controlpanel.ui;
 
@@ -2010,7 +2010,7 @@
       ctls.setReturningAttributes(new String[] { SchemaConstants.NO_ATTRIBUTES });
       String filter = BrowserController.ALL_OBJECTS_FILTER;
       NamingEnumeration<SearchResult> result =
-          getInfo().getDirContext().search(Utilities.getJNDIName(dn), filter, ctls);
+          getInfo().getConnection().getLdapContext().search(Utilities.getJNDIName(dn), filter, ctls);
 
       try
       {
@@ -2051,7 +2051,7 @@
       ctls.setReturningAttributes(new String[] { ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME });
       String filter = BrowserController.ALL_OBJECTS_FILTER;
       NamingEnumeration<SearchResult> result =
-          getInfo().getDirContext().search(Utilities.getJNDIName(dn), filter, ctls);
+          getInfo().getConnection().getLdapContext().search(Utilities.getJNDIName(dn), filter, ctls);
 
       try
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
index 45d8fae..63cb735 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/VLVIndexPanel.java
@@ -33,7 +33,6 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.Box;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
@@ -50,9 +49,9 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
-import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.ldap.DN;
 import org.forgerock.opendj.ldap.SearchScope;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
@@ -65,14 +64,11 @@
 import org.opends.guitools.controlpanel.task.Task;
 import org.opends.guitools.controlpanel.util.ConfigReader;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendVLVIndexCfgClient;
 import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
 import org.forgerock.opendj.server.config.client.RootCfgClient;
+import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.OpenDsException;
 
 /**
  * The panel that displays an existing VLV index (it appears on the right of the
@@ -604,7 +600,7 @@
       return canLaunch;
     }
 
-    private void updateConfiguration() throws OpenDsException, ConfigException
+    private void updateConfiguration() throws Exception
     {
       boolean configHandlerUpdated = false;
       try
@@ -618,7 +614,7 @@
             DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
           }
           DirectoryServer.getInstance().initializeConfiguration(
-              org.opends.server.extensions.ConfigFileHandler.class.getName(), ConfigReader.configFile);
+              ConfigurationHandler.class.getName(), ConfigReader.configFile);
           getInfo().setMustDeregisterConfig(true);
         }
         else
@@ -648,7 +644,7 @@
 
         if (isServerRunning())
         {
-          modifyVLVIndexOnline(getInfo().getDirContext());
+          modifyVLVIndexOnline(getInfo().getConnection());
         }
         else
         {
@@ -683,14 +679,13 @@
      * @throws OpenDsException
      *           if there is an error updating the server.
      */
-    private void modifyVLVIndexOnline(InitialLdapContext ctx) throws OpenDsException
+    private void modifyVLVIndexOnline(ConnectionWrapper connWrapper) throws Exception
     {
-      final ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      final RootCfgClient root = mCtx.getRootConfiguration();
+      final RootCfgClient root = connWrapper.getRootConfiguration();
       modifyBackendVLVIndexOnline((PluggableBackendCfgClient) root.getBackend(backendID));
     }
 
-    private void modifyBackendVLVIndexOnline(final PluggableBackendCfgClient backend) throws OpenDsException
+    private void modifyBackendVLVIndexOnline(final PluggableBackendCfgClient backend) throws Exception
     {
       final BackendVLVIndexCfgClient index = backend.getBackendVLVIndex(indexName);
       final DN b = DN.valueOf(baseDN);
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
index 62f214a..e4c33ef 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/ConfigFromDirContext.java
@@ -45,6 +45,7 @@
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.config.server.ConfigException;
 import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
@@ -55,12 +56,6 @@
 import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor;
 import org.opends.guitools.controlpanel.datamodel.VLVSortOrder;
 import org.opends.guitools.controlpanel.task.OnlineUpdateException;
-import org.forgerock.opendj.ldap.LdapException;
-
-import org.forgerock.opendj.config.client.ConcurrentModificationException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.AdministrationConnectorCfgClient;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
@@ -240,12 +235,12 @@
    * Reads configuration and monitoring information using the provided
    * connection.
    *
-   * @param context
+   * @param connWrapper
    *          the connection to be used to read the information.
    */
-  public void readConfiguration(final InitialLdapContext context)
+  public void readConfiguration(final ConnectionWrapper connWrapper)
   {
-    final List<OpenDsException> errors = new ArrayList<>();
+    final List<Exception> errors = new ArrayList<>();
     final Set<ConnectionHandlerDescriptor> connectionHandlers = new HashSet<>();
     final Set<BackendDescriptor> backendDescriptors = new HashSet<>();
     final Set<DN> as = new HashSet<>();
@@ -260,18 +255,18 @@
 
     hmConnectionHandlersMonitor.clear();
 
-    readSchemaIfNeeded(context, errors);
+    readSchemaIfNeeded(connWrapper.getLdapContext(), errors);
 
     try
     {
-      readConfig(context, connectionHandlers, backendDescriptors, as, errors);
+      readConfig(connWrapper, connectionHandlers, backendDescriptors, as, errors);
     }
     catch (final Throwable t)
     {
       errors.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(t), t));
     }
 
-    for (OpenDsException oe : errors)
+    for (Exception oe : errors)
     {
       logger.warn(LocalizableMessage.raw("Error reading configuration: " + oe, oe));
     }
@@ -280,7 +275,7 @@
     backends = Collections.unmodifiableSet(backendDescriptors);
     try
     {
-      updateMonitorInformation(context, errors);
+      updateMonitorInformation(connWrapper.getLdapContext(), errors);
     }
     catch (Throwable t)
     {
@@ -290,7 +285,7 @@
 
     try
     {
-      updateTaskInformation(context, errors, tasks);
+      updateTaskInformation(connWrapper.getLdapContext(), errors, tasks);
     }
     catch (Throwable t)
     {
@@ -311,7 +306,7 @@
     exceptions = Collections.unmodifiableList(errors);
   }
 
-  private void readSchemaIfNeeded(final InitialLdapContext context, final List<OpenDsException> errors)
+  private void readSchemaIfNeeded(final InitialLdapContext context, final List<Exception> errors)
   {
     if (mustReadSchema())
     {
@@ -332,13 +327,11 @@
     }
   }
 
-  private void readConfig(final InitialLdapContext context,
+  private void readConfig(final ConnectionWrapper connWrapper,
       final Set<ConnectionHandlerDescriptor> connectionHandlers, final Set<BackendDescriptor> backendDescriptors,
-      final Set<DN> alternateBindDNs, final List<OpenDsException> errors) throws Exception
+      final Set<DN> alternateBindDNs, final List<Exception> errors) throws Exception
   {
-    // Get the Directory Server configuration handler and use it.
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(context));
-    final RootCfgClient root = mCtx.getRootConfiguration();
+    final RootCfgClient root = connWrapper.getRootConfiguration();
 
     readAdminConnector(root, errors);
     readConnectionHandlers(connectionHandlers, root, errors);
@@ -357,39 +350,45 @@
     readAlternateBindDNs(alternateBindDNs, root, errors);
   }
 
-  private void readAdminConnector(final RootCfgClient root, final List<OpenDsException> errors)
+  private void readAdminConnector(final RootCfgClient root, final List<Exception> errors)
   {
     try
     {
       AdministrationConnectorCfgClient adminConnector = root.getAdministrationConnector();
       this.adminConnector = getConnectionHandler(adminConnector);
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
     }
   }
 
   private void readConnectionHandlers(final Set<ConnectionHandlerDescriptor> connectionHandlers,
-      RootCfgClient root, final List<OpenDsException> errors) throws ConcurrentModificationException,
-      AuthorizationException, CommunicationException
+      RootCfgClient root, final List<Exception> errors)
   {
-    for (String connHandler : root.listConnectionHandlers())
+    try
     {
-      try
+      for (String connHandler : root.listConnectionHandlers())
       {
-        ConnectionHandlerCfgClient connectionHandler = root.getConnectionHandler(connHandler);
-        connectionHandlers.add(getConnectionHandler(connectionHandler, connHandler));
+        try
+        {
+          ConnectionHandlerCfgClient connectionHandler = root.getConnectionHandler(connHandler);
+          connectionHandlers.add(getConnectionHandler(connectionHandler, connHandler));
+        }
+        catch (Exception oe)
+        {
+          errors.add(oe);
+        }
       }
-      catch (OpenDsException oe)
-      {
-        errors.add(oe);
-      }
+    }
+    catch (Exception oe)
+    {
+      errors.add(oe);
     }
   }
 
   private void readBackendConfiguration(final Set<BackendDescriptor> backendDescriptors,
-      final RootCfgClient root, final List<OpenDsException> errors) throws Exception
+      final RootCfgClient root, final List<Exception> errors) throws Exception
   {
     for (final String backendName : root.listBackends())
     {
@@ -426,7 +425,7 @@
         }
         backendDescriptors.add(desc);
       }
-      catch (OpenDsException oe)
+      catch (Exception oe)
       {
         errors.add(oe);
       }
@@ -466,14 +465,14 @@
   }
 
   private void refreshBackendConfig(final Set<IndexDescriptor> indexes,
-      final Set<VLVIndexDescriptor> vlvIndexes, final BackendCfgClient backend, final List<OpenDsException> errors)
+      final Set<VLVIndexDescriptor> vlvIndexes, final BackendCfgClient backend, final List<Exception> errors)
   {
     final PluggableBackendCfgClient db = (PluggableBackendCfgClient) backend;
     readBackendIndexes(indexes, errors, db);
     readBackendVLVIndexes(vlvIndexes, errors, db);
   }
 
-  private void readBackendIndexes(final Set<IndexDescriptor> indexes, final List<OpenDsException> errors,
+  private void readBackendIndexes(final Set<IndexDescriptor> indexes, final List<Exception> errors,
       final PluggableBackendCfgClient db)
   {
     indexes.add(new IndexDescriptor(DN2ID_INDEX_NAME));
@@ -488,14 +487,14 @@
             null, IndexTypeDescriptor.fromBackendIndexTypes(index.getIndexType()), index.getIndexEntryLimit()));
       }
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
     }
   }
 
   private void readBackendVLVIndexes(final Set<VLVIndexDescriptor> vlvIndexes,
-      final List<OpenDsException> errors, final PluggableBackendCfgClient db)
+      final List<Exception> errors, final PluggableBackendCfgClient db)
   {
     try
     {
@@ -508,19 +507,19 @@
             index.getFilter(), sortOrder));
       }
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
     }
   }
 
-  private boolean readIfReplicationIsSecure(final RootCfgClient root, final List<OpenDsException> errors)
+  private boolean readIfReplicationIsSecure(final RootCfgClient root, final List<Exception> errors)
   {
     try
     {
       return root.getCryptoManager().isSSLEncryption();
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
       return false;
@@ -533,7 +532,7 @@
     {
       return (ReplicationSynchronizationProviderCfgClient) root.getSynchronizationProvider(SYNC_PROVIDER_NAME);
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       return null;
     }
@@ -541,7 +540,7 @@
 
   private void readReplicationConfig(final Set<ConnectionHandlerDescriptor> connectionHandlers,
       final Set<BackendDescriptor> backendDescriptors, final ReplicationSynchronizationProviderCfgClient sync,
-      boolean isReplicationSecure, final List<OpenDsException> errors)
+      boolean isReplicationSecure, final List<Exception> errors)
   {
     replicationPort = -1;
     try
@@ -585,14 +584,14 @@
         }
       }
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
     }
   }
 
   private void readAlternateBindDNs(final Set<DN> alternateBindDNs, final RootCfgClient root,
-      final List<OpenDsException> errors)
+      final List<Exception> errors)
   {
     try
     {
@@ -607,7 +606,7 @@
         }
       }
     }
-    catch (OpenDsException oe)
+    catch (Exception oe)
     {
       errors.add(oe);
     }
@@ -860,7 +859,7 @@
    *           if there is an error retrieving the values of the search result.
    */
   private void handleTaskSearchResult(SearchResult sr, String searchBaseDN, Collection<TaskEntry> taskEntries,
-      List<OpenDsException> ex) throws NamingException
+      List<Exception> ex) throws NamingException
   {
     CustomSearchResult csr = new CustomSearchResult(sr, searchBaseDN);
     try
@@ -877,7 +876,7 @@
   }
 
   private void updateMonitorInformation(InitialLdapContext ctx,
-      List<OpenDsException> ex)
+      List<Exception> ex)
   {
     // Read monitoring information: since it is computed, it is faster
     // to get everything in just one request.
@@ -924,7 +923,7 @@
    * @param ts
    *          the list of task entries to be updated.
    */
-  public void updateTaskInformation(InitialLdapContext ctx, List<OpenDsException> ex, Collection<TaskEntry> ts)
+  public void updateTaskInformation(InitialLdapContext ctx, List<Exception> ex, Collection<TaskEntry> ts)
   {
     // Read monitoring information: since it is computed, it is faster
     // to get everything in just one request.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 37c0594..b767f19 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -20,7 +20,6 @@
 import static org.opends.admin.ads.util.ConnectionUtils.*;
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
-
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.Utils.*;
 
@@ -48,6 +47,7 @@
 import org.opends.admin.ads.TopologyCacheException;
 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.datamodel.ConnectionProtocolPolicy;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.quicksetup.Application;
@@ -1194,8 +1194,9 @@
       ctx = createAdministrativeContext(host, port, useSSL, useStartTLS, dn,
           pwd, getConnectTimeout(),
           userData.getTrustManager());
+      ConnectionWrapper connWrapper = new ConnectionWrapper(ctx, getConnectTimeout(), userData.getTrustManager());
 
-      ADSContext adsContext = new ADSContext(ctx);
+      ADSContext adsContext = new ADSContext(connWrapper);
       if (interactive && userData.getTrustManager() == null)
       {
         // This is required when the user did  connect to the server using SSL
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 a854f06..ccadb8b 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
@@ -27,7 +27,6 @@
 
 import javax.naming.Context;
 import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.JFrame;
 import javax.swing.SwingUtilities;
 
@@ -42,6 +41,7 @@
 import org.opends.admin.ads.TopologyCacheException;
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.admin.ads.util.PreferredConnection;
 import org.opends.guitools.uninstaller.ui.ConfirmUninstallPanel;
 import org.opends.guitools.uninstaller.ui.LoginDialog;
@@ -51,13 +51,8 @@
 import org.opends.quicksetup.util.ServerController;
 import org.opends.quicksetup.util.UIKeyStore;
 import org.opends.quicksetup.util.Utils;
-import org.forgerock.opendj.config.AttributeTypePropertyDefinition;
 import org.forgerock.opendj.config.ConfigurationFramework;
-import org.forgerock.opendj.config.ClassPropertyDefinition;
 import org.forgerock.opendj.config.ManagedObjectNotFoundException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
 import org.forgerock.opendj.server.config.client.ReplicationServerCfgClient;
 import org.forgerock.opendj.server.config.client.ReplicationSynchronizationProviderCfgClient;
@@ -71,7 +66,6 @@
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.OperatingSystem.*;
-
 import static org.forgerock.util.Utils.*;
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
@@ -118,25 +112,20 @@
     //  Bootstrap definition classes.
     try
     {
-      if (!ClassLoaderProvider.getInstance().isEnabled())
+      ConfigurationFramework configFramework = ConfigurationFramework.getInstance();
+      if (!configFramework.isInitialized())
       {
-        ClassLoaderProvider.getInstance().enable();
+        configFramework.initialize();
       }
+      configFramework.setIsClient(true);
     }
     catch (Throwable t)
     {
-      logger.warn(LocalizableMessage.raw("Error enabling admin framework class loader: "+t,
-          t));
+      logger.warn(LocalizableMessage.raw("Error enabling admin framework class loader: "+t, t));
     }
-
-    // Switch off class name validation in client.
-    ClassPropertyDefinition.setAllowClassValidation(false);
-
-    // Switch off attribute type name validation in client.
-    AttributeTypePropertyDefinition.setCheckSchema(false);
-
     logger.info(LocalizableMessage.raw("Uninstaller is created."));
   }
+
   /** {@inheritDoc} */
   @Override
   public LocalizableMessage getFrameTitle() {
@@ -1522,11 +1511,11 @@
     {
       getUninstallUserData().setAdminUID(loginDialog.getAdministratorUid());
       getUninstallUserData().setAdminPwd(loginDialog.getAdministratorPwd());
-      final InitialLdapContext ctx = loginDialog.getContext();
+      final ConnectionWrapper connWrapper = loginDialog.getConnection();
       try
       {
         getUninstallUserData().setLocalServerUrl(
-            (String)ctx.getEnvironment().get(Context.PROVIDER_URL));
+            (String)connWrapper.getLdapContext().getEnvironment().get(Context.PROVIDER_URL));
       }
       catch (NamingException ne)
       {
@@ -1544,7 +1533,7 @@
         public TopologyCache processBackgroundTask() throws Throwable
         {
           logger.info(LocalizableMessage.raw("Loading Topology Cache in askForAuthentication"));
-          ADSContext adsContext = new ADSContext(ctx);
+          ADSContext adsContext = new ADSContext(connWrapper);
           TopologyCache cache = new TopologyCache(adsContext,
               getTrustManager(), getConnectTimeout());
           cache.getFilter().setSearchMonitoringInformation(false);
@@ -1925,19 +1914,19 @@
       logger.info(LocalizableMessage.raw("Updating references in: "+ server.getHostPort(true)));
       notifyListeners(getFormattedWithPoints(
           INFO_PROGRESS_REMOVING_REFERENCES.get(server.getHostPort(true))));
-      InitialLdapContext ctx = null;
+      ConnectionWrapper connWrapper = null;
       try
       {
         String dn = ADSContext.getAdministratorDN(
             getUninstallUserData().getAdminUID());
         String pwd = getUninstallUserData().getAdminPwd();
-        ctx = getRemoteConnection(server, dn, pwd, getTrustManager(),
+        connWrapper = getRemoteConnection(server, dn, pwd, getTrustManager(),
             getConnectTimeout(),
             new LinkedHashSet<PreferredConnection>());
 
         // Update replication servers and domains.  If the domain
         // is an ADS, then remove it from there.
-        removeReferences(ctx, server.getHostPort(true), serverADSProperties);
+        removeReferences(connWrapper, server.getHostPort(true), serverADSProperties);
 
         notifyListeners(getFormattedDoneWithLineBreak());
       }
@@ -1966,7 +1955,7 @@
       }
       finally
       {
-        StaticUtils.close(ctx);
+        StaticUtils.close(connWrapper);
       }
     }
   }
@@ -1976,7 +1965,7 @@
    * provided InitialLdapContext.
    * It also tries to delete the server registration entry from the remote ADS
    * servers if the serverADSProperties object passed is not null.
-   * @param ctx the connection to the remote server where we want to remove
+   * @param connWrapper the connection to the remote server where we want to remove
    * references to the server that we are trying to uninstall.
    * @param serverDisplay an String representation that is used to identify
    * the remote server in the log messages we present to the user.
@@ -1985,15 +1974,13 @@
    * @throws ApplicationException if an error occurs while updating the remote
    * OpenDS server configuration.
    */
-  private void removeReferences(InitialLdapContext ctx, String serverDisplay,
+  private void removeReferences(ConnectionWrapper connWrapper, String serverDisplay,
       Map<ADSContext.ServerProperty, Object> serverADSProperties)
   throws ApplicationException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
       ReplicationSynchronizationProviderCfgClient sync =
         (ReplicationSynchronizationProviderCfgClient)
         root.getSynchronizationProvider("Multimaster Synchronization");
@@ -2004,16 +1991,7 @@
         Set<String> replServers = replicationServer.getReplicationServer();
         if (replServers != null)
         {
-          String replServer = null;
-          for (String o : replServers)
-          {
-            if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(
-                o))
-            {
-              replServer = o;
-              break;
-            }
-          }
+          String replServer = findReplicationServer(replServers);
           if (replServer != null)
           {
             logger.info(LocalizableMessage.raw("Updating references in replication server on "+
@@ -2042,16 +2020,7 @@
           Set<String> replServers = domain.getReplicationServer();
           if (replServers != null)
           {
-            String replServer = null;
-            for (String o : replServers)
-            {
-              if (getUninstallUserData().getReplicationServer().
-                  equalsIgnoreCase(o))
-              {
-                replServer = o;
-                break;
-              }
-            }
+            String replServer = findReplicationServer(replServers);
             if (replServer != null)
             {
               logger.info(LocalizableMessage.raw("Updating references in domain " +
@@ -2088,14 +2057,14 @@
       throw new ApplicationException(
           ReturnCode.CONFIGURATION_ERROR, errorMessage, t);
     }
-    ADSContext adsContext = new ADSContext(ctx);
+    ADSContext adsContext = new ADSContext(connWrapper);
 
     try
     {
       if (adsContext.hasAdminData() && serverADSProperties != null)
       {
         logger.info(LocalizableMessage.raw("Unregistering server on ADS of server "+
-            ConnectionUtils.getHostPort(ctx)+".  Properties: "+
+            ConnectionUtils.getHostPort(connWrapper.getLdapContext())+".  Properties: "+
             serverADSProperties));
         adsContext.unregisterServer(serverADSProperties);
       }
@@ -2119,6 +2088,18 @@
     }
   }
 
+  private String findReplicationServer(Set<String> replServers)
+  {
+    for (String s : replServers)
+    {
+      if (getUninstallUserData().getReplicationServer().equalsIgnoreCase(s))
+      {
+        return s;
+      }
+    }
+    return null;
+  }
+
   /**
    * Tells whether this ServerDescriptor object represents the server that we
    * are trying to uninstall or not.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/ui/LoginDialog.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/ui/LoginDialog.java
index 5ca7b5c..d94336f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/ui/LoginDialog.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/ui/LoginDialog.java
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
  */
 
 package org.opends.guitools.uninstaller.ui;
@@ -42,6 +42,7 @@
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.opends.admin.ads.ADSContext;
 import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.ConnectionProtocolPolicy;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.guitools.controlpanel.util.ConfigFromFile;
@@ -61,7 +62,6 @@
 import org.opends.quicksetup.util.Utils;
 
 import static com.forgerock.opendj.cli.Utils.*;
-
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
 
@@ -94,6 +94,8 @@
 
   private InitialLdapContext ctx;
 
+  private ConnectionWrapper connWrapper;
+
   private String usedUrl;
 
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -197,6 +199,16 @@
   }
 
   /**
+   * Returns the connection we got with the provided authentication.
+   *
+   * @return the connection
+   */
+  public ConnectionWrapper getConnection()
+  {
+    return connWrapper;
+  }
+
+  /**
    * Creates and returns the panel of the dialog.
    * @return the panel of the dialog.
    */
@@ -397,10 +409,8 @@
             throw new ApplicationException(ReturnCode.APPLICATION_ERROR,
                 ERR_COULD_NOT_FIND_VALID_LDAPURL.get(), null);
           }
-          ctx =
-            org.opends.guitools.controlpanel.util.Utilities.getAdminDirContext(
-              info, dn, pwd);
-
+          ctx = org.opends.guitools.controlpanel.util.Utilities.getAdminDirContext(info, dn, pwd);
+          connWrapper = new ConnectionWrapper(ctx, info.getConnectTimeout(), info.getTrustManager());
 
         } catch (NamingException ne)
         {
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 b0823fc..d3d281e 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
@@ -12,13 +12,12 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
- * Portions Copyright 2012-2015 ForgeRock AS.
+ * Portions Copyright 2012-2016 ForgeRock AS.
  */
 
 package org.opends.quicksetup;
 
 import static org.opends.messages.QuickSetupMessages.*;
-
 import static com.forgerock.opendj.cli.Utils.*;
 
 import java.io.ByteArrayOutputStream;
@@ -28,8 +27,6 @@
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizableMessageBuilder;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -38,6 +35,7 @@
 import org.opends.admin.ads.TopologyCacheException;
 import org.opends.admin.ads.TopologyCacheFilter;
 import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.admin.ads.util.PreferredConnection;
 import org.opends.admin.ads.util.ServerLoader;
 import org.opends.quicksetup.event.ProgressNotifier;
@@ -612,7 +610,7 @@
   }
 
   /**
-   * Gets an InitialLdapContext based on the information that appears on the
+   * Gets a connection based on the information that appears on the
    * provided ServerDescriptor object.  Note that the server is assumed to be
    * registered and that contains a Map with ADSContext.ServerProperty keys.
    * @param server the object describing the server.
@@ -627,7 +625,7 @@
    * @return the InitialLdapContext to the remote server.
    * @throws ApplicationException if something goes wrong.
    */
-  protected InitialLdapContext getRemoteConnection(ServerDescriptor server,
+  protected ConnectionWrapper getRemoteConnection(ServerDescriptor server,
       String dn, String pwd, ApplicationTrustManager trustManager,
       int timeout,
       Set<PreferredConnection> cnx)
@@ -641,10 +639,10 @@
     ServerLoader loader = new ServerLoader(adsProperties, dn, pwd,
         trustManager, timeout, cnx, filter);
 
-    InitialLdapContext ctx;
+    ConnectionWrapper connection;
     try
     {
-      ctx = loader.createContext();
+      connection = loader.createConnectionWrapper();
     }
     catch (NamingException ne)
     {
@@ -662,7 +660,7 @@
       throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, msg,
           ne);
     }
-    return ctx;
+    return connection;
   }
 
   /**
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 1b49b09..79c4791 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
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS.
+ * Portions Copyright 2011-2016 ForgeRock AS.
  */
 package org.opends.quicksetup.installer;
 
@@ -25,7 +25,6 @@
 import static org.opends.quicksetup.installer.DataReplicationOptions.Type.*;
 import static org.opends.quicksetup.installer.InstallProgressStep.*;
 import static org.opends.quicksetup.util.Utils.*;
-
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.Utils.*;
 
@@ -78,6 +77,7 @@
 import org.opends.admin.ads.TopologyCacheFilter;
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.admin.ads.util.PreferredConnection;
 import org.opends.quicksetup.ApplicationException;
 import org.opends.quicksetup.ButtonName;
@@ -1414,7 +1414,7 @@
    */
   private void unconfigureRemote()
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper connectionWrapper = null;
     if (registeredNewServerOnRemote || createdAdministrator || createdRemoteAds)
     {
       // Try to connect
@@ -1426,9 +1426,9 @@
       }
       try
       {
-        ctx = createInitialLdapContext(auth);
+        connectionWrapper = createConnection(auth);
 
-        ADSContext adsContext = new ADSContext(ctx);
+        ADSContext adsContext = new ADSContext(connectionWrapper);
         if (createdRemoteAds)
         {
           adsContext.removeAdminData(true);
@@ -1468,7 +1468,7 @@
       }
       finally
       {
-        StaticUtils.close(ctx);
+        StaticUtils.close(connectionWrapper);
       }
     }
     InstallerHelper helper = new InstallerHelper();
@@ -1477,8 +1477,9 @@
       notifyListeners(getFormattedWithPoints(INFO_PROGRESS_UNCONFIGURING_REPLICATION_REMOTE.get(getHostPort(server))));
       try
       {
-        ctx = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
-        helper.unconfigureReplication(ctx, hmConfiguredRemoteReplication.get(server), ConnectionUtils.getHostPort(ctx));
+        connectionWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
+        helper.unconfigureReplication(connectionWrapper, hmConfiguredRemoteReplication.get(server),
+            ConnectionUtils.getHostPort(connectionWrapper.getLdapContext()));
       }
       catch (ApplicationException ae)
       {
@@ -1486,7 +1487,7 @@
       }
       finally
       {
-        StaticUtils.close(ctx);
+        StaticUtils.close(connectionWrapper);
       }
       notifyListeners(getFormattedDoneWithLineBreak());
     }
@@ -1582,15 +1583,16 @@
   private void createReplicatedBackends(final Map<String, Set<String>> hmBackendSuffix,
       final Map<String, BackendTypeUIAdapter> backendTypes) throws ApplicationException
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper connection = null;
     try
     {
-      ctx = createLocalContext();
+      connection = createLocalConnection();
       final InstallerHelper helper = new InstallerHelper();
       for (String backendName : hmBackendSuffix.keySet())
       {
-        helper.createBackend(ctx, backendName, hmBackendSuffix.get(backendName), ConnectionUtils.getHostPort(ctx),
-            backendTypes.get(backendName).getLegacyConfigurationFrameworkBackend());
+        helper.createBackend(connection, backendName, hmBackendSuffix.get(backendName),
+            ConnectionUtils.getHostPort(connection.getLdapContext()),
+            backendTypes.get(backendName).getBackend());
       }
     }
     catch (NamingException ne)
@@ -1600,7 +1602,7 @@
     }
     finally
     {
-      StaticUtils.close(ctx);
+      StaticUtils.close(connection);
     }
   }
 
@@ -1700,21 +1702,21 @@
     replicationServers.put(ADSContext.getAdministrationSuffixDN(), adsServers);
     replicationServers.put(Constants.SCHEMA_DN, new HashSet<String>(adsServers));
 
-    InitialLdapContext ctx = null;
+    ConnectionWrapper connWrapper = null;
     long localTime = -1;
     long localTimeMeasureTime = -1;
     String localServerDisplay = null;
     try
     {
-      ctx = createLocalContext();
-      helper.configureReplication(ctx, replicationServers,
+      connWrapper = createLocalConnection();
+      helper.configureReplication(connWrapper, replicationServers,
           getUserData().getReplicationOptions().getReplicationPort(),
           getUserData().getReplicationOptions().useSecureReplication(),
           getLocalHostPort(),
           knownReplicationServerIds, knownServerIds);
       localTimeMeasureTime = System.currentTimeMillis();
-      localTime = Utils.getServerClock(ctx);
-      localServerDisplay = ConnectionUtils.getHostPort(ctx);
+      localTime = Utils.getServerClock(connWrapper.getLdapContext());
+      localServerDisplay = ConnectionUtils.getHostPort(connWrapper.getLdapContext());
     }
     catch (NamingException ne)
     {
@@ -1723,7 +1725,7 @@
     }
     finally
     {
-      StaticUtils.close(ctx);
+      StaticUtils.close(connWrapper);
     }
     notifyListeners(getFormattedDoneWithLineBreak());
     checkAbort();
@@ -1804,9 +1806,10 @@
           }
         }
 
-        ctx = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
+        connWrapper = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
+        InitialLdapContext ctx = connWrapper.getLdapContext();
         ConfiguredReplication repl =
-            helper.configureReplication(ctx, remoteReplicationServers, replicationPort, enableSecureReplication,
+            helper.configureReplication(connWrapper, remoteReplicationServers, replicationPort, enableSecureReplication,
                 ConnectionUtils.getHostPort(ctx), knownReplicationServerIds, knownServerIds);
         long remoteTimeMeasureTime = System.currentTimeMillis();
         long remoteTime = Utils.getServerClock(ctx);
@@ -1821,7 +1824,7 @@
 
         hmConfiguredRemoteReplication.put(server, repl);
 
-        StaticUtils.close(ctx);
+        StaticUtils.close(connWrapper);
         notifyListeners(getFormattedDoneWithLineBreak());
         checkAbort();
       }
@@ -2110,15 +2113,15 @@
    */
   protected void initializeSuffixes() throws ApplicationException
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper conn = null;
     try
     {
-      ctx = createLocalContext();
+      conn = createLocalConnection();
     }
     catch (Throwable t)
     {
       LocalizableMessage failedMsg = getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), t);
-      StaticUtils.close(ctx);
+      StaticUtils.close(conn);
       throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, failedMsg, t);
     }
 
@@ -2127,15 +2130,15 @@
     /* Initialize local ADS and schema contents using any replica. */
     {
       ServerDescriptor server = suffixes.iterator().next().getReplicas().iterator().next().getServer();
-      InitialLdapContext rCtx = null;
+      ConnectionWrapper remoteConn = null;
       try
       {
-        rCtx = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
+        remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
         TopologyCacheFilter filter = new TopologyCacheFilter();
         filter.setSearchMonitoringInformation(false);
         filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
         filter.addBaseDNToSearch(Constants.SCHEMA_DN);
-        ServerDescriptor s = createStandalone(rCtx, filter);
+        ServerDescriptor s = createStandalone(remoteConn.getLdapContext(), filter);
         for (ReplicaDescriptor replica : s.getReplicas())
         {
           String dn = replica.getSuffix().getDN();
@@ -2164,7 +2167,7 @@
       }
       finally
       {
-        StaticUtils.close(rCtx);
+        StaticUtils.close(remoteConn);
       }
     }
 
@@ -2203,14 +2206,14 @@
         if (replicationId == -1)
         {
           // This occurs if the remote server had not replication configured.
-          InitialLdapContext rCtx = null;
+          ConnectionWrapper remoteConn = null;
           try
           {
-            rCtx = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
+            remoteConn = getRemoteConnection(server, getTrustManager(), getPreferredConnections());
             TopologyCacheFilter filter = new TopologyCacheFilter();
             filter.setSearchMonitoringInformation(false);
             filter.addBaseDNToSearch(dn);
-            ServerDescriptor s = createStandalone(rCtx, filter);
+            ServerDescriptor s = createStandalone(remoteConn.getLdapContext(), filter);
             for (ReplicaDescriptor r : s.getReplicas())
             {
               if (areDnsEqual(r.getSuffix().getDN(), dn))
@@ -2234,7 +2237,7 @@
           }
           finally
           {
-            StaticUtils.close(rCtx);
+            StaticUtils.close(remoteConn);
           }
         }
         if (replicationId == -1)
@@ -2251,7 +2254,7 @@
             logger.info(LocalizableMessage.raw("Calling initializeSuffix with base DN: " + dn));
             logger.info(LocalizableMessage.raw("Try number: " + (6 - nTries)));
             logger.info(LocalizableMessage.raw("replicationId of source replica: " + replicationId));
-            initializeSuffix(ctx, replicationId, dn, !isADS && !isSchema, hostPort);
+            initializeSuffix(conn.getLdapContext(), replicationId, dn, !isADS && !isSchema, hostPort);
             initDone = true;
           }
           catch (PeerNotFoundException pnfe)
@@ -2268,7 +2271,7 @@
       }
       catch (ApplicationException ae)
       {
-        StaticUtils.close(ctx);
+        StaticUtils.close(conn);
         throw ae;
       }
       if ((isADS || isSchema) && isVerbose())
@@ -2297,8 +2300,8 @@
     DataReplicationOptions repl = getUserData().getReplicationOptions();
     boolean isRemoteServer = repl.getType() == DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY;
     AuthenticationData auth = isRemoteServer ? repl.getAuthenticationData() : null;
-    InitialLdapContext remoteCtx = null; // Bound to remote ADS host (if any).
-    InitialLdapContext localCtx = null; // Bound to local server.
+    ConnectionWrapper remoteConn = null; // Bound to remote ADS host (if any).
+    ConnectionWrapper localConn = null; // Bound to local server.
     ADSContext adsContext = null; // Bound to ADS host (via one of above).
 
     /*
@@ -2309,8 +2312,8 @@
     {
       if (isRemoteServer)
       {
-        remoteCtx = createInitialLdapContext(auth);
-        adsContext = new ADSContext(remoteCtx); // adsContext owns remoteCtx
+        remoteConn = createConnection(auth);
+        adsContext = new ADSContext(remoteConn); // adsContext owns remoteCtx
 
         /*
          * Check the remote server for ADS. If it does not exist, create the
@@ -2327,7 +2330,7 @@
           TopologyCacheFilter filter = new TopologyCacheFilter();
           filter.setSearchMonitoringInformation(false);
           filter.setSearchBaseDNInformation(false);
-          ServerDescriptor server = createStandalone(remoteCtx, filter);
+          ServerDescriptor server = createStandalone(remoteConn.getLdapContext(), filter);
           server.updateAdsPropertiesWithServerProperties();
           adsContext.registerServer(server.getAdsProperties());
           createdRemoteAds = true;
@@ -2344,7 +2347,7 @@
       {
         notifyListeners(getFormattedWithPoints(INFO_PROGRESS_CREATING_ADS.get()));
       }
-      localCtx = createLocalContext();
+      localConn = createLocalConnection();
       //      if (isRemoteServer)
       //      {
       //        /* Create an empty ADS suffix on the local server. */
@@ -2354,14 +2357,14 @@
       if (!isRemoteServer)
       {
         /* Configure local server to have an ADS */
-        adsContext = new ADSContext(localCtx); // adsContext owns localCtx
+        adsContext = new ADSContext(localConn); // adsContext owns localCtx
         adsContext.createAdminData(null);
       }
       /* Register new server in ADS. */
       TopologyCacheFilter filter = new TopologyCacheFilter();
       filter.setSearchMonitoringInformation(false);
       filter.setSearchBaseDNInformation(false);
-      ServerDescriptor server = createStandalone(localCtx, filter);
+      ServerDescriptor server = createStandalone(localConn.getLdapContext(), filter);
       server.updateAdsPropertiesWithServerProperties();
       if (0 == adsContext.registerOrUpdateServer(server.getAdsProperties()))
       {
@@ -2376,7 +2379,7 @@
       }
       if (isRemoteServer)
       {
-        seedAdsTrustStore(localCtx, adsContext.getTrustedCertificates());
+        seedAdsTrustStore(localConn.getLdapContext(), adsContext.getTrustedCertificates());
       }
       if (isVerbose())
       {
@@ -2439,23 +2442,29 @@
     }
     finally
     {
-      StaticUtils.close(remoteCtx, localCtx);
+      StaticUtils.close(remoteConn, localConn);
     }
   }
 
-  private InitialLdapContext createInitialLdapContext(AuthenticationData auth) throws NamingException
+  private ConnectionWrapper createConnection(AuthenticationData auth) throws NamingException
   {
     String ldapUrl = getLdapUrl(auth);
     String dn = auth.getDn();
     String pwd = auth.getPwd();
 
+    InitialLdapContext context = null;
+
     if (auth.useSecureConnection())
     {
       ApplicationTrustManager trustManager = getTrustManager();
       trustManager.setHost(auth.getHostName());
-      return createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, trustManager, null);
+      context = createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, trustManager, null);
     }
-    return createLdapContext(ldapUrl, dn, pwd, getConnectTimeout(), null);
+    else
+    {
+      context = createLdapContext(ldapUrl, dn, pwd, getConnectTimeout(), null);
+    }
+    return new ConnectionWrapper(context, getConnectTimeout(), getTrustManager());
   }
 
   /**
@@ -3106,6 +3115,7 @@
     host = getHostNameForLdapUrl(host);
     String ldapUrl = "ldaps://" + host + ":" + port;
     InitialLdapContext ctx = null;
+    ConnectionWrapper conn = null;
 
     ApplicationTrustManager trustManager = getTrustManager();
     trustManager.setHost(host);
@@ -3131,8 +3141,8 @@
           throw t;
         }
       }
-
-      ADSContext adsContext = new ADSContext(ctx);
+      conn = new ConnectionWrapper(ctx, getConnectTimeout(), trustManager);
+      ADSContext adsContext = new ADSContext(conn);
       if (adsContext.hasAdminData())
       {
         /* Check if there are already global administrators */
@@ -3271,6 +3281,7 @@
     finally
     {
       StaticUtils.close(ctx);
+      StaticUtils.close(conn);
     }
   }
 
@@ -3829,17 +3840,18 @@
     return servers;
   }
 
-  private InitialLdapContext createLocalContext() throws NamingException
+  private ConnectionWrapper createLocalConnection() throws NamingException
   {
     String ldapUrl =
         "ldaps://" + getHostNameForLdapUrl(getUserData().getHostName()) + ":" + getUserData().getAdminConnectorPort();
     String dn = getUserData().getDirectoryManagerDn();
     String pwd = getUserData().getDirectoryManagerPwd();
-    return createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, null, null);
+    InitialLdapContext context = createLdapsContext(ldapUrl, dn, pwd, getConnectTimeout(), null, null, null);
+    return new ConnectionWrapper(context, getConnectTimeout(), null);
   }
 
   /**
-   * Gets an InitialLdapContext based on the information that appears on the
+   * Gets a connection based on the information that appears on the
    * provided ServerDescriptor.
    *
    * @param server
@@ -3853,7 +3865,7 @@
    * @throws ApplicationException
    *           if something goes wrong.
    */
-  private InitialLdapContext getRemoteConnection(ServerDescriptor server, ApplicationTrustManager trustManager,
+  private ConnectionWrapper getRemoteConnection(ServerDescriptor server, ApplicationTrustManager trustManager,
       Set<PreferredConnection> cnx) throws ApplicationException
   {
     Map<ADSContext.ServerProperty, Object> adsProperties;
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
index d5f9417..6cf9af4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
@@ -44,13 +44,11 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-import javax.naming.directory.DirContext;
-import javax.naming.ldap.InitialLdapContext;
-
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.config.server.ConfigException;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.BackendMessages;
 import org.opends.messages.CoreMessages;
@@ -65,9 +63,6 @@
 import org.forgerock.opendj.config.ManagedObjectDefinition;
 import org.forgerock.opendj.config.ManagedObjectNotFoundException;
 import org.forgerock.opendj.config.PropertyException;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.client.CryptoManagerCfgClient;
 import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
@@ -307,21 +302,17 @@
 
   /**
    * Deletes a backend on the server.
-   * @param ctx the connection to the server.
+   * @param connWrapper the connection to the server.
    * @param backendName the name of the backend to be deleted.
    * @param serverDisplay the server display.
    * @throws ApplicationException if something goes wrong.
    */
-  public void deleteBackend(InitialLdapContext ctx, String backendName,
-      String serverDisplay)
-  throws ApplicationException
+  public void deleteBackend(ConnectionWrapper connWrapper, String backendName, String serverDisplay)
+      throws ApplicationException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
-      root.removeBackend(backendName);
+      connWrapper.getRootConfiguration().removeBackend(backendName);
     }
     catch (Throwable t)
     {
@@ -356,7 +347,7 @@
   /**
    * Creates a database backend on the server.
    *
-   * @param ctx
+   * @param connWrapper
    *          the connection to the server.
    * @param backendName
    *          the name of the backend to be created.
@@ -369,14 +360,13 @@
    * @throws ApplicationException
    *           if something goes wrong.
    */
-  public void createBackend(DirContext ctx, String backendName, Set<String> baseDNs, String serverDisplay,
-      ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
+  public void createBackend(ConnectionWrapper connWrapper, String backendName, Set<String> baseDNs,
+      String serverDisplay, ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType)
       throws ApplicationException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
       BackendCfgClient backend = root.createBackend(backendType, backendName, null);
       backend.setEnabled(true);
       backend.setBaseDN(toByteStrings(baseDNs));
@@ -403,25 +393,19 @@
 
   /**
    * Sets the base DNs on a given backend.
-   * @param ctx the connection to the server.
+   * @param connWrapper the connection to the server.
    * @param backendName the name of the backend where the base Dns must be
    * defined.
    * @param baseDNs the list of base DNs to be defined on the server.
    * @param serverDisplay the server display.
    * @throws ApplicationException if something goes wrong.
    */
-  public void setBaseDns(InitialLdapContext ctx,
-      String backendName,
-      Set<String> baseDNs,
-      String serverDisplay)
-  throws ApplicationException
+  public void setBaseDns(ConnectionWrapper connWrapper, String backendName, Set<String> baseDNs, String serverDisplay)
+      throws ApplicationException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
-      BackendCfgClient backend = root.getBackend(backendName);
+      BackendCfgClient backend = connWrapper.getRootConfiguration().getBackend(backendName);
       backend.setBaseDN(toByteStrings(baseDNs));
       backend.commit();
     }
@@ -436,7 +420,7 @@
 
   /**
    * Configures the replication on a given server.
-   * @param remoteCtx the connection to the server where we want to configure
+   * @param connWrapper the connection to the server where we want to configure
    * the replication.
    * @param replicationServers a Map where the key value is the base dn and
    * the value is the list of replication servers for that base dn (or domain).
@@ -453,7 +437,7 @@
    * @return a ConfiguredReplication object describing what has been configured.
    */
   public ConfiguredReplication configureReplication(
-      InitialLdapContext remoteCtx, Map<String,Set<String>> replicationServers,
+      ConnectionWrapper connWrapper, Map<String,Set<String>> replicationServers,
       int replicationPort, boolean useSecureReplication, String serverDisplay,
       Set<Integer> usedReplicationServerIds, Set<Integer> usedServerIds)
   throws ApplicationException
@@ -464,9 +448,7 @@
     boolean secureReplicationEnabled;
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(remoteCtx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
 
       /*
        * Configure Synchronization plugin.
@@ -654,7 +636,7 @@
   /**
    * Configures the replication on a given server.
    *
-   * @param remoteCtx
+   * @param connWrapper
    *          the connection to the server where we want to configure the
    *          replication.
    * @param replConf
@@ -664,13 +646,12 @@
    * @throws ApplicationException
    *           if something goes wrong.
    */
-  public void unconfigureReplication(InitialLdapContext remoteCtx, ConfiguredReplication replConf, String serverDisplay)
-      throws ApplicationException
+  public void unconfigureReplication(ConnectionWrapper connWrapper, ConfiguredReplication replConf,
+      String serverDisplay) throws ApplicationException
   {
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(remoteCtx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
       final String syncProvider = "Multimaster Synchronization";
       // Unconfigure Synchronization plugin.
       if (replConf.isSynchProviderCreated())
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 c4d39dd..be6f87a 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
@@ -65,11 +65,16 @@
 import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
 import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.ConfigurationFramework;
+import org.forgerock.opendj.config.ManagedObjectNotFoundException;
+import org.forgerock.opendj.config.PropertyException;
+import org.forgerock.opendj.config.server.ConfigException;
 import org.opends.admin.ads.*;
 import org.opends.admin.ads.ADSContext.ADSPropertySyntax;
 import org.opends.admin.ads.ADSContext.AdministratorProperty;
 import org.opends.admin.ads.ADSContext.ServerProperty;
 import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.admin.ads.util.OpendsCertificateException;
 import org.opends.admin.ads.util.PreferredConnection;
 import org.opends.admin.ads.util.ServerLoader;
@@ -86,10 +91,6 @@
 import org.opends.quicksetup.installer.PeerNotFoundException;
 import org.opends.quicksetup.installer.offline.OfflineInstaller;
 import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
-import org.opends.server.admin.*;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
 import org.forgerock.opendj.server.config.client.*;
 import org.forgerock.opendj.server.config.meta.ReplicationDomainCfgDefn;
 import org.forgerock.opendj.server.config.meta.ReplicationServerCfgDefn;
@@ -136,7 +137,6 @@
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.OperatingSystem.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static java.util.Collections.*;
 import static org.forgerock.util.Utils.*;
 import static org.opends.admin.ads.util.ConnectionUtils.*;
@@ -431,17 +431,14 @@
       // Bootstrap definition classes.
       try
       {
-        if (!ClassLoaderProvider.getInstance().isEnabled())
+        ConfigurationFramework configFramework = ConfigurationFramework.getInstance();
+        if (!configFramework.isInitialized())
         {
-          ClassLoaderProvider.getInstance().enable();
+          configFramework.initialize();
         }
-        // Switch off class name validation in client.
-        ClassPropertyDefinition.setAllowClassValidation(false);
-
-        // Switch off attribute type name validation in client.
-        AttributeTypePropertyDefinition.setCheckSchema(false);
+        configFramework.setIsClient(true);
       }
-      catch (InitializationException ie)
+      catch (ConfigException ie)
       {
         errPrintln(ie.getMessageObject());
         return ERROR_INITIALIZING_ADMINISTRATION_FRAMEWORK;
@@ -1111,6 +1108,12 @@
     return createInitialLdapContextInteracting(ci, isInteractive() && ci.isTrustStoreInMemory());
   }
 
+  private ConnectionWrapper createConnectionInteracting(LDAPConnectionConsoleInteraction ci)
+      throws ClientException
+  {
+    return createConnectionInteracting(ci, isInteractive() && ci.isTrustStoreInMemory());
+  }
+
   private OpendsCertificateException getCertificateRootException(Throwable t)
   {
     while (t != null)
@@ -1124,6 +1127,22 @@
     return null;
   }
 
+  private ConnectionWrapper createConnectionInteracting(LDAPConnectionConsoleInteraction ci,
+      boolean promptForCertificate) throws ClientException
+  {
+    try
+    {
+      InitialLdapContext ctx= createInitialLdapContextInteracting(ci, promptForCertificate);
+      return new ConnectionWrapper(ctx, CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT, ci.getTrustManager());
+    }
+    catch (NamingException e)
+    {
+      String hostName = getHostNameForLdapUrl(ci.getHostName());
+      Integer portNumber = ci.getPortNumber();
+      throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, ERR_FAILED_TO_CONNECT.get(hostName, portNumber));
+    }
+  }
+
   /**
    * Creates an Initial LDAP Context interacting with the user if the
    * application is interactive.
@@ -1561,6 +1580,27 @@
     return createAdministrativeContext(uData, bindDn);
   }
 
+  private ConnectionWrapper createAdministrativeConnection(MonoServerReplicationUserData uData)
+  {
+    final String bindDn = getAdministratorDN(uData.getAdminUid());
+    return createAdministrativeConnection(uData, bindDn);
+  }
+
+  private ConnectionWrapper createAdministrativeConnection(MonoServerReplicationUserData uData, final String bindDn)
+  {
+    try
+    {
+      return new ConnectionWrapper(createAdministrativeContext(uData, bindDn),
+          getConnectTimeout(), getTrustManager(sourceServerCI));
+    }
+    catch (NamingException e)
+    {
+      String hostPort = getServerRepresentation(uData.getHostName(), uData.getPort());
+      logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort));
+      return null;
+    }
+  }
+
   private InitialLdapContext createAdministrativeContext(MonoServerReplicationUserData uData, final String bindDn)
   {
     try
@@ -1965,11 +2005,11 @@
    */
   private boolean promptIfRequired(PurgeHistoricalUserData uData)
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper connWrapper = null;
     try
     {
-      ctx = getInitialLdapContext(uData);
-      if (ctx == null)
+      connWrapper = getConnection(uData);
+      if (connWrapper == null)
       {
         return false;
       }
@@ -1987,7 +2027,7 @@
       List<String> suffixes = argParser.getBaseDNs();
       if (uData.isOnline())
       {
-        checkSuffixesForPurgeHistorical(suffixes, ctx, true);
+        checkSuffixesForPurgeHistorical(suffixes, connWrapper.getLdapContext(), true);
       }
       else
       {
@@ -2001,7 +2041,7 @@
 
       if (uData.isOnline())
       {
-        List<? extends TaskEntry> taskEntries = getAvailableTaskEntries(ctx);
+        List<? extends TaskEntry> taskEntries = getAvailableTaskEntries(connWrapper.getLdapContext());
 
         TaskScheduleInteraction interaction =
             new TaskScheduleInteraction(uData.getTaskSchedule(), argParser.taskArgs, this,
@@ -2022,7 +2062,21 @@
     }
     finally
     {
-      close(ctx);
+      close(connWrapper);
+    }
+  }
+
+  private ConnectionWrapper getConnection(PurgeHistoricalUserData uData)
+  {
+    try
+    {
+      InitialLdapContext ctx = getInitialLdapContext(uData);
+      return new ConnectionWrapper(ctx, sourceServerCI.getConnectTimeout(), sourceServerCI.getTrustManager());
+    }
+    catch (NamingException ce)
+    {
+      logger.warn(LocalizableMessage.raw("An error occured " + ce));
+      return null;
     }
   }
 
@@ -2099,10 +2153,10 @@
       InitialLdapContext ctx)
   {
     List<TaskEntry> taskEntries = new ArrayList<>();
-    List<OpenDsException> exceptions = new ArrayList<>();
+    List<Exception> exceptions = new ArrayList<>();
     ConfigFromDirContext cfg = new ConfigFromDirContext();
     cfg.updateTaskInformation(ctx, exceptions, taskEntries);
-    for (OpenDsException ode : exceptions)
+    for (Exception ode : exceptions)
     {
       logger.warn(LocalizableMessage.raw("Error retrieving task entries: "+ode, ode));
     }
@@ -2163,7 +2217,7 @@
      */
     sourceServerCI.initializeGlobalArguments(host1, port1, adminUid, bindDn1, pwd,
         pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
-    InitialLdapContext ctx1 = null;
+    ConnectionWrapper ctx1 = null;
 
     while (ctx1 == null && !cancelled)
     {
@@ -2187,7 +2241,7 @@
         bindDn1 = sourceServerCI.getBindDN();
         pwd1 = sourceServerCI.getBindPassword();
 
-        ctx1 = createInitialLdapContextInteracting(sourceServerCI);
+        ctx1 = createConnectionInteracting(sourceServerCI);
         if (ctx1 == null)
         {
           cancelled = true;
@@ -2227,7 +2281,7 @@
       if (replicationServer1Configured && !configureReplicationServer1)
       {
         final LocalizableMessage msg =
-            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx1), repPort1);
+            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx1.getLdapContext()), repPort1);
         if (!askConfirmation(msg, false))
         {
           cancelled = true;
@@ -2335,7 +2389,7 @@
       // eventually admin authentication data.
       if (!cancelled)
       {
-        AtomicReference<InitialLdapContext> aux = new AtomicReference<>(ctx1);
+        AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(ctx1);
         cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, true);
         ctx1 = aux.get();
       }
@@ -2405,7 +2459,7 @@
           pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
       destinationServerCI.setUseAdminOrBindDn(true);
     }
-    InitialLdapContext ctx2 = null;
+    ConnectionWrapper ctx2 = null;
 
     while (ctx2 == null && !cancelled)
     {
@@ -2441,7 +2495,7 @@
 
         if (!error)
         {
-          ctx2 = createInitialLdapContextInteracting(destinationServerCI, true);
+          ctx2 = createConnectionInteracting(destinationServerCI, true);
           if (ctx2 == null)
           {
             cancelled = true;
@@ -2496,7 +2550,7 @@
       if (replicationServer2Configured && !configureReplicationServer2)
       {
         final LocalizableMessage prompt =
-            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx2), repPort2);
+            INFO_REPLICATION_SERVER_CONFIGURED_WARNING_PROMPT.get(getHostPort(ctx2.getLdapContext()), repPort2);
         if (!askConfirmation(prompt, false))
         {
           cancelled = true;
@@ -2613,7 +2667,7 @@
       // to load the ADS to ask the user to accept the certificates.
       if (!cancelled)
       {
-        AtomicReference<InitialLdapContext> aux = new AtomicReference<>(ctx2);
+        AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(ctx2);
         cancelled = !loadADSAndAcceptCertificates(destinationServerCI, aux, uData, false);
         ctx2 = aux.get();
       }
@@ -2744,7 +2798,7 @@
     int port = argParser.getPortToDisable();
 
     /* Try to connect to the server. */
-    InitialLdapContext ctx = null;
+    ConnectionWrapper ctx = null;
 
     while (ctx == null && !cancelled)
     {
@@ -2758,7 +2812,7 @@
         adminUid = sourceServerCI.getProvidedAdminUID();
         adminPwd = sourceServerCI.getBindPassword();
 
-        ctx = createInitialLdapContextInteracting(sourceServerCI);
+        ctx = createConnectionInteracting(sourceServerCI);
         if (ctx == null)
         {
           cancelled = true;
@@ -2795,7 +2849,7 @@
       // disableReplication(DisableReplicationUserData) method.  Here we have
       // to load the ADS to ask the user to accept the certificates and
       // eventually admin authentication data.
-      AtomicReference<InitialLdapContext> aux = new AtomicReference<>(ctx);
+      AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(ctx);
       cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false);
       ctx = aux.get();
     }
@@ -2840,7 +2894,8 @@
     if (disableReplicationServer && repPort < 0)
     {
       disableReplicationServer = false;
-      final LocalizableMessage msg = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(getHostPort(ctx));
+      final LocalizableMessage msg = INFO_REPLICATION_PROMPT_NO_REPLICATION_SERVER_TO_DISABLE.get(
+          getHostPort(ctx.getLdapContext()));
       try
       {
         cancelled = askConfirmation(msg, false, logger);
@@ -2860,18 +2915,19 @@
     if (!cancelled && !disableAll)
     {
       List<String> suffixes = argParser.getBaseDNs();
-      checkSuffixesForDisableReplication(suffixes, ctx, true, !disableReplicationServer);
+      checkSuffixesForDisableReplication(suffixes, ctx.getLdapContext(), true, !disableReplicationServer);
       cancelled = suffixes.isEmpty() && !disableReplicationServer;
 
       uData.setBaseDNs(suffixes);
 
       if (!uData.disableReplicationServer() && repPort > 0 &&
-          disableAllBaseDns(ctx, uData) && !argParser.advancedArg.isPresent())
+          disableAllBaseDns(ctx.getLdapContext(), uData) && !argParser.advancedArg.isPresent())
       {
         try
         {
           uData.setDisableReplicationServer(askConfirmation(
-              INFO_REPLICATION_DISABLE_ALL_SUFFIXES_DISABLE_REPLICATION_SERVER.get(getHostPort(ctx), repPort), true,
+              INFO_REPLICATION_DISABLE_ALL_SUFFIXES_DISABLE_REPLICATION_SERVER.get(
+                  getHostPort(ctx.getLdapContext()), repPort), true,
               logger));
         }
         catch (ClientException ce)
@@ -3005,16 +3061,16 @@
    */
   private boolean promptIfRequiredForPreOrPost(MonoServerReplicationUserData uData)
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper ctx = null;
     try
     {
-      ctx = getInitialLdapContext(uData);
+      ctx = getConnection(uData);
       if (ctx == null)
       {
         return false;
       }
       List<String> suffixes = argParser.getBaseDNs();
-      checkSuffixesForInitializeReplication(suffixes, ctx, true);
+      checkSuffixesForInitializeReplication(suffixes, ctx.getLdapContext(), true);
       uData.setBaseDNs(suffixes);
       return !suffixes.isEmpty();
     }
@@ -3024,6 +3080,20 @@
     }
   }
 
+  private ConnectionWrapper getConnection(MonoServerReplicationUserData uData)
+  {
+    try
+    {
+      InitialLdapContext ctx = getInitialLdapContext(uData);
+      return new ConnectionWrapper(ctx, sourceServerCI.getConnectTimeout(), getTrustManager(sourceServerCI));
+    }
+    catch (NamingException ce)
+    {
+      logger.warn(LocalizableMessage.raw("An error occured " + ce));
+      return null;
+    }
+  }
+
   private InitialLdapContext getInitialLdapContext(MonoServerReplicationUserData uData)
   {
     // Try to connect to the server.
@@ -3082,10 +3152,10 @@
   private boolean promptIfRequired(StatusReplicationUserData uData)
   throws ReplicationCliException
   {
-    InitialLdapContext ctx = null;
+    ConnectionWrapper ctx = null;
     try
     {
-      ctx = getInitialLdapContext(uData);
+      ctx = getConnection(uData);
       if (ctx == null)
       {
         return false;
@@ -3096,7 +3166,7 @@
       // statusReplication(StatusReplicationUserData) method. Here we have
       // to load the ADS to ask the user to accept the certificates and
       // eventually admin authentication data.
-      AtomicReference<InitialLdapContext> aux = new AtomicReference<>(ctx);
+      AtomicReference<ConnectionWrapper> aux = new AtomicReference<>(ctx);
       boolean cancelled = !loadADSAndAcceptCertificates(sourceServerCI, aux, uData, false);
       ctx = aux.get();
       if (cancelled)
@@ -3150,7 +3220,7 @@
     sourceServerCI.initializeGlobalArguments(hostSource, portSource, adminUid, null, adminPwd,
         pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     /* Try to connect to the source server. */
-    InitialLdapContext ctxSource = null;
+    ConnectionWrapper ctxSource = null;
 
     while (ctxSource == null && !cancelled)
     {
@@ -3163,7 +3233,7 @@
         adminUid = sourceServerCI.getAdministratorUID();
         adminPwd = sourceServerCI.getBindPassword();
 
-        ctxSource = createInitialLdapContextInteracting(sourceServerCI);
+        ctxSource = createConnectionInteracting(sourceServerCI);
 
         if (ctxSource == null)
         {
@@ -3212,7 +3282,7 @@
     destinationServerCI.initializeGlobalArguments(hostDestination, portDestination, adminUid, null, adminPwd,
         pwdFile == null ? null : new LinkedHashMap<String, String>(pwdFile));
     /* Try to connect to the destination server. */
-    InitialLdapContext ctxDestination = null;
+    ConnectionWrapper ctxDestination = null;
 
     destinationServerCI.resetHeadingDisplayed();
     while (ctxDestination == null && !cancelled)
@@ -3237,7 +3307,7 @@
 
         if (!error)
         {
-          ctxDestination = createInitialLdapContextInteracting(destinationServerCI, true);
+          ctxDestination = createConnectionInteracting(destinationServerCI, true);
 
           if (ctxDestination == null)
           {
@@ -3269,14 +3339,16 @@
     if (!cancelled)
     {
       List<String> suffixes = argParser.getBaseDNs();
-      cancelled = serversOperations.continueAfterUserInput(suffixes, ctxSource, ctxDestination, true);
+      cancelled = serversOperations.continueAfterUserInput(
+          suffixes, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), true);
       uData.setBaseDNs(suffixes);
     }
 
     if (!cancelled)
     {
       println();
-      cancelled = serversOperations.confirmOperation(uData, ctxSource, ctxDestination, true);
+      cancelled = serversOperations.confirmOperation(
+          uData, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), true);
       println();
     }
 
@@ -3463,30 +3535,28 @@
   /**
    * Tells whether the server to which the LdapContext is connected has a
    * replication port or not.
-   * @param ctx the InitialLdapContext to be used.
+   * @param connWrapper the InitialLdapContext to be used.
    * @return <CODE>true</CODE> if the replication port for the server could
    * be found and <CODE>false</CODE> otherwise.
    */
-  private boolean hasReplicationPort(InitialLdapContext ctx)
+  private boolean hasReplicationPort(ConnectionWrapper connWrapper)
   {
-    return getReplicationPort(ctx) != -1;
+    return getReplicationPort(connWrapper) != -1;
   }
 
   /**
    * Returns the replication port of server to which the LdapContext is
    * connected and -1 if the replication port could not be found.
-   * @param ctx the InitialLdapContext to be used.
+   * @param connWrapper the InitialLdapContext to be used.
    * @return the replication port of server to which the LdapContext is
    * connected and -1 if the replication port could not be found.
    */
-  private int getReplicationPort(InitialLdapContext ctx)
+  private int getReplicationPort(ConnectionWrapper connWrapper)
   {
     int replicationPort = -1;
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
 
       ReplicationSynchronizationProviderCfgClient sync =
           (ReplicationSynchronizationProviderCfgClient)
@@ -3514,7 +3584,7 @@
    * accordingly.
    *
    * @param ci the LDAP connection to the server
-   * @param ctx the Ldap context to be used in an array: note the context
+   * @param connWrapper the Ldap context to be used in an array: note the context
    * may be modified with the new credentials provided by the user.
    * @param uData the ReplicationUserData to be updated.
    * @param isFirstOrSourceServer whether this is the first server in the
@@ -3527,12 +3597,13 @@
    * messages.
    */
   private boolean loadADSAndAcceptCertificates(LDAPConnectionConsoleInteraction ci,
-      AtomicReference<InitialLdapContext> ctx, ReplicationUserData uData, boolean isFirstOrSourceServer)
+      AtomicReference<ConnectionWrapper> connWrapper, ReplicationUserData uData, boolean isFirstOrSourceServer)
   throws ReplicationCliException
   {
     boolean cancelled = false;
     boolean triedWithUserProvidedAdmin = false;
-    final InitialLdapContext ctx1 = ctx.get();
+    final ConnectionWrapper connWrapper1 = connWrapper.get();
+    final InitialLdapContext ctx1 = connWrapper1.getLdapContext();
     String host = getHostName(ctx1);
     int port = getPort(ctx1);
     boolean isSSL = isSSL(ctx1);
@@ -3546,7 +3617,7 @@
     }
     try
     {
-      ADSContext adsContext = new ADSContext(ctx1);
+      ADSContext adsContext = new ADSContext(connWrapper1);
       if (adsContext.hasAdminData())
       {
         boolean reloadTopology = true;
@@ -3629,8 +3700,10 @@
                     final InitialLdapContext ctx2 = createAdministrativeContext(host, port, isSSL,
                         isStartTLS, getAdministratorDN(adminUid),
                         adminPwd, getConnectTimeout(), getTrustManager(ci));
-                    ctx.set(ctx2);
-                    adsContext = new ADSContext(ctx2);
+                    final ConnectionWrapper connWrapper2 =
+                        new ConnectionWrapper(ctx2, getConnectTimeout(), getTrustManager(ci));
+                    connWrapper.set(connWrapper2);
+                    adsContext = new ADSContext(connWrapper2);
                     cache = new TopologyCache(adsContext, getTrustManager(ci),
                         getConnectTimeout());
                     cache.getFilter().setSearchMonitoringInformation(false);
@@ -3716,15 +3789,15 @@
   /**
    * Tells whether there is a Global Administrator defined in the server
    * to which the InitialLdapContext is connected.
-   * @param ctx the InitialLdapContext.
+   * @param connWrapper the InitialLdapContext.
    * @return <CODE>true</CODE> if we could find an administrator and
    * <CODE>false</CODE> otherwise.
    */
-  private boolean hasAdministrator(InitialLdapContext ctx)
+  private boolean hasAdministrator(ConnectionWrapper connWrapper)
   {
     try
     {
-      ADSContext adsContext = new ADSContext(ctx);
+      ADSContext adsContext = new ADSContext(connWrapper);
       if (adsContext.hasAdminData())
       {
         Set<?> administrators = adsContext.readAdministratorRegistry();
@@ -3743,18 +3816,18 @@
    * Tells whether there is a Global Administrator corresponding to the provided
    * ReplicationUserData defined in the server to which the InitialLdapContext
    * is connected.
-   * @param ctx the InitialLdapContext.
+   * @param connWrapper the InitialLdapContext.
    * @param uData the user data
    * @return <CODE>true</CODE> if we could find an administrator and
    * <CODE>false</CODE> otherwise.
    */
-  private boolean hasAdministrator(InitialLdapContext ctx,
+  private boolean hasAdministrator(ConnectionWrapper connWrapper,
       ReplicationUserData uData)
   {
     String adminUid = uData.getAdminUid();
     try
     {
-      ADSContext adsContext = new ADSContext(ctx);
+      ADSContext adsContext = new ADSContext(connWrapper);
       Set<Map<AdministratorProperty, Object>> administrators =
         adsContext.readAdministratorRegistry();
       for (Map<AdministratorProperty, Object> admin : administrators)
@@ -3943,16 +4016,16 @@
    */
   private ReplicationCliReturnCode enableReplication(EnableReplicationUserData uData)
   {
-    InitialLdapContext ctx1 = null;
-    InitialLdapContext ctx2 = null;
+    ConnectionWrapper ctx1 = null;
+    ConnectionWrapper ctx2 = null;
     try
     {
       println();
       print(formatter.getFormattedWithPoints(INFO_REPLICATION_CONNECTING.get()));
 
       LinkedList<LocalizableMessage> errorMessages = new LinkedList<>();
-      ctx1 = createAdministrativeContext(uData, true, errorMessages);
-      ctx2 = createAdministrativeContext(uData, false, errorMessages);
+      ctx1 = createAdministrativeConnection(uData, true, errorMessages);
+      ctx2 = createAdministrativeConnection(uData, false, errorMessages);
 
       if (!errorMessages.isEmpty())
       {
@@ -3998,7 +4071,7 @@
       try
       {
         updateConfiguration(ctx1, ctx2, uData);
-        printSuccessfullyEnabled(ctx1, ctx2);
+        printSuccessfullyEnabled(ctx1.getLdapContext(), ctx2.getLdapContext());
         return SUCCESSFUL;
       }
       catch (ReplicationCliException rce)
@@ -4015,26 +4088,27 @@
     }
   }
 
-  private void checkReplicationServerAlreadyConfigured(InitialLdapContext ctx, EnableReplicationServerData server)
+  private void checkReplicationServerAlreadyConfigured(
+      ConnectionWrapper connWrapper, EnableReplicationServerData server)
   {
-    int repPort = getReplicationPort(ctx);
+    int repPort = getReplicationPort(connWrapper);
     if (!server.configureReplicationServer() && repPort > 0)
     {
-      println(INFO_REPLICATION_SERVER_CONFIGURED_WARNING.get(getHostPort(ctx), repPort));
+      println(INFO_REPLICATION_SERVER_CONFIGURED_WARNING.get(getHostPort(connWrapper.getLdapContext()), repPort));
       println();
     }
   }
 
   private void checksForNonInteractiveMode(EnableReplicationUserData uData,
-      InitialLdapContext ctx1, InitialLdapContext ctx2, LinkedList<LocalizableMessage> errorMessages)
+      ConnectionWrapper connWrapper1, ConnectionWrapper connWrapper2, LinkedList<LocalizableMessage> errorMessages)
   {
     EnableReplicationServerData server1 = uData.getServer1();
     EnableReplicationServerData server2 = uData.getServer2();
     String host1 = server1.getHostName();
     String host2 = server2.getHostName();
 
-    int replPort1 = checkReplicationPort(ctx1, server1, errorMessages);
-    int replPort2 = checkReplicationPort(ctx2, server2, errorMessages);
+    int replPort1 = checkReplicationPort(connWrapper1, server1, errorMessages);
+    int replPort2 = checkReplicationPort(connWrapper2, server2, errorMessages);
     if (replPort1 > 0 && replPort1 == replPort2 && host1.equalsIgnoreCase(host2))
     {
       errorMessages.add(ERR_REPLICATION_SAME_REPLICATION_PORT.get(replPort1, host1));
@@ -4050,9 +4124,9 @@
   }
 
   private int checkReplicationPort(
-      InitialLdapContext ctx, EnableReplicationServerData server, LinkedList<LocalizableMessage> errorMessages)
+      ConnectionWrapper connWrapper, EnableReplicationServerData server, LinkedList<LocalizableMessage> errorMessages)
   {
-    int replPort = getReplicationPort(ctx);
+    int replPort = getReplicationPort(connWrapper);
     boolean hasReplicationPort = replPort > 0;
     if (replPort < 0 && server.configureReplicationServer())
     {
@@ -4105,6 +4179,23 @@
     }
   }
 
+  private ConnectionWrapper createAdministrativeConnection(EnableReplicationUserData uData, boolean isFirstSetOfValues,
+      LinkedList<LocalizableMessage> errorMessages)
+  {
+    EnableReplicationServerData server = isFirstSetOfValues ? uData.getServer1() : uData.getServer2();
+    try
+    {
+      return new ConnectionWrapper(createAdministrativeContext(uData, isFirstSetOfValues, errorMessages),
+          getConnectTimeout(), getTrustManager(sourceServerCI));
+    }
+    catch (NamingException e)
+    {
+      String hostPort = getServerRepresentation(server.getHostName(), server.getPort());
+      logger.error(LocalizableMessage.raw("Error when creating connection for:" + hostPort));
+      return null;
+    }
+  }
+
   private InitialLdapContext createAdministrativeContext(EnableReplicationUserData uData, boolean isFirstSetOfValues,
       LinkedList<LocalizableMessage> errorMessages)
   {
@@ -4139,8 +4230,8 @@
         ? getAdministratorDN(uData.getAdminUid())
         : uData.getBindDn();
 
-    InitialLdapContext ctx = createAdministrativeContext(uData, bindDn);
-    if (ctx == null)
+    ConnectionWrapper connWrapper = createAdministrativeConnection(uData, bindDn);
+    if (connWrapper == null)
     {
       return ERROR_CONNECTING;
     }
@@ -4152,7 +4243,8 @@
       println();
 
       List<String> suffixes = uData.getBaseDNs();
-      checkSuffixesForDisableReplication(suffixes, ctx, false, !uData.disableReplicationServer());
+      checkSuffixesForDisableReplication(
+          suffixes, connWrapper.getLdapContext(), false, !uData.disableReplicationServer());
       if (suffixes.isEmpty() && !uData.disableReplicationServer() && !uData.disableAll())
       {
         return REPLICATION_CANNOT_BE_DISABLED_ON_BASEDN;
@@ -4161,7 +4253,7 @@
 
       if (!isInteractive())
       {
-        boolean hasReplicationPort = hasReplicationPort(ctx);
+        boolean hasReplicationPort = hasReplicationPort(connWrapper);
         if (uData.disableAll() && hasReplicationPort)
         {
           uData.setDisableReplicationServer(true);
@@ -4169,7 +4261,8 @@
         else if (uData.disableReplicationServer() && !hasReplicationPort && !uData.disableAll())
         {
           uData.setDisableReplicationServer(false);
-          println(INFO_REPLICATION_WARNING_NO_REPLICATION_SERVER_TO_DISABLE.get(getHostPort(ctx)));
+          println(
+              INFO_REPLICATION_WARNING_NO_REPLICATION_SERVER_TO_DISABLE.get(getHostPort(connWrapper.getLdapContext())));
           println();
         }
       }
@@ -4179,17 +4272,19 @@
         printNewCommandBuilder(DISABLE_REPLICATION_SUBCMD_NAME, uData);
       }
 
-      if (!isInteractive() && !uData.disableReplicationServer() && !uData.disableAll() && disableAllBaseDns(ctx, uData)
-          && hasReplicationPort(ctx))
+      if (!isInteractive() && !uData.disableReplicationServer() && !uData.disableAll()
+          && disableAllBaseDns(connWrapper.getLdapContext(), uData) && hasReplicationPort(connWrapper))
       {
         // Inform the user that the replication server will not be disabled.
         // Inform also of the user of the disableReplicationServerArg
-        println(INFO_REPLICATION_DISABLE_ALL_SUFFIXES_KEEP_REPLICATION_SERVER.get(getHostPort(ctx),
-            argParser.disableReplicationServerArg.getLongIdentifier(), argParser.disableAllArg.getLongIdentifier()));
+        println(INFO_REPLICATION_DISABLE_ALL_SUFFIXES_KEEP_REPLICATION_SERVER.get(
+            getHostPort(connWrapper.getLdapContext()),
+            argParser.disableReplicationServerArg.getLongIdentifier(),
+            argParser.disableAllArg.getLongIdentifier()));
       }
       try
       {
-        updateConfiguration(ctx, uData);
+        updateConfiguration(connWrapper, uData);
         return SUCCESSFUL;
       }
       catch (ReplicationCliException rce)
@@ -4202,7 +4297,7 @@
     }
     finally
     {
-      close(ctx);
+      close(connWrapper);
     }
   }
 
@@ -4217,7 +4312,7 @@
   private ReplicationCliReturnCode statusReplication(
       StatusReplicationUserData uData)
   {
-    final InitialLdapContext ctx = createAdministrativeContext(uData);
+    final ConnectionWrapper ctx = createAdministrativeConnection(uData);
     if (ctx == null)
     {
       return ERROR_CONNECTING;
@@ -4521,7 +4616,7 @@
    * replication domains must be configured or not.
    */
   private void checkSuffixesForEnableReplication(Collection<String> suffixes,
-      InitialLdapContext ctx1, InitialLdapContext ctx2,
+      ConnectionWrapper ctx1, ConnectionWrapper ctx2,
       boolean interactive, EnableReplicationUserData uData)
   {
     EnableReplicationServerData server1 = uData.getServer1();
@@ -4531,9 +4626,9 @@
     if (server1.configureReplicationDomain() &&
         server2.configureReplicationDomain())
     {
-      availableSuffixes.addAll(getCommonSuffixes(ctx1, ctx2,
+      availableSuffixes.addAll(getCommonSuffixes(ctx1.getLdapContext(), ctx2.getLdapContext(),
             SuffixRelationType.NOT_FULLY_REPLICATED));
-      alreadyReplicatedSuffixes.addAll(getCommonSuffixes(ctx1, ctx2,
+      alreadyReplicatedSuffixes.addAll(getCommonSuffixes(ctx1.getLdapContext(), ctx2.getLdapContext(),
             SuffixRelationType.FULLY_REPLICATED));
     }
     else if (server1.configureReplicationDomain())
@@ -5018,8 +5113,8 @@
    * parameters to update the configuration.
    * @throws ReplicationCliException if there is an error.
    */
-  private void updateConfiguration(InitialLdapContext ctx1,
-      InitialLdapContext ctx2, EnableReplicationUserData uData)
+  private void updateConfiguration(ConnectionWrapper ctx1,
+      ConnectionWrapper ctx2, EnableReplicationUserData uData)
   throws ReplicationCliException
   {
     final Set<String> twoReplServers = new LinkedHashSet<>();
@@ -5033,8 +5128,8 @@
     filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
     filter.addBaseDNToSearch(Constants.SCHEMA_DN);
     addBaseDNs(filter, uData.getBaseDNs());
-    ServerDescriptor serverDesc1 = createStandalone(ctx1, filter);
-    ServerDescriptor serverDesc2 = createStandalone(ctx2, filter);
+    ServerDescriptor serverDesc1 = createStandalone(ctx1.getLdapContext(), filter);
+    ServerDescriptor serverDesc2 = createStandalone(ctx2.getLdapContext(), filter);
 
     ADSContext adsCtx1 = new ADSContext(ctx1);
     ADSContext adsCtx2 = new ADSContext(ctx2);
@@ -5047,8 +5142,8 @@
       try
       {
         final Set<PreferredConnection> cnx = new LinkedHashSet<>();
-        cnx.addAll(getPreferredConnections(ctx1));
-        cnx.addAll(getPreferredConnections(ctx2));
+        cnx.addAll(getPreferredConnections(ctx1.getLdapContext()));
+        cnx.addAll(getPreferredConnections(ctx2.getLdapContext()));
         TopologyCache cache1 = createTopologyCache(adsCtx1, cnx, uData);
         if (cache1 != null)
         {
@@ -5121,8 +5216,8 @@
 
     // These are used to identify which server we use to initialize
     // the contents of the other server (if any).
-    InitialLdapContext ctxSource = null;
-    InitialLdapContext ctxDestination = null;
+    ConnectionWrapper ctxSource = null;
+    ConnectionWrapper ctxDestination = null;
     ADSContext adsCtxSource = null;
 
     boolean adsAlreadyReplicated = false;
@@ -5138,7 +5233,7 @@
         Set<Map<ServerProperty, Object>> registry2 = adsCtx2.readServerRegistry();
         if (registry2.size() <= 1)
         {
-          if (!hasAdministrator(adsCtx1.getDirContext(), uData))
+          if (!hasAdministrator(adsCtx1.getConnection(), uData))
           {
             adsCtx1.createAdministrator(getAdministratorProperties(uData));
           }
@@ -5156,7 +5251,7 @@
         }
         else if (registry1.size() <= 1)
         {
-          if (!hasAdministrator(adsCtx2.getDirContext(), uData))
+          if (!hasAdministrator(adsCtx2.getConnection(), uData))
           {
             adsCtx2.createAdministrator(getAdministratorProperties(uData));
           }
@@ -5207,7 +5302,7 @@
             {
               // The case where only the first ADS is replicated or none
               // is replicated.
-              if (!hasAdministrator(adsCtx1.getDirContext(), uData))
+              if (!hasAdministrator(adsCtx1.getConnection(), uData))
               {
                 adsCtx1.createAdministrator(getAdministratorProperties(uData));
               }
@@ -5225,7 +5320,7 @@
             }
             else if (isADS2Replicated)
             {
-              if (!hasAdministrator(adsCtx2.getDirContext(), uData))
+              if (!hasAdministrator(adsCtx2.getConnection(), uData))
               {
                 adsCtx2.createAdministrator(getAdministratorProperties(uData));
               }
@@ -5246,7 +5341,7 @@
       }
       else if (!adsCtx1.hasAdminData() && adsCtx2.hasAdminData())
       {
-        if (!hasAdministrator(adsCtx2.getDirContext(), uData))
+        if (!hasAdministrator(adsCtx2.getConnection(), uData))
         {
           adsCtx2.createAdministrator(getAdministratorProperties(uData));
         }
@@ -5265,7 +5360,7 @@
       }
       else if (adsCtx1.hasAdminData() && !adsCtx2.hasAdminData())
       {
-        if (!hasAdministrator(adsCtx1.getDirContext(), uData))
+        if (!hasAdministrator(adsCtx1.getConnection(), uData))
         {
           adsCtx1.createAdministrator(getAdministratorProperties(uData));
         }
@@ -5311,14 +5406,13 @@
     {
       try
       {
-        ServerDescriptor.seedAdsTrustStore(ctxDestination,
-            adsCtxSource.getTrustedCertificates());
+        ServerDescriptor.seedAdsTrustStore(ctxDestination.getLdapContext(), adsCtxSource.getTrustedCertificates());
       }
       catch (Throwable t)
       {
         logger.error(LocalizableMessage.raw("Error seeding truststores: "+t, t));
         throw new ReplicationCliException(
-            ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(getHostPort(ctxDestination),
+            ERR_REPLICATION_ENABLE_SEEDING_TRUSTSTORE.get(getHostPort(ctxDestination.getLdapContext()),
             getHostPort(adsCtxSource.getDirContext()), toString(t)),
             ERROR_SEEDING_TRUSTORE, t);
       }
@@ -5348,8 +5442,8 @@
     try
     {
       Set<PreferredConnection> cnx = new LinkedHashSet<>();
-      cnx.addAll(getPreferredConnections(ctx1));
-      cnx.addAll(getPreferredConnections(ctx2));
+      cnx.addAll(getPreferredConnections(ctx1.getLdapContext()));
+      cnx.addAll(getPreferredConnections(ctx2.getLdapContext()));
       cache1 = createTopologyCache(adsCtx1, cnx, uData);
       if (cache1 != null)
       {
@@ -5374,8 +5468,8 @@
           ERROR_READING_TOPOLOGY_CACHE, tce);
     }
 
-    addToSets(serverDesc1, uData.getServer1(), ctx1, twoReplServers, usedReplicationServerIds);
-    addToSets(serverDesc2, uData.getServer2(), ctx2, twoReplServers, usedReplicationServerIds);
+    addToSets(serverDesc1, uData.getServer1(), ctx1.getLdapContext(), twoReplServers, usedReplicationServerIds);
+    addToSets(serverDesc2, uData.getServer2(), ctx2.getLdapContext(), twoReplServers, usedReplicationServerIds);
 
     for (String baseDN : uData.getBaseDNs())
     {
@@ -5436,11 +5530,11 @@
     if (adsMergeDone)
     {
       PointAdder pointAdder = new PointAdder(this);
-      print(INFO_ENABLE_REPLICATION_INITIALIZING_ADS_ALL.get(getHostPort(ctxSource)));
+      print(INFO_ENABLE_REPLICATION_INITIALIZING_ADS_ALL.get(getHostPort(ctxSource.getLdapContext())));
       pointAdder.start();
       try
       {
-        initializeAllSuffix(ADSContext.getAdministrationSuffixDN(), ctxSource, false);
+        initializeAllSuffix(ADSContext.getAdministrationSuffixDN(), ctxSource.getLdapContext(), false);
       }
       finally
       {
@@ -5454,9 +5548,10 @@
     {
       print(formatter.getFormattedWithPoints(
           INFO_ENABLE_REPLICATION_INITIALIZING_ADS.get(
-              getHostPort(ctxDestination), getHostPort(ctxSource))));
+              getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext()))));
 
-      initializeSuffix(ADSContext.getAdministrationSuffixDN(), ctxSource, ctxDestination, false);
+      initializeSuffix(
+          ADSContext.getAdministrationSuffixDN(), ctxSource.getLdapContext(), ctxDestination.getLdapContext(), false);
       print(formatter.getFormattedDone());
       println();
     }
@@ -5478,11 +5573,11 @@
       {
         PointAdder pointAdder = new PointAdder(this);
         println(INFO_ENABLE_REPLICATION_INITIALIZING_SCHEMA.get(
-            getHostPort(ctxDestination), getHostPort(ctxSource)));
+            getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext())));
         pointAdder.start();
         try
         {
-          initializeAllSuffix(Constants.SCHEMA_DN, ctxSource, false);
+          initializeAllSuffix(Constants.SCHEMA_DN, ctxSource.getLdapContext(), false);
         }
         finally
         {
@@ -5493,8 +5588,8 @@
       else
       {
         print(formatter.getFormattedWithPoints(INFO_ENABLE_REPLICATION_INITIALIZING_SCHEMA.get(
-            getHostPort(ctxDestination), getHostPort(ctxSource))));
-        initializeSuffix(Constants.SCHEMA_DN, ctxSource, ctxDestination, false);
+            getHostPort(ctxDestination.getLdapContext()), getHostPort(ctxSource.getLdapContext()))));
+        initializeSuffix(Constants.SCHEMA_DN, ctxSource.getLdapContext(), ctxDestination.getLdapContext(), false);
       }
       print(formatter.getFormattedDone());
       println();
@@ -5515,7 +5610,7 @@
     }
   }
 
-  private void configureToReplicateBaseDN(EnableReplicationServerData server, InitialLdapContext ctx,
+  private void configureToReplicateBaseDN(EnableReplicationServerData server, ConnectionWrapper ctx,
       ServerDescriptor serverDesc, TopologyCache cache, String baseDN, Set<Integer> usedIds,
       Set<String> alreadyConfiguredServers, Set<String> repServers, final Set<String> allRepServers,
       Set<String> alreadyConfiguredReplicationServers) throws ReplicationCliException
@@ -5527,9 +5622,9 @@
       {
         configureToReplicateBaseDN(ctx, baseDN, repServers, usedIds);
       }
-      catch (OpenDsException ode)
+      catch (Exception ode)
       {
-        LocalizableMessage msg = getMessageForEnableException(getHostPort(ctx), baseDN);
+        LocalizableMessage msg = getMessageForEnableException(getHostPort(ctx.getLdapContext()), baseDN);
         throw new ReplicationCliException(msg, ERROR_ENABLING_REPLICATION_ON_BASEDN, ode);
       }
     }
@@ -5542,7 +5637,7 @@
     }
   }
 
-  private void configureServer(InitialLdapContext ctx, ServerDescriptor serverDesc,
+  private void configureServer(ConnectionWrapper ctx, ServerDescriptor serverDesc,
       EnableReplicationServerData enableServer, IntegerArgument replicationPortArg,
       Set<Integer> usedReplicationServerIds, Set<String> allRepServers,
       Set<String> alreadyConfiguredReplicationServers, Arg2<Number, Number> replicationServerAlreadyConfiguredMsg)
@@ -5555,9 +5650,9 @@
         configureAsReplicationServer(ctx, enableServer.getReplicationPort(), enableServer.isSecureReplication(),
             allRepServers, usedReplicationServerIds);
       }
-      catch (OpenDsException ode)
+      catch (Exception ode)
       {
-        throw errorConfiguringReplicationServer(ctx, ode);
+        throw errorConfiguringReplicationServer(ctx.getLdapContext(), ode);
       }
     }
     else if (serverDesc.isReplicationServer())
@@ -5566,9 +5661,9 @@
       {
         updateReplicationServer(ctx, allRepServers);
       }
-      catch (OpenDsException ode)
+      catch (Exception ode)
       {
-        throw errorConfiguringReplicationServer(ctx, ode);
+        throw errorConfiguringReplicationServer(ctx.getLdapContext(), ode);
       }
       if (replicationPortArg.isPresent() && enableServer.getReplicationPort() != serverDesc.getReplicationServerPort())
       {
@@ -5581,7 +5676,7 @@
     alreadyConfiguredReplicationServers.add(serverDesc.getId());
   }
 
-  private ReplicationCliException errorConfiguringReplicationServer(InitialLdapContext ctx, OpenDsException ode)
+  private ReplicationCliException errorConfiguringReplicationServer(InitialLdapContext ctx, Exception ode)
   {
     return new ReplicationCliException(
         ERR_REPLICATION_CONFIGURING_REPLICATIONSERVER.get(getHostPort(ctx)),
@@ -5626,7 +5721,7 @@
    * parameters to update the configuration.
    * @throws ReplicationCliException if there is an error.
    */
-  private void updateConfiguration(InitialLdapContext ctx,
+  private void updateConfiguration(ConnectionWrapper ctx,
       DisableReplicationUserData uData) throws ReplicationCliException
   {
     TopologyCacheFilter filter = new TopologyCacheFilter();
@@ -5636,7 +5731,7 @@
       filter.addBaseDNToSearch(ADSContext.getAdministrationSuffixDN());
       addBaseDNs(filter, uData.getBaseDNs());
     }
-    ServerDescriptor server = createStandalone(ctx, filter);
+    ServerDescriptor server = createStandalone(ctx.getLdapContext(), filter);
 
     ADSContext adsCtx = new ADSContext(ctx);
 
@@ -5649,7 +5744,7 @@
       if (adsCtx.hasAdminData() && tryToUpdateRemote)
       {
         cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
-        cache.setPreferredConnections(getPreferredConnections(ctx));
+        cache.setPreferredConnections(getPreferredConnections(ctx.getLdapContext()));
         cache.getFilter().setSearchMonitoringInformation(false);
         if (!uData.disableAll())
         {
@@ -5820,9 +5915,9 @@
     boolean forceDisableADS = false;
     boolean schemaReplicated = false;
     boolean adsReplicated = false;
-    boolean disableAllBaseDns = disableAllBaseDns(ctx, uData);
+    boolean disableAllBaseDns = disableAllBaseDns(ctx.getLdapContext(), uData);
 
-    Collection<ReplicaDescriptor> replicas = getReplicas(ctx);
+    Collection<ReplicaDescriptor> replicas = getReplicas(ctx.getLdapContext());
     for (ReplicaDescriptor rep : replicas)
     {
       String dn = rep.getSuffix().getDN();
@@ -5920,7 +6015,7 @@
       }
       catch (OpenDsException ode)
       {
-        LocalizableMessage msg = getMessageForDisableException(getHostPort(ctx), baseDN);
+        LocalizableMessage msg = getMessageForDisableException(getHostPort(ctx.getLdapContext()), baseDN);
         throw new ReplicationCliException(msg,
             ERROR_DISABLING_REPLICATION_ON_BASEDN, ode);
       }
@@ -5957,13 +6052,13 @@
           }
         }
       }
-      String bindDn = getBindDN(ctx);
-      String pwd = getBindPassword(ctx);
+      String bindDn = getBindDN(ctx.getLdapContext());
+      String pwd = getBindPassword(ctx.getLdapContext());
       for (ServerDescriptor s : serversToUpdate)
       {
         removeReferencesInServer(s, replicationServerHostPort, bindDn, pwd,
             baseDNsToUpdate, disableReplicationServer,
-            getPreferredConnections(ctx));
+            getPreferredConnections(ctx.getLdapContext()));
       }
 
       if (disableReplicationServer)
@@ -6041,7 +6136,7 @@
    * parameters to update the configuration.
    * @throws ReplicationCliException if there is an error.
    */
-  private void displayStatus(InitialLdapContext ctx,
+  private void displayStatus(ConnectionWrapper ctx,
       StatusReplicationUserData uData) throws ReplicationCliException
   {
     ADSContext adsCtx = new ADSContext(ctx);
@@ -6051,7 +6146,7 @@
     try
     {
       cache = new TopologyCache(adsCtx, getTrustManager(sourceServerCI), getConnectTimeout());
-      cache.setPreferredConnections(getPreferredConnections(ctx));
+      cache.setPreferredConnections(getPreferredConnections(ctx.getLdapContext()));
       addBaseDNs(cache.getFilter(), uData.getBaseDNs());
       cache.reloadTopology();
     }
@@ -6132,7 +6227,7 @@
       }
       if (!rServers.isEmpty())
       {
-        displayStatus(rServers, uData.isScriptFriendly(), getPreferredConnections(ctx));
+        displayStatus(rServers, uData.isScriptFriendly(), getPreferredConnections(ctx.getLdapContext()));
         somethingDisplayed = true;
       }
     }
@@ -6162,7 +6257,7 @@
       Set<ReplicaDescriptor> replicasWithNoReplicationServer = new HashSet<>();
       Set<ServerDescriptor> serversWithNoReplica = new HashSet<>();
       displayStatus(orderedReplicaLists, uData.isScriptFriendly(),
-            getPreferredConnections(ctx),
+            getPreferredConnections(ctx.getLdapContext()),
             cache.getServers(),
             replicasWithNoReplicationServer, serversWithNoReplica);
       somethingDisplayed = true;
@@ -6721,17 +6816,15 @@
    * that will be used by the newly configured replication server.
    * @throws OpenDsException if there is an error updating the configuration.
    */
-  private void configureAsReplicationServer(InitialLdapContext ctx,
+  private void configureAsReplicationServer(ConnectionWrapper ctx,
       int replicationPort, boolean useSecureReplication,
       Set<String> replicationServers,
-      Set<Integer> usedReplicationServerIds) throws OpenDsException
+      Set<Integer> usedReplicationServerIds) throws Exception
   {
     print(formatter.getFormattedWithPoints(
-        INFO_REPLICATION_ENABLE_CONFIGURING_REPLICATION_SERVER.get(getHostPort(ctx))));
+        INFO_REPLICATION_ENABLE_CONFIGURING_REPLICATION_SERVER.get(getHostPort(ctx.getLdapContext()))));
 
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(
-        JNDIDirContextAdaptor.adapt(ctx));
-    RootCfgClient root = mCtx.getRootConfiguration();
+    RootCfgClient root = ctx.getRootConfiguration();
 
     /* Configure Synchronization plugin. */
     ReplicationSynchronizationProviderCfgClient sync = null;
@@ -6742,7 +6835,8 @@
     }
     catch (ManagedObjectNotFoundException monfe)
     {
-      logger.info(LocalizableMessage.raw("Synchronization server does not exist in " + getHostPort(ctx)));
+      logger.info(LocalizableMessage.raw(
+          "Synchronization server does not exist in " + getHostPort(ctx.getLdapContext())));
     }
     if (sync == null)
     {
@@ -6820,15 +6914,13 @@
    * replication server will communicate with.
    * @throws OpenDsException if there is an error updating the configuration.
    */
-  private void updateReplicationServer(InitialLdapContext ctx,
-      Set<String> replicationServers) throws OpenDsException
+  private void updateReplicationServer(ConnectionWrapper ctx,
+      Set<String> replicationServers) throws Exception
   {
     print(formatter.getFormattedWithPoints(
-        INFO_REPLICATION_ENABLE_UPDATING_REPLICATION_SERVER.get(getHostPort(ctx))));
+        INFO_REPLICATION_ENABLE_UPDATING_REPLICATION_SERVER.get(getHostPort(ctx.getLdapContext()))));
 
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(
-        JNDIDirContextAdaptor.adapt(ctx));
-    RootCfgClient root = mCtx.getRootConfiguration();
+    RootCfgClient root = ctx.getRootConfiguration();
 
     ReplicationSynchronizationProviderCfgClient sync =
       (ReplicationSynchronizationProviderCfgClient)
@@ -6889,10 +6981,10 @@
    * that will be used by the newly configured replication server.
    * @throws OpenDsException if there is an error updating the configuration.
    */
-  private void configureToReplicateBaseDN(InitialLdapContext ctx,
+  private void configureToReplicateBaseDN(ConnectionWrapper ctx,
       String baseDN,
       Set<String> replicationServers,
-      Set<Integer> usedReplicationDomainIds) throws OpenDsException
+      Set<Integer> usedReplicationDomainIds) throws Exception
   {
     boolean userSpecifiedAdminBaseDN = false;
     List<String> l = argParser.getBaseDNs();
@@ -6904,16 +6996,14 @@
         && areDnsEqual(baseDN, ADSContext.getAdministrationSuffixDN()))
     {
       print(formatter.getFormattedWithPoints(
-          INFO_REPLICATION_ENABLE_CONFIGURING_ADS.get(getHostPort(ctx))));
+          INFO_REPLICATION_ENABLE_CONFIGURING_ADS.get(getHostPort(ctx.getLdapContext()))));
     }
     else
     {
       print(formatter.getFormattedWithPoints(
-          INFO_REPLICATION_ENABLE_CONFIGURING_BASEDN.get(baseDN, getHostPort(ctx))));
+          INFO_REPLICATION_ENABLE_CONFIGURING_BASEDN.get(baseDN, getHostPort(ctx.getLdapContext()))));
     }
-    ManagementContext mCtx = LDAPManagementContext.createFromContext(
-        JNDIDirContextAdaptor.adapt(ctx));
-    RootCfgClient root = mCtx.getRootConfiguration();
+    RootCfgClient root = ctx.getRootConfiguration();
 
     ReplicationSynchronizationProviderCfgClient sync =
       (ReplicationSynchronizationProviderCfgClient)
@@ -7039,16 +7129,18 @@
     {
       logger.info(LocalizableMessage.raw("Configuring server "+server.getHostPort(true)));
       InitialLdapContext ctx = null;
+      ConnectionWrapper conn = null;
       try
       {
         ctx = getDirContextForServer(cache, s);
+        conn = new ConnectionWrapper(ctx, getConnectTimeout(), getTrustManager(sourceServerCI));
         if (serversToConfigureDomain.contains(s))
         {
-          configureToReplicateBaseDN(ctx, baseDN, repServers, usedIds);
+          configureToReplicateBaseDN(conn, baseDN, repServers, usedIds);
         }
         if (replicationServersToConfigure.contains(s))
         {
-          updateReplicationServer(ctx, allRepServers);
+          updateReplicationServer(conn, allRepServers);
         }
       }
       catch (NamingException ne)
@@ -7057,7 +7149,7 @@
         LocalizableMessage msg = getMessageForException(ne, hostPort);
         throw new ReplicationCliException(msg, ERROR_CONNECTING, ne);
       }
-      catch (OpenDsException ode)
+      catch (Exception ode)
       {
         String hostPort = getHostPort2(s, cache.getPreferredConnections());
         LocalizableMessage msg = getMessageForEnableException(hostPort, baseDN);
@@ -7067,6 +7159,7 @@
       finally
       {
         close(ctx);
+        close(conn);
       }
       alreadyConfiguredServers.add(s.getId());
       alreadyConfiguredReplicationServers.add(s.getId());
@@ -7659,17 +7752,15 @@
     filter.setSearchBaseDNInformation(false);
     ServerLoader loader = new ServerLoader(server.getAdsProperties(), bindDn,
         pwd, getTrustManager(sourceServerCI), getConnectTimeout(), cnx, filter);
-    InitialLdapContext ctx = null;
+    ConnectionWrapper ctx = null;
     String lastBaseDN = null;
     String hostPort = null;
 
     try
     {
-      ctx = loader.createContext();
-      hostPort = getHostPort(ctx);
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      ctx = loader.createConnectionWrapper();
+      hostPort = getHostPort(ctx.getLdapContext());
+      RootCfgClient root = ctx.getRootConfiguration();
       ReplicationSynchronizationProviderCfgClient sync = null;
       try
       {
@@ -7756,7 +7847,7 @@
       LocalizableMessage msg = getMessageForException(ne, hostPort);
       throw new ReplicationCliException(msg, ERROR_CONNECTING, ne);
     }
-    catch (OpenDsException ode)
+    catch (Exception ode)
     {
       if (lastBaseDN != null)
       {
@@ -7786,15 +7877,12 @@
    * @throws ReplicationCliException if there is an error updating the
    * configuration of the server.
    */
-  private void deleteReplicationDomain(InitialLdapContext ctx,
-      String baseDN) throws ReplicationCliException
+  private void deleteReplicationDomain(ConnectionWrapper ctx, String baseDN) throws ReplicationCliException
   {
-    String hostPort = getHostPort(ctx);
+    String hostPort = getHostPort(ctx.getLdapContext());
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = ctx.getRootConfiguration();
       ReplicationSynchronizationProviderCfgClient sync = null;
       try
       {
@@ -7830,7 +7918,7 @@
         }
       }
     }
-    catch (OpenDsException ode)
+    catch (Exception ode)
     {
       LocalizableMessage msg = getMessageForDisableException(hostPort, baseDN);
         throw new ReplicationCliException(msg,
@@ -7840,19 +7928,17 @@
 
   /**
    * Disables the replication server for a given server.
-   * @param ctx the connection to the server.
+   * @param connWrapper the connection to the server.
    * @throws ReplicationCliException if there is an error updating the
    * configuration of the server.
    */
-  private void disableReplicationServer(InitialLdapContext ctx)
+  private void disableReplicationServer(ConnectionWrapper connWrapper)
   throws ReplicationCliException
   {
-    String hostPort = getHostPort(ctx);
+    String hostPort = getHostPort(connWrapper.getLdapContext());
     try
     {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(
-          JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
+      RootCfgClient root = connWrapper.getRootConfiguration();
       ReplicationSynchronizationProviderCfgClient sync = null;
       ReplicationServerCfgClient replicationServer = null;
       try
@@ -7883,7 +7969,7 @@
         println();
       }
     }
-    catch (OpenDsException ode)
+    catch (Exception ode)
     {
       throw new ReplicationCliException(
           ERR_REPLICATION_DISABLING_REPLICATIONSERVER.get(hostPort),
@@ -9124,13 +9210,13 @@
   }
 
   private void updateAvailableAndReplicatedSuffixesForOneDomain(
-      InitialLdapContext ctxDomain, InitialLdapContext ctxOther,
+      ConnectionWrapper ctxDomain, ConnectionWrapper ctxOther,
       Set<String> availableSuffixes, Set<String> alreadyReplicatedSuffixes)
   {
-    Collection<ReplicaDescriptor> replicas = getReplicas(ctxDomain);
+    Collection<ReplicaDescriptor> replicas = getReplicas(ctxDomain.getLdapContext());
     int replicationPort = getReplicationPort(ctxOther);
     boolean isReplicationServerConfigured = replicationPort != -1;
-    String replicationServer = getReplicationServer(getHostName(ctxOther), replicationPort);
+    String replicationServer = getReplicationServer(getHostName(ctxOther.getLdapContext()), replicationPort);
     for (ReplicaDescriptor replica : replicas)
     {
       if (!isReplicationServerConfigured)
@@ -9162,16 +9248,16 @@
   }
 
   private void updateAvailableAndReplicatedSuffixesForNoDomain(
-      InitialLdapContext ctx1, InitialLdapContext ctx2,
+      ConnectionWrapper ctx1, ConnectionWrapper ctx2,
       Set<String> availableSuffixes, Set<String> alreadyReplicatedSuffixes)
   {
     int replicationPort1 = getReplicationPort(ctx1);
     boolean isReplicationServer1Configured = replicationPort1 != -1;
-    String replicationServer1 = getReplicationServer(getHostName(ctx1), replicationPort1);
+    String replicationServer1 = getReplicationServer(getHostName(ctx1.getLdapContext()), replicationPort1);
 
     int replicationPort2 = getReplicationPort(ctx2);
     boolean isReplicationServer2Configured = replicationPort2 != -1;
-    String replicationServer2 = getReplicationServer(getHostName(ctx2), replicationPort2);
+    String replicationServer2 = getReplicationServer(getHostName(ctx2.getLdapContext()), replicationPort2);
 
     TopologyCache cache1 = isReplicationServer1Configured ? createTopologyCache(ctx1) : null;
     TopologyCache cache2 = isReplicationServer2Configured ? createTopologyCache(ctx2) : null;
@@ -9194,7 +9280,7 @@
     }
   }
 
-  private TopologyCache createTopologyCache(InitialLdapContext ctx)
+  private TopologyCache createTopologyCache(ConnectionWrapper ctx)
   {
     try
     {
@@ -9203,14 +9289,15 @@
       {
         TopologyCache cache = new TopologyCache(adsContext, getTrustManager(sourceServerCI), getConnectTimeout());
         cache.getFilter().setSearchMonitoringInformation(false);
-        cache.setPreferredConnections(getPreferredConnections(ctx));
+        cache.setPreferredConnections(getPreferredConnections(ctx.getLdapContext()));
         cache.reloadTopology();
         return cache;
       }
     }
     catch (Throwable t)
     {
-      logger.warn(LocalizableMessage.raw("Error loading topology cache in " + getLdapUrl(ctx) + ": " + t, t));
+      logger.warn(LocalizableMessage.raw("Error loading topology cache in "
+          + getLdapUrl(ctx.getLdapContext()) + ": " + t, t));
     }
     return null;
   }
@@ -9298,9 +9385,9 @@
     createTopologyCache(adsCtx1, uData, suffixes);
     createTopologyCache(adsCtx2, uData, suffixes);
 
-    int repPort1 = getReplicationPort(adsCtx1.getDirContext());
+    int repPort1 = getReplicationPort(adsCtx1.getConnection());
     String repServer1 =  getReplicationServer(server1.getHostName(), repPort1);
-    int repPort2 = getReplicationPort(adsCtx2.getDirContext());
+    int repPort2 = getReplicationPort(adsCtx2.getConnection());
     String repServer2 =  getReplicationServer(server2.getHostName(), repPort2);
     for (String baseDN : uData.getBaseDNs())
     {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
index 5de245c..5cc625c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/status/StatusCli.java
@@ -48,6 +48,7 @@
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizableMessageBuilder;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.AdminException;
 import org.forgerock.opendj.config.LDAPProfile;
 import org.forgerock.opendj.config.client.ManagementContext;
 import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
@@ -61,6 +62,7 @@
 import org.forgerock.util.Options;
 import org.forgerock.util.time.Duration;
 import org.opends.admin.ads.util.ApplicationTrustManager;
+import org.opends.admin.ads.util.ConnectionWrapper;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNTableModel;
@@ -76,7 +78,6 @@
 import org.forgerock.opendj.ldap.DN;
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.NullOutputStream;
-import org.opends.server.types.OpenDsException;
 import org.opends.server.util.BuildVersion;
 import org.opends.server.util.StaticUtils;
 import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
@@ -330,7 +331,8 @@
         InitialLdapContext ctx = null;
         try {
           ctx = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd);
-          controlInfo.setDirContext(ctx);
+          controlInfo.setConnection(
+              new ConnectionWrapper(ctx, controlInfo.getConnectTimeout(), controlInfo.getTrustManager()));
           controlInfo.regenerateDescriptor();
           writeStatus(controlInfo);
 
@@ -782,9 +784,10 @@
    */
   private void writeErrorContents(ServerDescriptor desc)
   {
-    for (OpenDsException ex : desc.getExceptions())
+    for (Exception ex : desc.getExceptions())
     {
-      LocalizableMessage errorMsg = ex.getMessageObject();
+      LocalizableMessage errorMsg = ex instanceof AdminException ?
+          ((AdminException) ex).getMessageObject() : LocalizableMessage.raw(ex.getMessage());
       if (errorMsg != null)
       {
         println();

--
Gitblit v1.10.0