Spring LDAP 常见问题解答
操作属性
如何通过context.removeAttributeValue()?
默认情况下,DirContextAdapter 仅读取可见属性。这是因为操作属性只有在明确请求时才会由服务器返回,而 Spring LDAP 无法知道需要请求哪些属性。这意味着 DirContextAdapter 不会包含操作属性。因此,removeAttributeValue 对 DirContextAdapter 没有作用(从 DirContextAdapter 的角度来看,它本来就不在其中)。
基本上有两种方法可以实现此操作:
-
使用一个接受属性名称作为参数的查找或搜索方法,例如
LdapTemplate#lookup(Name, String[], ContextMapper)。然后使用一个ContextMapper实现,该实现返回传入的DirContextAdapter在mapFromContext()中。 -
使用
LdapTemplate#modifyAttributes(Name, ModificationItem[])直接,手动构建ModificationItem数组。