You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel YAML DSL路由查询LDAP属性的故障排查与解决

Apache Camel YAML DSL LDAP查询问题排查与临时解决

初始配置与第一个错误

尝试通过Apache Camel YAML DSL实现LDAP查询并输出结果到日志,初始路由及Bean定义如下:

- route:
    id: route-561c
    from:
      uri: timer:1000
      id: from-c523
      parameters:
        repeatCount: 1
      steps:
        - setBody:
            id: setBody-1772
            expression:
              simple:
                expression: '{"filter":"(sn=Amanda)"}'
                id: simple-12b7
                resultType: String
        - unmarshal:
            id: unmarshal-7216
            json:
              id: json-91b8
              library: Jackson
        - log:
            message: ${body[filter]}
            id: log-eab5
        - to:
            uri: spring-ldap:ldapTemplate
            id: to-60b7
            parameters:
              operation: SEARCH
        - log:
            message: ${body}
            id: log-18a8
            logName: logLdapResponse
- beans:
    - name: ldapContextSource
      properties:
        url: ldap://localhost:389
        base: ou=Users,dc=example,dc=org
        userDn: cn=admin,dc=example,dc=org
        password: admin
      type: org.springframework.ldap.core.support.LdapContextSource
    - name: ldapTemplate
      type: org.springframework.ldap.core.LdapTemplate

运行时抛出错误:"At least one server url must be set",尽管已在LdapContextSource Bean中配置了url属性。

调整配置后的新错误

按照建议将LDAP配置迁移到application.properties文件:

#LDAP
spring.ldap.base:ou=Users,dc=example,dc=org
spring.ldap.password:admin
spring.ldap.urls:ldap://localhost:389
spring.ldap.username:cn=admin,dc=example,dc=org

调整后路由可正常连接LDAP服务器,但出现新的异常:

2023-04-23T14:06:36.755+02:00  WARN 28704 --- [ - timer://1000] o.a.camel.component.timer.TimerConsumer  : Error processing exchange. Exchange[4A1AE7CEFE694EC-0000000000000000]. Caused by: [org.springframework.ldap.NameNotFoundException - [LDAP: error code 32 - No Such Object]]

org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - No Such Object]
        at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:183) ~[spring-ldap-core-3.0.2.jar:3.0.2]
        at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:386) ~[spring-ldap-core-3.0.2.jar:3.0.2]
        at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:338) ~[spring-ldap-core-3.0.2.jar:3.0.2]
...

查看OpenLDAP日志发现,查询的base被重复拼接为:base="ou=Users,dc=example,dc=org,ou=Users,dc=example,dc=org",这是导致LDAP错误码32(对象不存在)的原因。

根因与临时解决方案

经排查,该问题是camel-spring-ldap-starter版本4.0.0-M2存在的已知Bug,临时解决方法如下:

  • 注释application.properties中的spring.ldap.base属性
  • 将base信息整合到搜索过滤器中,例如把原过滤器(sn=Amanda)修改为(&(sn=Amanda)(ou=Users,dc=example,dc=org))(根据实际LDAP结构调整)

内容的提问来源于stack exchange,提问作者Jirmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 15:52:48