132.6. 使用方法


组件仅支持制作者端点。尝试创建消费者端点可能会导致 UnsupportedOperationException
消息的正文必须是映射( java.util.Map实例)。除非在 ContextSource 配置中指定基本 DN,否则此映射必须至少包含一个带有键 dn (不需要 function_driven 操作)的条目,用来指定执行 LDAP 操作的 root 节点。映射的其他条目是特定于操作的。

对于 bindunbind 操作,消息的正文保持不变。有关 searchfunction_driven 操作,正文被设置为搜索的结果,请参阅 http://static.springsource.org/spring-ldap/site/apidocs/org/springframework/ldap/core/LdapTemplate.html#search%28java.lang.String,%20java.lang.String,%20int,%20org.springframework.ldap.core.AttributesMapper%29

132.6.2. 绑定

消息正文必须具有一个带有关键 属性 的条目。该值必须是 javax.naming.directory.Attributes 此条目的实例,指定要创建的 LDAP 节点。

132.6.3. unbind

不需要其他条目,会删除带有指定 dn 的节点。

132.6.4. 身份验证

消息正文必须具有带有键 过滤器 和密码 的条目。该值必须是 String 实例,分别代表有效的 LDAP 过滤器和用户密码。

132.6.5. 修改属性

消息正文必须具有带有密钥 modify Items 的条目。该值必须是任何类型为 javax.naming.directory.ModificationItem的数组的实例

132.6.6. function-Driven

消息正文必须具有带有密钥函数和 请求 的条目。功能 值必须是 java.util.function.BiFunction<L, Q, S > 类型。L type 参数必须是 org.springframework.ldap.core.LdapOperationsrequest 值必须与函数中的 Q type 参数相同,它必须封装 函数 中调用的 LdapTemplate 方法所预期的参数。 S type 参数代表被调用的 LdapTemplate 方法返回的响应类型。此操作允许动态调用上述操作未涵盖的 LdapTemplate 方法。

键定义

为避免拼写错误,在 org.apache.camel.springldap.springLdapProducer 中定义以下常量:

  • public static final String DN = "dn"
  • 公共静态最终字符串 FILTER = "filter"
  • 公共静态最终字符串 ATTRIBUTES = "attributes"
  • 公共静态最终字符串 PASSWORD = "password";
  • 公共静态最终字符串 MODIFICATION_ITEMS = "modificationItems";
  • 公共静态最终字符串 FUNCTION = "function";
  • 公共静态最终字符串 REQUEST = "request";

以下是 createMap 功能示例:

from(“direct:start”)
    .setBody(constant(createMap()))
    .to("spring-ldap:ldapTemplate?operation=BIND");

在这里,createMap 功能返回 Map 对象,其中包含 ldap 服务器的属性和域名的信息。

private static Map<String, Object> createMap() {
    BasicAttributes basicAttributes = new BasicAttributes();
    basicAttributes.put("cn", "Name Surname");
    basicAttributes.put("sn", "Surname");
    basicAttributes.put("objectClass", "person");
    Map<String, Object> map = new HashMap<>();
    map.put(SpringLdapProducer.DN, "cn=LdapDN,dc=example,dc=org");
    map.put(SpringLdapProducer.ATTRIBUTES, basicAttributes);
    return map;
}

您还必须为上例使用 Spring Boot 自动配置或 LdapTemplate Bean 配置 ldap 连接。

Spring Boot 自动配置示例:

spring.ldap.password=passwordforldapserver
spring.ldap.urls=urlForLdapServer
spring.ldap.username=usernameForLdapServer
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.