From 439a48e88a9891e3e3e813ca06bfbcbf54bcb140 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Wed, 20 Jul 2011 09:37:34 +0000
Subject: [PATCH] Fix issue OPENDJ-237: Password modification by deleting the value and adding a new one fails with unwilling to perform (would result in multiple password in the entry). Make sure we update the passwords counters when deleting values. Unit-tests added to make sure we do not have regressions in the future
---
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
index e37efe2..858bd6a 100644
--- a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
+++ b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
@@ -1323,6 +1323,12 @@
// encoded forms.
Attribute pwAttr = m.getAttribute();
AttributeBuilder builder = new AttributeBuilder(pwAttr, true);
+ if (pwAttr.isEmpty())
+ {
+ // Removing all current password values.
+ numPasswords = 0;
+ }
+
for (AttributeValue v : pwAttr)
{
if (pwPolicyState.passwordIsPreEncoded(v.getValue()))
@@ -1335,7 +1341,31 @@
}
else
{
- builder.add(v);
+ // We still need to check if the pre-encoded password matches
+ // an existing value, to decrease the number of passwords.
+ List<Attribute> attrList = currentEntry.getAttribute(pwAttr
+ .getAttributeType());
+ if ((attrList == null) || (attrList.isEmpty()))
+ {
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+ ERR_MODIFY_NO_EXISTING_VALUES.get());
+ }
+ boolean found = false;
+ for (Attribute attr : attrList)
+ {
+ for (AttributeValue av : attr)
+ {
+ if (av.equals(v))
+ {
+ builder.add(v);
+ found = true;
+ }
+ }
+ }
+ if (found)
+ {
+ numPasswords--;
+ }
}
}
else
--
Gitblit v1.10.0