From 99a2da7abf1dc83881842841c0cfaaa5090ff3b5 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 29 Jul 2011 10:36:10 +0000
Subject: [PATCH] Fix issue OPENDJ-248: Call Account Status Notification Handlers when account gets enabled / disabled with the manage-account CLI.

---
 opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java
index 6455583..62a7153 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordPolicyStateExtendedOperation.java
@@ -58,7 +58,8 @@
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
-
+import static org.opends.messages.CoreMessages.INFO_MODIFY_ACCOUNT_DISABLED;
+import static org.opends.messages.CoreMessages.INFO_MODIFY_ACCOUNT_ENABLED;
 
 
 /**
@@ -434,7 +435,8 @@
   // The search filter that will be used to retrieve user entries.
   private SearchFilter userFilter;
 
-
+  private boolean isAccountSetDisabled;
+  private boolean isAccountSetEnabled;
 
   /**
    * Create an instance of this password policy state extended operation.  All
@@ -615,6 +617,8 @@
       return;
     }
 
+    isAccountSetDisabled = false;
+    isAccountSetEnabled = false;
     // Create a hash set that will be used to hold the types of the return
     // types that should be included in the response.
     boolean returnAll;
@@ -750,6 +754,24 @@
       operation.appendErrorMessage(message);
       operation.setResultCode(ResultCode.PROTOCOL_ERROR);
     }
+    // Post AccountStatus Notifications if needed.
+    if (isAccountSetDisabled)
+    {
+      pwpState.generateAccountStatusNotification(
+            AccountStatusNotificationType.ACCOUNT_DISABLED,
+            userEntry, INFO_MODIFY_ACCOUNT_DISABLED.get(),
+            AccountStatusNotification.createProperties(pwpState, false, -1,
+                 null, null));
+
+    }
+    if (isAccountSetEnabled)
+    {
+      pwpState.generateAccountStatusNotification(
+            AccountStatusNotificationType.ACCOUNT_ENABLED,
+            userEntry, INFO_MODIFY_ACCOUNT_ENABLED.get(),
+            AccountStatusNotification.createProperties(pwpState, false, -1,
+                 null, null));
+    }
   }
 
   /**
@@ -1299,10 +1321,12 @@
           if (value.equalsIgnoreCase("true"))
           {
             pwpState.setDisabled(true);
+            isAccountSetDisabled = true;
           }
           else if (value.equalsIgnoreCase("false"))
           {
             pwpState.setDisabled(false);
+            isAccountSetEnabled = true;
           }
           else
           {
@@ -1318,6 +1342,7 @@
 
       case OP_CLEAR_ACCOUNT_DISABLED_STATE:
         pwpState.setDisabled(false);
+        isAccountSetEnabled = true;
         returnTypes.add(OP_GET_ACCOUNT_DISABLED_STATE);
         break;
 

--
Gitblit v1.10.0