Spring LDAP 常见问题

操作属性

如何使用 context.removeAttributeValue() 删除操作属性?

默认情况下,DirContextAdapter 只读取可见属性。这是因为操作属性只有在明确请求时才由服务器返回,并且 Spring LDAP 无法知道要请求哪些属性。这意味着 DirContextAdapter 不会填充操作属性。因此,removeAttributeValue 不会产生任何效果(因为,从 DirContextAdapter 的角度来看,它一开始就不存在)。

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

  • 使用接受属性名称作为参数的搜索或查找方法,例如 LdapTemplate#lookup(Name, String[], ContextMapper)。然后使用一个 ContextMapper 实现,该实现返回 mapFromContext() 中提供的 DirContextAdapter

  • 直接使用 LdapTemplate#modifyAttributes(Name, ModificationItem[]),手动构建 ModificationItem 数组。

© . This site is unofficial and not affiliated with VMware.