Spring LDAP FAQ

Operational Attributes

How do I remove an operational attribute by using context.removeAttributeValue()?

默认情况下,DirContextAdapter 仅读取可见的属性。这是因为只有在明确要求时才会由服务器返回操作属性,而 Spring LDAP 无法知道要询问哪些属性。这意味着未使用操作属性填充 DirContextAdapter。因此,removeAttributeValue 没有任何效果(因为从 DirContextAdapter 的角度来看,它本来就不存在)。

By default, the DirContextAdapter reads only the visible attributes. This is because the operational attributes are returned by the server only if explicitly asked for, and there is no way for Spring LDAP to know the attributes for which to ask. This means that the DirContextAdapter is not populated with the operational attributes. Consequently, the removeAttributeValue does not have any effect (since, from the point of view of the DirContextAdapter, it was not there in the first place).

基本上有两种方法可以做到这一点:

There are basically two ways to do this:

  • Use a search or lookup method that takes the attribute names as an argument, such as LdapTemplate#lookup(Name, String[], ContextMapper). Then use a ContextMapper implementation that returns the supplied DirContextAdapter in mapFromContext().

  • Use LdapTemplate#modifyAttributes(Name, ModificationItem[]) directly, manually building the ModificationItem array.