From 56100637ded7f7f68c9a60436e3fe0c792961a02 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 30 Nov 2006 21:50:39 +0000
Subject: [PATCH] Update the extended operation handler API to provide the ability for custom extended operations to handle their own controls.  The password modify extended operation has been updated to support the LDAP no-op control and the password policy control.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
index 4bf9eaa..444bc29 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPPasswordModify.java
@@ -33,6 +33,9 @@
 import java.util.ArrayList;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.opends.server.controls.PasswordPolicyErrorType;
+import org.opends.server.controls.PasswordPolicyResponseControl;
+import org.opends.server.controls.PasswordPolicyWarningType;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.protocols.asn1.ASN1Element;
 import org.opends.server.protocols.asn1.ASN1OctetString;
@@ -755,6 +758,50 @@
     }
 
 
+    // See if the response included any controls that we recognize, and if so
+    // then handle them.
+    ArrayList<LDAPControl> responseControls = responseMessage.getControls();
+    if (responseControls != null)
+    {
+      for (LDAPControl c : responseControls)
+      {
+        if (c.getOID().equals(OID_PASSWORD_POLICY_CONTROL))
+        {
+          try
+          {
+            PasswordPolicyResponseControl pwPolicyControl =
+                 PasswordPolicyResponseControl.decodeControl(c.getControl());
+
+            PasswordPolicyWarningType pwPolicyWarningType =
+                 pwPolicyControl.getWarningType();
+            if (pwPolicyWarningType != null)
+            {
+              int    msgID   = MSGID_LDAPPWMOD_PWPOLICY_WARNING;
+              String message = getMessage(msgID, pwPolicyWarningType.toString(),
+                                          pwPolicyControl.getWarningValue());
+              out.println(wrapText(message, MAX_LINE_WIDTH));
+            }
+
+            PasswordPolicyErrorType pwPolicyErrorType =
+                 pwPolicyControl.getErrorType();
+            if (pwPolicyErrorType != null)
+            {
+              int    msgID   = MSGID_LDAPPWMOD_PWPOLICY_ERROR;
+              String message = getMessage(msgID, pwPolicyErrorType.toString());
+              out.println(wrapText(message, MAX_LINE_WIDTH));
+            }
+          }
+          catch (Exception e)
+          {
+            int    msgID   = MSGID_LDAPPWMOD_CANNOT_DECODE_PWPOLICY_CONTROL;
+            String message = getMessage(msgID, String.valueOf(e));
+            err.println(wrapText(message, MAX_LINE_WIDTH));
+          }
+        }
+      }
+    }
+
+
     // See if the response included a generated password.
     ASN1OctetString responseValue = extendedResponse.getValue();
     if (responseValue != null)

--
Gitblit v1.10.0