From 10f162fe7aef97d8a9655b502bfccbe2cfbd7572 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 21 Mar 2014 13:53:49 +0000
Subject: [PATCH] Removed duplicated code.

---
 opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java |   55 ++++++++++++++++---------------------------------------
 1 files changed, 16 insertions(+), 39 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java b/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
index 4bbbaef..97f93ef 100644
--- a/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
@@ -26,8 +26,6 @@
  *      Portions Copyright 2012-2014 ForgeRock AS.
  */
 package org.opends.server.tools;
-import org.opends.admin.ads.util.ConnectionUtils;
-import org.forgerock.i18n.LocalizableMessage;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -38,10 +36,14 @@
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.opends.server.controls.*;
+import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.opends.server.plugins.ChangeNumberControlPlugin;
+import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.opends.admin.ads.util.ConnectionUtils;
+import org.opends.server.controls.*;
+import org.opends.server.plugins.ChangeNumberControlPlugin;
 import org.opends.server.protocols.ldap.AddRequestProtocolOp;
 import org.opends.server.protocols.ldap.AddResponseProtocolOp;
 import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
@@ -58,8 +60,6 @@
 import org.opends.server.protocols.ldap.ModifyDNResponseProtocolOp;
 import org.opends.server.protocols.ldap.ProtocolOp;
 import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.forgerock.opendj.ldap.ByteString;
 import org.opends.server.util.AddChangeRecordEntry;
 import org.opends.server.util.ChangeRecordEntry;
 import org.opends.server.util.EmbeddedUtils;
@@ -72,7 +72,6 @@
 import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
 import com.forgerock.opendj.cli.CommonArguments;
-import com.forgerock.opendj.cli.ConsoleApplication;
 import com.forgerock.opendj.cli.FileBasedArgument;
 import com.forgerock.opendj.cli.IntegerArgument;
 import com.forgerock.opendj.cli.StringArgument;
@@ -82,8 +81,7 @@
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
-
-
+import static org.opends.server.util.args.LDAPConnectionArgumentParser.*;
 
 /**
  * This class provides a tool that can be used to issue modify requests to the
@@ -944,38 +942,17 @@
 
     String bindDNValue = bindDN.getValue();
     String fileNameValue = filename.getValue();
-    String bindPasswordValue = bindPassword.getValue();
-    if(bindPasswordValue != null && bindPasswordValue.equals("-")  ||
-        (!bindPasswordFile.isPresent()  &&
-        (bindDNValue != null && bindPasswordValue == null)))
+    String bindPasswordValue;
+    try
     {
-      // read the password from the stdin.
-      try
-      {
-        out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
-        char[] pwChars = ConsoleApplication.readPassword();
-        bindPasswordValue = new String(pwChars);
-        //As per rfc 4513(section-5.1.2) a client should avoid sending
-        //an empty password to the server.
-        while(pwChars.length==0)
-        {
-          err.println(wrapText(
-                  INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
-                  MAX_LINE_WIDTH));
-          out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
-          pwChars = ConsoleApplication.readPassword();
-        }
-        bindPasswordValue = new String(pwChars);
-      } catch(Exception ex)
-      {
-        logger.traceException(ex);
-        err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
-        return CLIENT_SIDE_PARAM_ERROR;
-      }
-    } else if(bindPasswordValue == null)
+      bindPasswordValue = getPasswordValue(
+          bindPassword, bindPasswordFile, bindDNValue, out, err);
+    }
+    catch (Exception ex)
     {
-      // Read from file if it exists.
-      bindPasswordValue = bindPasswordFile.getValue();
+      logger.traceException(ex);
+      err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
+      return CLIENT_SIDE_PARAM_ERROR;
     }
 
     String keyStorePathValue = keyStorePath.getValue();

--
Gitblit v1.10.0