I want to delete attribute with multiple values but it ignores this while successfully deletes another attribute with specific value in directory.
Attribute attr1 = new BasicAttribute("fooAttr");
ModificationItem attr1mod = new
ModificationItem(DirContext.REMOVE_ATTRIBUTE,attr1);
Attribute attr2 = new BasicAttribute("barAttr","my value");
ModificationItem attr2mod = new
ModificationItem(DirContext.REMOVE_ATTRIBUTE,attr2);
try{
ldapTemplate.modifyAttributes("cn=myname,dc=example,dc=com", new
ModificationItem[]{attr1mod, attr2mod});
} catch(Exception e) {
//
}
barAttr is deleted with the specified value but multivalued fooAttr is not deleted.
barAttr is also multivalued and the specified value is deleted. I also tried to delete a specified value of fooAttr and still it failed to delete the specified value of fooAttr. I confirmed externally that fooAttr exists in the directory.
ldapTemplate.modifyAttributes executes successfully, does not throw exception.
If I do this:
ldapTemplate.modifyAttributes("cn=myname,dc=example,dc=com", new
ModificationItem[]{attr1mod});
then in this case exception is thrown:
LDAP: error code 16 - Failed to modify the underlying source: No such attribute
UPDATE I also tried this approach:
DirContextOperation context = ldaptemplate.lookup(dn);
String [] fooAttrValues = context.getStringAttributes("fooAttr");
for(String value : fooattrValues) {
context.removeAttributeValue("fooAttr", value);
}
String [] fooAttrValues2 = context.getStringAttributes("fooAttr");
This does not work, after program is run the director still has the same attribute and all the values. I debugged through it, it does get the correct values but does not remove any value, even fooAttrValues2 still has all the values.
How can I fix this problem?