gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:11:42 25 4
gpt4 key购买 nike

当我查找 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com