Chapter 62. Spring LDAP Since Camel 2.11 Only producer is supported The Spring LDAP component provides a Camel wrapper for Spring LDAP . Maven users must add the following dependency to their pom.xml for this component: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-ldap</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> 62.1. URI format Where springLdapTemplate is the name of the Spring LDAP Template bean . In this bean, you configure the URL and the credentials for your LDAP access. 62.2. Configuring Options Camel components are configured on two levels: Component level Endpoint level 62.2.1. Component Level Options The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on. Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all. You can configure components with Component DSL in a configuration file (application.properties|yaml), or directly with Java code. 62.2.2. Endpoint Level Options At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer (from) or as a producer (to) or used for both. You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java. When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings. Placeholders allows you to externalize the configuration from your code, giving you more flexible and reusable code. 62.3. Component Options The Spring LDAP component supports 2 options, which are listed below. Name Description Default Type lazyStartProducer (producer) Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false boolean autowiredEnabled (advanced) Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. true boolean 62.4. Endpoint Options The Spring LDAP endpoint is configured using URI syntax: Following are the path and query parameters: 62.4.1. Path Parameters (1 parameters) Name Description Default Type templateName (producer) Required Name of the Spring LDAP Template bean. String 62.4.2. Query Parameters (3 parameters) Name Description Default Type operation (producer) Required The LDAP operation to be performed. Enum values: SEARCH BIND UNBIND AUTHENTICATE MODIFY_ATTRIBUTES FUNCTION_DRIVEN LdapOperation scope (producer) The scope of the search operation. Enum values: object onelevel subtree subtree String lazyStartProducer (producer (advanced)) Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false boolean 62.5. Usage The component supports producer endpoints only. An attempt to create a consumer endpoint can result in an UnsupportedOperationException . The body of the message must be a map (an instance of java.util.Map ). Unless a base DN is specified in the configuration of your ContextSource, this map must contain at least an entry with the key dn (not needed for function_driven operation) that specifies the root node for the LDAP operation to be performed. Other entries of the map are operation-specific. The body of the message remains unchanged for the bind and unbind operations. For the search and function_driven operations, the body is set to the result of the search, see 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 . 62.5.1. Search The message body must have an entry with the key filter . The value must be a String representing a valid LDAP filter, see http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol#Search_and_Compare . 62.5.2. Bind The message body must have an entry with the key attributes . The value must be an instance of javax.naming.directory.Attributes This entry specifies the LDAP node to be created. 62.5.3. Unbind No further entries are necessary, the node with the specified dn is deleted. 62.5.4. Authenticate The message body must have entries with the keys filter and password . The values must be an instance of String representing a valid LDAP filter and a user password, respectively. 62.5.5. Modify Attributes The message body must have an entry with the key modificationItems . The value must be an instance of any array of type javax.naming.directory.ModificationItem 62.5.6. Function-Driven The message body must have entries with the keys function and request . The function value must be of type java.util.function.BiFunction<L, Q, S> . The L type parameter must be of type org.springframework.ldap.core.LdapOperations . The request value must be the same type as the Q type parameter in the function and it must encapsulate the parameters expected by the LdapTemplate method being invoked within the function . The S type parameter represents the response type as returned by the LdapTemplate method being invoked. This operation allows dynamic invocation of LdapTemplate methods that are not covered by the operations mentioned above. Key definitions In order to avoid spelling errors, the following constants are defined in org.apache.camel.springldap.SpringLdapProducer : public static final String DN = "dn" public static final String FILTER = "filter" public static final String ATTRIBUTES = "attributes" public static final String PASSWORD = "password"; public static final String MODIFICATION_ITEMS = "modificationItems"; public static final String FUNCTION = "function"; public static final String REQUEST = "request"; Following is an example of createMap function: Here, createMap function returns Map object that contains information about attributes and domain name of ldap server. You must also configure ldap connection using Spring Boot auto-configuration or LdapTemplate Bean for the above example. Example for Spring Boot auto-configuration: 62.6. Spring Boot Auto-Configuration When using spring-ldap with Spring Boot, use the following Maven dependency to enable support for auto configuration: <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-ldap-starter</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> The component supports 3 options that are listed below. Name Description Default Type camel.component.spring-ldap.autowired-enabled Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. true Boolean camel.component.spring-ldap.enabled Whether to enable auto configuration of the spring-ldap component. This is enabled by default. Boolean camel.component.spring-ldap.lazy-start-producer Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false Boolean

Commands:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-ldap</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
spring-ldap:springLdapTemplate[?options]
spring-ldap:templateName
from("direct:start") .setBody(constant(createMap())) .to("spring-ldap:ldapTemplate?operation=BIND");
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.ldap.password=passwordforldapserver spring.ldap.urls=urlForLdapServer spring.ldap.username=usernameForLdapServer
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-ldap-starter</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>