From 3b357835c4678d4d7ceccd87e9b54a200186f590 Mon Sep 17 00:00:00 2001 From: Turki Alzubaidi <35930561+AlzubaidiTurki@users.noreply.github.com> Date: Wed, 8 Feb 2023 00:27:18 +0300 Subject: [PATCH] check Id equality while ignoring case. LDAP attribute names are case insensitive. however, they are case aware. figured this when I tried to implement an entry. Take this case, let us say we have an attribute named "Mobile" with capital M in LDAP, if we type: @Attribute(name="mobile") // small m String mobile; In fetching process, this is fine. attribute is mapped properly and mobile variable will store whatever value. However, during saving process, the condition !id.equals(that.id) will compare "mobile" to "Mobile", and it will assume these attributes are not the same. thus it will be treated as an attribute that should go to REPLACE LDAP operation. Now, using Replace to non existing attribute will add that attribute to the LDAP entry. so "mobile" should be added. but actually what happens is the same as when we fetch attributes. LDAP will treat replace the value and won't create a new attribute. What is the new value? it is the same as the original one, since value haven't been touched. This causes a meaningless LDAP REPLACE operations. Hope that is clear and makes sense :) Acknowledgement: Wouldn't figure this out without the help of my dear mentor Mosaed Alsharyan, and my friend Omar Alhamdan --- .../java/org/springframework/ldap/core/NameAwareAttribute.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java b/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java index bb0003c19..ecaee73b8 100644 --- a/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java +++ b/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java @@ -293,7 +293,7 @@ public boolean equals(Object o) { NameAwareAttribute that = (NameAwareAttribute) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (id != null ? !id.equalsIgnoreCase(that.id) : that.id != null) return false; if(this.values.size() != that.values.size()) { return false; }