From d48666a047490384cdbebdcbc7d02acfb60b4c62 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Thu, 03 Apr 2014 15:21:56 +0000
Subject: [PATCH] Checkpoint for OPENDJ-1303 "opendj-cli" - Moved AuthenticatedConnectionFactory from tools to cli.   -- Undo modifications on tools about abstract authenticated connection factory. (and deleted the file)   -- Deleted the file from the tools. - Added functions to opendj-cli Utils. - Trivial code cleanup.

---
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java           |    9 -
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentGroup.java                      |    4 
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java          |   46 ++++-
 opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java           |   32 +---
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentException.java                  |    4 
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java  |    2 
 opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java                   |   36 +---
 opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java                              |   29 ++++
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java         |   10 -
 /dev/null                                                                                 |   53 -------
 opendj-cli/src/main/java/com/forgerock/opendj/cli/MenuBuilder.java                        |   12 -
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java        |   10 -
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java         |   10 -
 opendj-cli/src/main/java/com/forgerock/opendj/cli/AuthenticatedConnectionFactory.java     |   31 +++-
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java |   10 -
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java         |   10 -
 opendj-cli/src/main/java/com/forgerock/opendj/cli/BooleanArgument.java                    |    8 
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java              |    2 
 opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java            |   10 -
 opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java              |   47 ++++++
 20 files changed, 163 insertions(+), 212 deletions(-)

diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/AbstractAuthenticatedConnectionFactory.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/AbstractAuthenticatedConnectionFactory.java
deleted file mode 100644
index 356dff7..0000000
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/AbstractAuthenticatedConnectionFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2014 ForgeRock AS.
- */
-package com.forgerock.opendj.cli;
-
-import org.forgerock.opendj.ldap.ConnectionFactory;
-import org.forgerock.opendj.ldap.requests.BindRequest;
-
-/**
- * Abstract authenticated connection factory implementation.
- */
-abstract class AbstractAuthenticatedConnectionFactory {
-
-    AbstractAuthenticatedConnectionFactory() {
-        // No implementation required.
-    }
-
-    /**
-     * Returns the new authenticated connection factory.
-     *
-     * @param connection
-     *            The connection factory.
-     * @param request
-     *            The bind request.
-     * @return A new authenticated connection factory.
-     * @throws ArgumentException
-     *             If an error occurs when parsing the arguments.
-     */
-    abstract ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-            final BindRequest request) throws ArgumentException;
-}
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentException.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentException.java
index 61ba1f8..fa14f50 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentException.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentException.java
@@ -63,9 +63,7 @@
         this.message = message;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public LocalizableMessage getMessageObject() {
         return this.message;
     }
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentGroup.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentGroup.java
index c0eaa36..6a7df74 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentGroup.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentGroup.java
@@ -63,9 +63,7 @@
         this.args = new LinkedList<Argument>();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int compareTo(final ArgumentGroup o) {
         // Groups with higher priority numbers appear before
         // those with lower priority in the usage output
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthenticatedConnectionFactory.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/AuthenticatedConnectionFactory.java
similarity index 91%
rename from opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthenticatedConnectionFactory.java
rename to opendj-cli/src/main/java/com/forgerock/opendj/cli/AuthenticatedConnectionFactory.java
index 9fcce6e..82c61d5 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthenticatedConnectionFactory.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/AuthenticatedConnectionFactory.java
@@ -24,8 +24,7 @@
  *      Copyright 2009-2010 Sun Microsystems, Inc.
  *      Portions copyright 2011-2014 ForgeRock AS.
  */
-
-package com.forgerock.opendj.ldap.tools;
+package com.forgerock.opendj.cli;
 
 import org.forgerock.opendj.ldap.Connection;
 import org.forgerock.opendj.ldap.AbstractConnectionWrapper;
@@ -61,13 +60,13 @@
  * the connection attempt will fail and an {@code ErrorResultException} will be
  * thrown.
  */
-final class AuthenticatedConnectionFactory implements ConnectionFactory {
+public final class AuthenticatedConnectionFactory implements ConnectionFactory {
 
     /**
      * An authenticated connection supports all operations except Bind
      * operations.
      */
-    static final class AuthenticatedConnection extends AbstractConnectionWrapper<Connection> {
+    public static final class AuthenticatedConnection extends AbstractConnectionWrapper<Connection> {
 
         private final BindRequest request;
         private volatile BindResult result;
@@ -83,15 +82,17 @@
          * Bind operations are not supported by pre-authenticated connections.
          * These methods will always throw {@code UnsupportedOperationException}.
          */
-
+        /** {@inheritDoc} */
         public BindResult bind(BindRequest request) throws ErrorResultException {
             throw new UnsupportedOperationException();
         }
 
+        /** {@inheritDoc} */
         public BindResult bind(String name, char[] password) throws ErrorResultException {
             throw new UnsupportedOperationException();
         }
 
+        /** {@inheritDoc} */
         public FutureResult<BindResult> bindAsync(BindRequest request,
                 IntermediateResponseHandler intermediateResponseHandler,
                 ResultHandler<? super BindResult> resultHandler) {
@@ -105,7 +106,7 @@
          * @return The Bind result which was returned from the server after
          *         authentication.
          */
-        BindResult getAuthenticatedBindResult() {
+        public BindResult getAuthenticatedBindResult() {
             return result;
         }
 
@@ -125,7 +126,7 @@
          *             If this connection has already been closed, i.e. if
          *             {@code isClosed() == true}.
          */
-        FutureResult<BindResult> rebindAsync(final ResultHandler<? super BindResult> handler) {
+        public FutureResult<BindResult> rebindAsync(final ResultHandler<? super BindResult> handler) {
             if (request == null) {
                 throw new UnsupportedOperationException();
             }
@@ -138,6 +139,7 @@
 
             final ResultHandler<BindResult> handlerWrapper = new ResultHandler<BindResult>() {
 
+                /** {@inheritDoc} */
                 public void handleErrorResult(final ErrorResultException error) {
                     /*
                      * This connection is now unauthenticated so prevent further
@@ -150,6 +152,7 @@
                     }
                 }
 
+                /** {@inheritDoc} */
                 public void handleResult(final BindResult result) {
                     // Save the result.
                     AuthenticatedConnection.this.result = result;
@@ -164,6 +167,11 @@
             return connection.bindAsync(request, null, handlerWrapper);
         }
 
+        /**
+         * Returns the string representation of this authenticated connection.
+         *
+         * @return The string representation of this authenticated connection factory.
+         */
         public String toString() {
             StringBuilder builder = new StringBuilder();
             builder.append("AuthenticatedConnection(");
@@ -238,7 +246,7 @@
      * @throws NullPointerException
      *             If {@code factory} or {@code request} was {@code null}.
      */
-    AuthenticatedConnectionFactory(final ConnectionFactory factory, final BindRequest request) {
+    public AuthenticatedConnectionFactory(final ConnectionFactory factory, final BindRequest request) {
         Reject.ifNull(factory, request);
         this.parentFactory = factory;
 
@@ -251,6 +259,7 @@
         parentFactory.close();
     }
 
+    /** {@inheritDoc} */
     public Connection getConnection() throws ErrorResultException {
         final Connection connection = parentFactory.getConnection();
         BindResult bindResult = null;
@@ -269,6 +278,7 @@
         return new AuthenticatedConnection(connection, request, bindResult);
     }
 
+    /** {@inheritDoc} */
     public FutureResult<Connection> getConnectionAsync(
             final ResultHandler<? super Connection> handler) {
         final FutureResultImpl future = new FutureResultImpl(request, handler);
@@ -310,6 +320,11 @@
         return this;
     }
 
+    /**
+     * Returns the string representation of this authenticated connection factory.
+     *
+     * @return The string representation of this authenticated connection factory.
+     */
     public String toString() {
         final StringBuilder builder = new StringBuilder();
         builder.append("AuthenticatedConnectionFactory(");
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/BooleanArgument.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/BooleanArgument.java
index c40d7bc..d854328 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/BooleanArgument.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/BooleanArgument.java
@@ -64,9 +64,7 @@
                 .valueOf(false), null, description);
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     final public void addValue(final String valueString) {
         if (valueString != null) {
@@ -76,9 +74,7 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     final public void setPresent(final boolean isPresent) {
         addValue(String.valueOf(isPresent));
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
index be4754b..0709410 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
@@ -47,7 +47,6 @@
 import javax.net.ssl.X509TrustManager;
 
 import org.forgerock.i18n.LocalizableMessage;
-
 import org.forgerock.opendj.ldap.ConnectionFactory;
 import org.forgerock.opendj.ldap.KeyManagers;
 import org.forgerock.opendj.ldap.LDAPConnectionFactory;
@@ -67,7 +66,7 @@
 /**
  * A connection factory designed for use with command line tools.
  */
-public class ConnectionFactoryProvider extends AbstractAuthenticatedConnectionFactory {
+public class ConnectionFactoryProvider {
     /**
      * The Logger.
      */
@@ -312,11 +311,41 @@
     }
 
     /**
-     * Returns the connection factory.
+     * Returns the host name.
+     *
+     * @return The host name value.
+     */
+    public String getHostname() {
+        if (hostNameArg.isPresent()) {
+            return hostNameArg.getValue();
+        }
+        return hostNameArg.getDefaultValue();
+    }
+
+    /**
+     * Get the port which has to be used for the command.
+     *
+     * @return The port specified by the command line argument, or the default value, if not specified.
+     */
+    public int getPort() {
+        if (portArg.isPresent()) {
+            try {
+                return portArg.getIntValue();
+            } catch (ArgumentException e) {
+                return Integer.valueOf(portArg.getDefaultValue());
+            }
+        }
+        return Integer.valueOf(portArg.getDefaultValue());
+    }
+
+    /**
+     * Checks if any conflicting arguments are present, build the connection with
+     * selected arguments and returns the connection factory.
      *
      * @return The connection factory.
      * @throws ArgumentException
-     *             If an error occurs during the parsing of the arguments.
+     *             If an error occurs during the parsing of the arguments. (conflicting
+     *             arguments or if an error occurs during building SSL context).
      */
     public ConnectionFactory getConnectionFactory() throws ArgumentException {
         if (connFactory == null) {
@@ -437,7 +466,7 @@
             authenticatedConnFactory = getConnectionFactory();
             final BindRequest bindRequest = getBindRequest();
             if (bindRequest != null) {
-                authenticatedConnFactory = newAuthenticatedConnectionFactory(authenticatedConnFactory, bindRequest);
+                authenticatedConnFactory = new AuthenticatedConnectionFactory(authenticatedConnFactory, bindRequest);
             }
         }
         return authenticatedConnFactory;
@@ -771,11 +800,4 @@
 
         return option.substring(equalPos + 1, option.length());
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-            final BindRequest request) throws ArgumentException {
-        return null;
-    }
 }
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/MenuBuilder.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/MenuBuilder.java
index 5da49e6..3fd925b 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/MenuBuilder.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/MenuBuilder.java
@@ -68,9 +68,7 @@
             this.callbacks = callbacks;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public MenuResult<T> invoke(ConsoleApplication app) throws ClientException {
             List<T> values = new ArrayList<T>();
             for (MenuCallback<T> callback : callbacks) {
@@ -149,9 +147,7 @@
             this.nMaxTries = nMaxTries;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public MenuResult<T> run() throws ClientException {
             // The validation call-back which will be used to determine the
             // action call-back.
@@ -296,9 +292,7 @@
             this.result = result;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         public MenuResult<T> invoke(ConsoleApplication app) throws ClientException {
             return result;
         }
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java
index 9ab53f4..73694a1 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java
@@ -54,7 +54,7 @@
  * A trust manager which prompts the user for the length of time that they would
  * like to trust a server certificate.
  */
-final class PromptingTrustManager implements X509TrustManager {
+public final class PromptingTrustManager implements X509TrustManager {
     /**
      * Enumeration description server certificate trust option.
      */
@@ -119,7 +119,27 @@
 
     private final ConsoleApplication app;
 
-    PromptingTrustManager(final ConsoleApplication app, final String acceptedStorePath,
+    /**
+     * Creates a prompting trust manager based on these arguments.
+     *
+     * @param app
+     *            The linked console application.
+     * @param acceptedStorePath
+     *            The store path.
+     * @param sourceTrustManager
+     *            The source of the trust manager.
+     * @throws KeyStoreException
+     *             If no Provider supports a KeyStoreSpi implementation for the specified type.
+     * @throws IOException
+     *             If there is an I/O or format problem with the keystore data, if a password is required but not given,
+     *             or if the given password was incorrect. If the error is due to a wrong password, the cause of the
+     *             IOException should be an UnrecoverableKeyException.
+     * @throws NoSuchAlgorithmException
+     *             If no provider supports a trust manager factory spi implementation for the specified algorithm.
+     * @throws CertificateException
+     *             If any of the certificates in the key store could not be loaded
+     */
+    public PromptingTrustManager(final ConsoleApplication app, final String acceptedStorePath,
             final X509TrustManager sourceTrustManager) throws KeyStoreException, IOException,
             NoSuchAlgorithmException, CertificateException {
         Reject.ifNull(app, acceptedStorePath);
@@ -170,11 +190,30 @@
         this.onDiskTrustManager = x509tm;
     }
 
-    PromptingTrustManager(final ConsoleApplication app, final X509TrustManager sourceTrustManager)
+    /**
+     * Creates a prompting trust manager based on these arguments.
+     *
+     * @param app
+     *            The linked console application.
+     * @param sourceTrustManager
+     *            The source of the trust manager.
+     * @throws KeyStoreException
+     *             If no Provider supports a KeyStoreSpi implementation for the specified type.
+     * @throws IOException
+     *             If there is an I/O or format problem with the keystore data, if a password is required but not given,
+     *             or if the given password was incorrect. If the error is due to a wrong password, the cause of the
+     *             IOException should be an UnrecoverableKeyException.
+     * @throws NoSuchAlgorithmException
+     *             If no provider supports a trust manager factory spi implementation for the specified algorithm.
+     * @throws CertificateException
+     *             If any of the certificates in the key store could not be loaded
+     */
+    public PromptingTrustManager(final ConsoleApplication app, final X509TrustManager sourceTrustManager)
             throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
         this(app, DEFAULT_PATH, sourceTrustManager);
     }
 
+    /** {@inheritDoc} */
     public void checkClientTrusted(final X509Certificate[] x509Certificates, final String s)
             throws CertificateException {
         try {
@@ -196,6 +235,7 @@
         }
     }
 
+    /** {@inheritDoc} */
     public void checkServerTrusted(final X509Certificate[] x509Certificates, final String s)
             throws CertificateException {
         try {
@@ -217,6 +257,7 @@
         }
     }
 
+    /** {@inheritDoc} */
     public X509Certificate[] getAcceptedIssuers() {
         if (nestedTrustManager != null) {
             return nestedTrustManager.getAcceptedIssuers();
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java
index 3e6dfe1..9cc9119 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java
@@ -59,9 +59,7 @@
             // No implementation required.
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void addCell(String s) {
             // Avoid printing tab separators for trailing empty cells.
@@ -79,9 +77,7 @@
             column++;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void addHeading(String s) {
             if (displayHeadings) {
@@ -89,9 +85,7 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endHeader() {
             if (displayHeadings) {
@@ -99,34 +93,26 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endRow() {
             writer.println();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endTable() {
             writer.flush();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void startHeader() {
             column = 0;
             requiredSeparators = 0;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void startRow() {
             column = 0;
@@ -171,9 +157,7 @@
         this.displayHeadings = displayHeadings;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     protected TableSerializer getSerializer() {
         return new Serializer();
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java
index ca8906c..22f925d 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java
@@ -74,27 +74,21 @@
             this.indentPadding = builder.toString();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void addCell(String s) {
             currentRow.add(s);
             column++;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void addColumn(int width) {
             columnWidths.add(width);
             totalColumns++;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void addHeading(String s) {
             if (displayHeadings) {
@@ -102,9 +96,7 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endHeader() {
             if (displayHeadings) {
@@ -145,9 +137,7 @@
             }
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endRow() {
             boolean isRemainingText;
@@ -222,17 +212,13 @@
             } while (isRemainingText);
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void endTable() {
             writer.flush();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void startHeader() {
             determineColumnWidths();
@@ -241,9 +227,7 @@
             currentRow.clear();
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        /** {@inheritDoc} */
         @Override
         public void startRow() {
             column = 0;
@@ -487,9 +471,7 @@
         this.totalWidth = totalWidth;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     protected TableSerializer getSerializer() {
         return new Serializer();
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
index e2e3d4c..d93be76 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -51,6 +51,8 @@
 import javax.net.ssl.SSLHandshakeException;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.RDN;
 
 /**
  * This class provides utility functions for all the client side tools.
@@ -510,4 +512,31 @@
     private Utils() {
         // Do nothing.
     }
+
+    /**
+     * Returns {@code true} if the the provided string is a DN and {@code false} otherwise.
+     *
+     * @param dn
+     *            the String we are analyzing.
+     * @return {@code true} if the the provided string is a DN and {@code false} otherwise.
+     */
+    public static boolean isDN(String dn) {
+        try {
+            DN.valueOf(dn);
+        } catch (Exception ex) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Returns the DN of the global administrator for a given UID.
+     *
+     * @param uid
+     *            The UID to be used to generate the DN.
+     * @return The DN of the administrator for the given UID.
+     */
+    private static String getAdministratorDN(String uid) {
+        return "cn=" + RDN.valueOf(uid) + ",cn=Administrators, cn=admin data";
+    }
 }
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
index 34f61bb..efe4c9b 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/AuthRate.java
@@ -394,14 +394,7 @@
         try {
             setDefaultPerfToolProperties();
 
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
             runner = new BindPerformanceRunner(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
index 55f99f8..0b24fa3 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPCompare.java
@@ -50,7 +50,6 @@
 import org.forgerock.opendj.ldap.controls.AssertionRequestControl;
 import org.forgerock.opendj.ldap.controls.Control;
 import org.forgerock.opendj.ldap.controls.ProxiedAuthV2RequestControl;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.CompareRequest;
 import org.forgerock.opendj.ldap.requests.Requests;
 import org.forgerock.opendj.ldap.responses.Result;
@@ -147,14 +146,7 @@
         BooleanArgument noPropertiesFileArgument;
 
         try {
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
             argParser.addArgument(propertiesFileArgument);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
index 18e38d8..0b4d9d7 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPModify.java
@@ -56,7 +56,6 @@
 import org.forgerock.opendj.ldap.controls.PreReadResponseControl;
 import org.forgerock.opendj.ldap.controls.ProxiedAuthV2RequestControl;
 import org.forgerock.opendj.ldap.requests.AddRequest;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.DeleteRequest;
 import org.forgerock.opendj.ldap.requests.ModifyDNRequest;
 import org.forgerock.opendj.ldap.requests.ModifyRequest;
@@ -267,14 +266,7 @@
         BooleanArgument noPropertiesFileArgument;
 
         try {
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
             argParser.addArgument(propertiesFileArgument);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
index 520c418..cec3939 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPPasswordModify.java
@@ -37,7 +37,6 @@
 import org.forgerock.opendj.ldap.ErrorResultException;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.controls.Control;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.PasswordModifyExtendedRequest;
 import org.forgerock.opendj.ldap.requests.Requests;
 import org.forgerock.opendj.ldap.responses.PasswordModifyExtendedResult;
@@ -113,14 +112,7 @@
         BooleanArgument noPropertiesFileArgument;
 
         try {
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
             argParser.addArgument(propertiesFileArgument);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
index f899991..3b6ee7b 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDAPSearch.java
@@ -68,7 +68,6 @@
 import org.forgerock.opendj.ldap.controls.SimplePagedResultsControl;
 import org.forgerock.opendj.ldap.controls.VirtualListViewRequestControl;
 import org.forgerock.opendj.ldap.controls.VirtualListViewResponseControl;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.Requests;
 import org.forgerock.opendj.ldap.requests.SearchRequest;
 import org.forgerock.opendj.ldap.responses.Result;
@@ -263,14 +262,7 @@
         StringArgument assertionFilter;
         IntegerArgument sizeLimit;
         try {
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
             final StringArgument propertiesFileArgument =
                 CommonArguments.getPropertiesFile();
             argParser.addArgument(propertiesFileArgument);
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
index 4e1989e..1e809dc 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ModRate.java
@@ -36,7 +36,6 @@
 import org.forgerock.opendj.ldap.FutureResult;
 import org.forgerock.opendj.ldap.ModificationType;
 import org.forgerock.opendj.ldap.ResultCode;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.ModifyRequest;
 import org.forgerock.opendj.ldap.requests.Requests;
 import org.forgerock.opendj.ldap.responses.Result;
@@ -174,14 +173,7 @@
         try {
             Utils.setDefaultPerfToolProperties();
 
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
             runner = new ModifyPerformanceRunner(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
index 4e5b27a..3fd70e3 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
@@ -58,7 +58,7 @@
 import com.forgerock.opendj.cli.IntegerArgument;
 import com.forgerock.opendj.cli.MultiColumnPrinter;
 import com.forgerock.opendj.cli.StringArgument;
-import com.forgerock.opendj.ldap.tools.AuthenticatedConnectionFactory.AuthenticatedConnection;
+import com.forgerock.opendj.cli.AuthenticatedConnectionFactory.AuthenticatedConnection;
 import com.forgerock.opendj.util.StaticUtils;
 
 /**
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
index e88f3e7..287b290 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/SearchRate.java
@@ -43,7 +43,6 @@
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchResultHandler;
 import org.forgerock.opendj.ldap.SearchScope;
-import org.forgerock.opendj.ldap.requests.BindRequest;
 import org.forgerock.opendj.ldap.requests.Requests;
 import org.forgerock.opendj.ldap.requests.SearchRequest;
 import org.forgerock.opendj.ldap.responses.Result;
@@ -217,14 +216,7 @@
         try {
             Utils.setDefaultPerfToolProperties();
 
-            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this) {
-                @Override
-                public ConnectionFactory newAuthenticatedConnectionFactory(final ConnectionFactory connection,
-                        final BindRequest request) throws ArgumentException {
-                    return new AuthenticatedConnectionFactory(connection, request);
-
-                }
-            };
+            connectionFactoryProvider = new ConnectionFactoryProvider(argParser, this);
             runner = new SearchPerformanceRunner(argParser, this);
 
             propertiesFileArgument = CommonArguments.getPropertiesFile();
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
index b314845..bf1467d 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/Utils.java
@@ -51,7 +51,7 @@
 
 import com.forgerock.opendj.cli.ConsoleApplication;
 import com.forgerock.opendj.ldap.controls.AccountUsabilityRequestControl;
-import com.forgerock.opendj.ldap.tools.AuthenticatedConnectionFactory.AuthenticatedConnection;
+import com.forgerock.opendj.cli.AuthenticatedConnectionFactory.AuthenticatedConnection;
 import com.forgerock.opendj.util.StaticUtils;
 
 /**

--
Gitblit v1.10.0