Announcement Announcement Module
Collapse
No announcement yet.
simpleLdapTemplate - how can I remove an attribute? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • simpleLdapTemplate - how can I remove an attribute?

    I'm successfully using simpleLdapTemplate for all of my ldap CRUD operations; however, I cannot find a way to actually remove a particular attribute from an entry. I can only set the attribute value to empty or null but cannot find a way to set the equivalent DirContext.REMOVE_ATTRIBUTE ModificationItem.

    Is there a way to use simpleLdapTemplate and still have this granular level of control?

  • #2
    AFAIK, there is no direct method in SimpleLdapTempalte to remove an attribute. However, you can use the SimpleLdapTemplate to get an instnace of LdapOperations and use it to remove an attribute. Here is some code that can help you:

    Code:
        public void removeAttribute(String dn, String name, String value)
        {
        	ModificationItem[] items = new ModificationItem[]{
                    					new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(name, value))
            							};
        	LdapOperations ldapOperations = ldapTemplate.getLdapOperations();
            ldapOperations.modifyAttributes(dn, items);    	
        }

    Comment

    Working...
    X