From 9d26dfb9884fbac1c94d776e25f381bb08a57ac2 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 14 Nov 2007 14:09:26 +0000
Subject: [PATCH] Fix some issues in the interactive mode of dsreplication enable and dsreplication disable when the user provides values in the command-line.

---
 opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java |   88 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index f2d9914..37fef16 100644
--- a/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -73,7 +73,9 @@
   private String hostName;
   private int portNumber;
   private String bindDN;
+  private String providedBindDN;
   private String adminUID;
+  private String providedAdminUID;
   private String bindPassword;
   private KeyManager keyManager;
   private ApplicationTrustManager trustManager;
@@ -530,9 +532,25 @@
     bindDN = secureArgsList.bindDnArg.getValue();
     adminUID = secureArgsList.adminUidArg.getValue();
     final boolean useAdmin = secureArgsList.useAdminUID();
-    boolean argIsPresent = useAdmin ?
-        secureArgsList.adminUidArg.isPresent() :
-          secureArgsList.bindDnArg.isPresent();
+    if (useAdmin && secureArgsList.adminUidArg.isPresent())
+    {
+      providedAdminUID = adminUID;
+    }
+    else
+    {
+      providedAdminUID = null;
+    }
+    if ((!useAdmin || useAdminOrBindDn) &&
+        secureArgsList.bindDnArg.isPresent())
+    {
+      providedBindDN = bindDN;
+    }
+    else
+    {
+      providedBindDN = null;
+    }
+    boolean argIsPresent = (providedAdminUID != null) ||
+    (providedBindDN != null);
     final String tmpBindDN = bindDN;
     final String tmpAdminUID = adminUID;
     if (keyManager == null)
@@ -579,12 +597,16 @@
             if (Utils.isDn(v))
             {
               bindDN = v;
+              providedBindDN = v;
               adminUID = null;
+              providedAdminUID = null;
             }
             else
             {
               bindDN = null;
+              providedBindDN = null;
               adminUID = v;
+              providedAdminUID = v;
             }
           }
           else if (useAdmin)
@@ -592,11 +614,13 @@
             adminUID = app.readValidatedInput(
                 INFO_LDAP_CONN_PROMPT_ADMINISTRATOR_UID.get(adminUID),
                 callback);
+            providedAdminUID = adminUID;
           }
           else
           {
             bindDN = app.readValidatedInput(INFO_LDAP_CONN_PROMPT_BIND_DN
               .get(bindDN), callback);
+            providedBindDN = bindDN;
           }
         }
         catch (CLIException e)
@@ -647,24 +671,21 @@
         {
           app.println();
           Message prompt;
-          if (useAdminOrBindDn)
+          if (providedAdminUID != null)
           {
-            if (adminUID != null)
-            {
-              prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(adminUID);
-            }
-            else
-            {
-              prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDN);
-            }
+            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(providedAdminUID);
           }
-          else if (useAdmin)
+          else if (providedBindDN != null)
           {
-            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(adminUID);
+            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(providedBindDN);
+          }
+          else if (bindDN != null)
+          {
+            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDN);
           }
           else
           {
-            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDN);
+            prompt = INFO_LDAPAUTH_PASSWORD_PROMPT.get(adminUID);
           }
           bindPassword = app.readPassword(prompt);
         }
@@ -1143,13 +1164,25 @@
     String dn;
     if (useAdminOrBindDn)
     {
-      if (this.adminUID != null)
+      if (providedBindDN != null)
+      {
+        dn = providedBindDN;
+      }
+      else if (providedAdminUID != null)
+      {
+        dn = ADSContext.getAdministratorDN(providedAdminUID);
+      }
+      else if (this.bindDN != null)
+      {
+        dn = this.bindDN;
+      }
+      else if (this.adminUID != null)
       {
         dn = ADSContext.getAdministratorDN(this.adminUID);
       }
       else
       {
-        dn = this.bindDN;
+        dn = null;
       }
     }
     else if (secureArgsList.useAdminUID())
@@ -1711,4 +1744,25 @@
 
    trustManagerInitialized = true;
  }
+ /**
+  * Returns the explicitly provided Admin UID from the user (interactively
+  * or through the argument).
+  * @return the explicitly provided Admin UID from the user (interactively
+  * or through the argument).
+  */
+ public String getProvidedAdminUID()
+ {
+   return providedAdminUID;
+ }
+
+ /**
+  * Returns the explicitly provided bind DN from the user (interactively
+  * or through the argument).
+  * @return the explicitly provided bind DN from the user (interactively
+  * or through the argument).
+  */
+ public String getProvidedBindDN()
+ {
+   return providedBindDN;
+ }
 }

--
Gitblit v1.10.0