From 6c2dae79767257aa61c05c36189489861ca6f0f0 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Thu, 06 Mar 2014 14:37:45 +0000
Subject: [PATCH] Checkpoint OPENDJ-1343 Migrate dsconfig - Removed the PasswordReader class as now we only support >JDK6   - Replaced calls to PasswordReader.readPassword to ConsoleApplication.readPassword() - Minor code cleanup / removed unused on the SecureConnectionCli class.

---
 opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java |   94 ++++++++++++++++------------------------------
 1 files changed, 33 insertions(+), 61 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index e47acfa..822f17d 100644
--- a/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -27,10 +27,11 @@
 
 package org.opends.server.admin.client.cli;
 
-import static org.opends.server.util.ServerConstants.EOL;
-import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
+import static com.forgerock.opendj.cli.CliMessages.*;
+import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
+import static com.forgerock.opendj.cli.Utils.MAX_LINE_WIDTH;
 import static org.opends.server.util.StaticUtils.wrapText;
-import static org.opends.messages.ToolMessages.*;
+import static com.forgerock.opendj.cli.ReturnCode.CONFLICTING_ARGS;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -38,19 +39,18 @@
 import java.util.Collection;
 import java.util.LinkedHashSet;
 
-import javax.net.ssl.KeyManager;
-
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizableMessageBuilder;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.opends.admin.ads.util.ApplicationTrustManager;
-import org.opends.server.util.PasswordReader;
 
 import com.forgerock.opendj.cli.Argument;
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentGroup;
 import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.ClientException;
 import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
 import com.forgerock.opendj.cli.FileBasedArgument;
 import com.forgerock.opendj.cli.StringArgument;
 import com.forgerock.opendj.cli.SubCommandArgumentParser;
@@ -146,59 +146,32 @@
    * @param err
    *          The error stream to used if we have to prompt to the
    *          user.
-   * @param clearArg
+   * @param pwdArg
    *          The password StringArgument argument.
    * @param fileArg
    *          The password FileBased argument.
    * @return The password stored into the specified file on by the
    *         command line argument, or prompts it if not specified.
    */
-  protected String getBindPassword(String dn,
-      OutputStream out, OutputStream err, StringArgument clearArg,
-      FileBasedArgument fileArg)
+  protected String getBindPassword(String dn, OutputStream out,
+      OutputStream err, StringArgument pwdArg, FileBasedArgument fileArg)
   {
-    if (clearArg.isPresent())
-    {
-      String bindPasswordValue = clearArg.getValue();
-      if(bindPasswordValue != null && "-".equals(bindPasswordValue))
-      {
-        // read the password from the stdin.
-        try
-        {
-          out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
-          out.flush();
-          char[] pwChars = PasswordReader.readPassword();
-          bindPasswordValue = new String(pwChars);
-        } catch(Exception ex)
-        {
-          logger.traceException(ex);
-          try
-          {
-            err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
-            err.write(EOL.getBytes());
-          }
-          catch (IOException e)
-          {
-          }
-          return null;
-        }
-      }
-      return bindPasswordValue;
-    }
-    else
+    String bindPasswordValue = null;
     if (fileArg.isPresent())
     {
       return fileArg.getValue();
     }
-    else
+    else if (pwdArg.isPresent())
     {
-      // read the password from the stdin.
+      bindPasswordValue = pwdArg.getValue();
+    }
+    if ((bindPasswordValue != null && "-".equals(bindPasswordValue))
+        || bindPasswordValue == null)
+    {
+      // Read the password from the STDin.
       try
       {
-        out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
-        out.flush();
-        char[] pwChars = PasswordReader.readPassword();
-        return new String(pwChars);
+        return readPassword(dn, out);
       }
       catch (Exception ex)
       {
@@ -206,19 +179,28 @@
         try
         {
           err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
-          err.write(EOL.getBytes());
+          err.write(LINE_SEPARATOR.getBytes());
         }
         catch (IOException e)
         {
+          // Nothing to do.
         }
-        return null;
       }
     }
+    return bindPasswordValue;
+  }
 
+  private String readPassword(String dn, OutputStream out) throws IOException,
+      ClientException
+  {
+    out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
+    out.flush();
+    char[] pwChars = ConsoleApplication.readPassword();
+    return new String(pwChars);
   }
 
   /**
-   * Get the password which has to be used for the command.
+   * Gets the password which has to be used for the command.
    *
    * @param dn
    *          The user DN for which to password could be asked.
@@ -238,7 +220,7 @@
   }
 
   /**
-   * Get the password which has to be used for the command without prompting
+   * Gets the password which has to be used for the command without prompting
    * the user.  If no password was specified, return null.
    *
    * @return The password stored into the specified file on by the
@@ -366,10 +348,10 @@
               .getLongIdentifier());
       if (buf.length() > 0)
       {
-        buf.append(EOL);
+        buf.append(LINE_SEPARATOR);
       }
       buf.append(message);
-      ret = 1;
+      return CONFLICTING_ARGS.get();
     }
 
     return ret;
@@ -433,16 +415,6 @@
   }
 
   /**
-   * Handle KeyStore.
-   *
-   * @return The keyStore manager to be used for the command.
-   */
-  public KeyManager getKeyManager()
-  {
-    return secureArgsList.getKeyManager() ;
-  }
-
-  /**
    * Returns the timeout to be used to connect in milliseconds.  The method
    * must be called after parsing the arguments.
    * @return the timeout to be used to connect in milliseconds.  Returns

--
Gitblit v1.10.0