From 7f207072519d5a4551dc943791cf23fef968cae7 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 09 Jan 2009 17:47:45 +0000
Subject: [PATCH] Fix for issue 3698 (Cannot change Directory Manager password with the Control Panel)

---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/ModifyEntryTask.java |   72 +++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/ModifyEntryTask.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
index 0b135b2..e3d60ec 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
@@ -55,6 +55,7 @@
 import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
 import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
 import org.opends.guitools.controlpanel.ui.ProgressDialog;
+import org.opends.guitools.controlpanel.ui.StatusGenericPanel;
 import org.opends.guitools.controlpanel.ui.ViewEntryPanel;
 import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
 import org.opends.guitools.controlpanel.util.Utilities;
@@ -84,6 +85,7 @@
   private CustomSearchResult oldEntry;
   private DN oldDn;
   private ArrayList<ModificationItem> modifications;
+  private ModificationItem passwordModification;
   private Entry newEntry;
   private BrowserController controller;
   private TreePath treePath;
@@ -132,8 +134,22 @@
           ode);
     }
     modifications = getModifications(newEntry, oldEntry, getInfo());
+    // Find password modifications
+    for (ModificationItem mod : modifications)
+    {
+      if (mod.getAttribute().getID().equalsIgnoreCase("userPassword"))
+      {
+        passwordModification = mod;
+        break;
+      }
+    }
+    if (passwordModification != null)
+    {
+      modifications.remove(passwordModification);
+    }
     hasModifications = modifications.size() > 0 ||
-    !oldDn.equals(newEntry.getDN());
+    !oldDn.equals(newEntry.getDN()) ||
+    (passwordModification != null);
   }
 
   /**
@@ -287,6 +303,60 @@
   }
 
   /**
+   * {@inheritDoc}
+   */
+  public void postOperation()
+  {
+    if ((lastException == null) && (state == State.FINISHED_SUCCESSFULLY) &&
+        (passwordModification != null))
+    {
+      try
+      {
+        Object o = passwordModification.getAttribute().get();
+        String sPwd;
+        if (o instanceof byte[])
+        {
+          try
+          {
+            sPwd = new String((byte[])o, "UTF-8");
+          }
+          catch (Throwable t)
+          {
+            throw new IllegalStateException("Unexpected error: "+t, t);
+          }
+        }
+        else
+        {
+          sPwd = String.valueOf(o);
+        }
+        ResetUserPasswordTask newTask = new ResetUserPasswordTask(getInfo(),
+            getProgressDialog(), (BasicNode)treePath.getLastPathComponent(),
+            controller, sPwd.toCharArray());
+        if ((modifications.size() > 0) || mustRename)
+        {
+          getProgressDialog().appendProgressHtml("<br><br>");
+        }
+        StatusGenericPanel.launchOperation(newTask,
+            INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUMMARY.get(),
+            INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUCCESSFUL_SUMMARY.get(),
+            INFO_CTRL_PANEL_RESETTING_USER_PASSWORD_SUCCESSFUL_DETAILS.get(),
+            ERR_CTRL_PANEL_RESETTING_USER_PASSWORD_ERROR_SUMMARY.get(),
+            ERR_CTRL_PANEL_RESETTING_USER_PASSWORD_ERROR_DETAILS.get(),
+            null,
+            getProgressDialog(),
+            false,
+            getInfo());
+        getProgressDialog().setVisible(true);
+      }
+      catch (NamingException ne)
+      {
+        // This should not happen
+        throw new IllegalStateException("Unexpected exception: "+ne, ne);
+      }
+    }
+  }
+
+  /**
    * Modifies and renames the entry.
    * @param ctx the connection to the server.
    * @param oldDN the oldDN of the entry.

--
Gitblit v1.10.0