【问题标题】:Spring LDAP querybuilder PartialResultExceptionSpring LDAP 查询生成器 PartialResultException
【发布时间】:2017-07-10 20:27:41
【问题描述】:

我正在尝试从我的 LDAP 服务器获取所有用户,从基础进行搜索,这是我的代码:

public LdapTemplate ldapTemplate() {
        LdapContextSource ctxSrc = new LdapContextSource();
        ctxSrc.setUrl("ldap://127.0.0.1:389/");
        ctxSrc.setBase("dc=test,dc=com");
        ctxSrc.setUserDn("admin");
        ctxSrc.setPassword("password");
        ctxSrc.afterPropertiesSet();
        LdapTemplate lt = new LdapTemplate(ctxSrc);
        return lt;
}
private LdapTemplate ldapTemplate = ldapTemplate();
public List<User> getAllUsers() {

        LdapQuery query= query().base("").where("objectclass").is("user");
        return ldapTemplate.search(query, new UserAttributesMapper());
}

这是错误:

10:07:09.406 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
10:07:09.413 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
10:07:09.416 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://127.0.0.1:389/dc=test,dc=com
10:07:09.548 [main] DEBUG o.s.l.c.s.AbstractContextSource - Got Ldap context on server 'ldap://127.0.0.1:389/dc=test,dc=com'
Exception in thread "main" org.springframework.ldap.PartialResultException: Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name '/'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:216)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:385)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:616)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:586)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:1651)
    at ldap.example.UserRepositoryImpl.getAllUsers(UserRepositoryImpl.java:81)
    at ldap.example.test.LdapApp.main(LdapApp.java:23)
Caused by: javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name '/'
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2914)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2888)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.getNextBatch(AbstractLdapNamingEnumeration.java:148)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMoreImpl(AbstractLdapNamingEnumeration.java:217)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMore(AbstractLdapNamingEnumeration.java:189)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:365)
    ... 6 more

BUILD FAILED (total time: 1 second)

当我按ou 过滤时,它可以工作,但我需要从根过滤。

【问题讨论】:

标签: spring spring-ldap


【解决方案1】:

您在问题的评论中写道,更改端口会有所帮助。 但是改变端口并不能解决这个问题。 端口 3268 指向 Active Directory 特殊位置 - 全局目录。有一组所有对象 - 但每个对象只有一小部分属性(例如 distinguishedNamecnsAMAccountName...) . 所以 - 在您不需要更具体的属性之前,它一直有效。

问题分析

发生异常是因为 AD 作为您的查询结果返回 referral objects

[Active Directory] ​​(...) 生成 引用 以响应请求有关森林中存在但不包含在处理请求的目录服务器上的对象的数据的查询。这些被称为内部交叉引用,因为它们引用林中的域、模式和配置容器。

如果禁用了推荐追踪:

如果引用追踪未启用并执行子树搜索,则搜索将返回指定域内满足搜索条件的所有对象。搜索还将返回对作为目录服务器域的直接后代的任何从属域的引用。客户端必须通过绑定到引用指定的路径并提交另一个查询来解析引用。

您可以启用推荐追踪,但它需要花费 - 它会减慢应用程序 - 您可以阅读此 here。而且我认为在大多数情况下没有必要。

解决方案 1:

有时足够的解决方案是在您的问题中分配更具体的 baseDN - ctxSrc.setBase() 方法。也许您所有的用户都在内部路径中,例如"ou=user,dc=department,dc=test,dc=com"

this answer阅读更多内容。

解决方案 2:

在 Spring LdapTemplate 中,您也可以使用方法 setIgnorePartialResultException() 忽略此异常:

ldapTemplate.setIgnorePartialResultException(true);

this answer阅读更多内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 2014-10-05
    相关资源
    最近更新 更多