ldap - Spring ldapTemplate : how to lookup fully qualified DN with configured base DN?

标签 ldap spring-ldap

当我查找 DN 时带 Spring ldapTemplate , 我必须省略配置的基本 DN。

例如,当基本 DN 配置为 dc=company,dc=com 时,工作查找就像

ldapTemplate.lookup("ou=whatever,ou=groups")

当我通过完全限定的 DN 时

ldapTemplate.lookup("ou=whatever,ou=groups,dc=company,dc=com")

查找失败并提示 DN ou=whatever,ou=groups,dc=company,dc=com,dc=company,dc=com(注意末尾的双底)不存在。

因此,当我根据之前查找返回的 DN 进行查找时,我必须从 DN 的末尾删除基数。

这很烦人,我几乎可以肯定有更好的方法来做到这一点。

那么,我该如何查找具有配置的基本 DN 的完全限定 DN?

我知道有一个采用基本参数的查询方法,但这似乎是为了更真实的查询,而不是简单的查找。

使用@jzheaux 接受的答案的示例

LdapName fqdn = ... //fully qualified DN with base DN that is returned from lookup
LdapName baseDn = ((LdapContextSource) ldapTemplate.getContextSource()).getBaseLdapName();
LdapName lookupDn = LdapUtils.removeFirst(fqdn, baseDn);

最佳答案

根据 JavaDoc,这就是 LdapUtils#removeFirst 的用途:

/**
 * Remove the supplied path from the beginning the specified
 * <code>Name</code> if the name instance starts with
 * <code>path</code>. Useful for stripping base path suffix from a
 * <code>Name</code>.
**/

或者,您可以在没有基础的情况下配置您的 ContextSource。然后,您的所有查询都使用完全限定名称。或者,您可以使用多个 ContextSource;一个配置了基础,另一个没有。

关于ldap - Spring ldapTemplate : how to lookup fully qualified DN with configured base DN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55285743/

相关文章:

php - 如何使用 CodeIgniter 和 adLDAP v2.1 库排除 LDAP 域下的特定文件夹

java - Spring Security Active Directory 忽略 PartialResultException

java - 使用 LdapTemplate 时 LDAP 连接不会关闭

spring-boot - 使用 Spring 从 LDAP 检索用户信息

java - bean 类 [org.springframework.ldap.core.LdapTemplate] 的属性 'defaultCountLimit' 无效

active-directory - 如何在两个 FreeIPA 服务器之间配置信任?

mysql - 在 MySQL 数据库中使用 sAMAccountName 作为 uid

java - Spring LDAP 引用 : No PersonRepo interface

php - 使用 LDAP/PHP/IIS/SSL 在 Active Directory 中更改密码

spring ldap 2.0.1 替换已弃用的 OdmManager