Class DirContextAdapter

java.lang.Object
org.springframework.ldap.core.DirContextAdapter
All Implemented Interfaces:
Context, DirContext, AttributeModificationsAware, DirContextOperations, LdapDataEntry

public class DirContextAdapter extends Object implements DirContextOperations
Adapter that implements the interesting methods of the DirContext interface. In particular it contains utility methods for getting and setting attributes. Using the DefaultDirObjectFactory in your ContextSource (which is the default) you will receive instances of this class from searches and lookups. This can be particularly useful when updating data, since this class implements AttributeModificationsAware, providing a getModificationItems() method. When in update mode, an object of this class keeps track of the changes made to its attributes, making them available as an array of ModificationItem objects, suitable as input to LdapTemplate.modifyAttributes(DirContextOperations).

For a multi-value attribute with only some of its values added or removed, this class ordinarily calculates individual "add value" and "remove value" modifications for just the values that changed. Some directory servers reject this for attributes without an equality matching rule defined in their schema, requiring the attribute to be replaced in its entirety instead. Use setMayRemoveByValue(BiPredicate) to control, per attribute, whether removing individual values is attempted at all.

This class is aware of the specifics of Name instances with regards to equality when working with attribute values. This comes in very handy when working with e.g. security groups and modifications of them. If Name instances are supplied to one of the Attribute manipulation methods (e.g. addAttributeValue(String, Object), removeAttributeValue(String, Object), setAttributeValue(String, Object), or setAttributeValues(String, Object[])), the produced modifications will be calculated using Name equality. This means that if an the member has a value of "cn=John Doe,ou=People", and we call addAttributeValue("member", LdapUtils.newLdapName("CN=John Doe,OU=People"), this will not be considered a modification since the two DN strings represent the same distinguished name (case and spacing between attributes is disregarded).

Note that this is not a complete implementation of DirContext. Several methods are not relevant for the intended usage of this class, so they throw UnsupportedOperationException.

See Also: