在Apache Camel LDAP组件中分配结果

时间:2015-05-11 09:19:21

标签: java ldap apache-camel

我需要从LDAP中获取多个条目(> 1000个用户)。文档(http://camel.apache.org/ldap.html)表示有一个pageSize选项。

的pageSize
"当指定时,ldap模块使用分页来检索所有结果(大多数LDAP服务器在尝试在一个查询中检索超过1000个条目时抛出异常)。为了能够使用它,必须将LdapContext(DirContext的子类)作为ldapServerBean传入(否则抛出异常)"

这是什么意思?如何传递LdapContext以及如何遍历页面?有人可以给我一个简单的例子,其中从LDAP中提取了许多条目吗?

2 个答案:

答案 0 :(得分:0)

除了指定pageSize参数外,您可能不需要做任何其他事情。该说明澄清了您可能不会遇到的小问题。

ldap组件不仅限于从LdapContext读取,它可以使用DirContext(超级接口)的实例。使用此超级接口的实例将使用以设置pageSize。如果您按照Camel文档中的示例进行操作,您将看到它正在使用com.sun.jndi.ldap.LdapCtxFactory作为上下文bean的工厂。此类构建实现LdapContext的对象,因此pageSize参数应该有效。

例如,您只需将参数添加到URI。

Collection<?> results = (Collection<?>) (template
  .sendBody(
    "ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system&pageSize=1000",
    "(member=uid=huntc,ou=users,ou=system)"));

答案 1 :(得分:0)

您的问题已经很老了,但是答案还可以帮助其他人,因为Camel的LDAP端点还不清楚。下面是一个工作示例:

<bean id="ldapServerBean" class="javax.naming.ldap.InitialLdapContext" scope="prototype">
<constructor-arg>
    <props>
        <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
        <prop key="java.naming.provider.url">${ldap.url}</prop>
        <prop key="java.naming.security.authentication">simple</prop>
        <prop key="java.naming.security.principal">${ldap.user}</prop>
        <prop key="java.naming.security.credentials">${ldap.password}</prop>
    </props>
</constructor-arg>
<constructor-arg>
    <null />
</constructor-arg>
</bean>

路线:

<route id="LDAP" autoStartup="{{route.autoStartup}}">
    <from uri="quartz2://ldapTimer?cron={{scheduler.cron}}"/>
    <setBody><simple>{{ldap.filter}}</simple></setBody>
    <to uri="ldap:ldapServerBean?base={{ldap.base}}&amp;scope={{ldap.scope}}&amp;returnedAttributes={{ldap.returnedAttributes}}&amp;pageSize={{ldap.pageSize}}"/>
    <log loggingLevel="INFO" message="LDAP Result: ${body}"/>
    <to ...>
</route>

通过这种方式,您可以利用路由中作为参数提供的pageSize,并且能够从LDAP服务器检索1000条以上的记录。