Camel Component: LDAP - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

The ldap component allows you to perform searches in LDAP servers using filters as the message payload.

This component uses standard JNDI (javax.naming package) to access the server.

Maven users will need to add the following dependency to their pom.xml for this component:

   <!-- use the same version as your Camel core version -->

URI format


The ldapServerBean portion of the URI refers to a DirContext bean in the registry. The LDAP component only supports producer endpoints, which means that an ldap URI cannot appear in the from at the start of a route.

For more information about the DirContext bean, see its JAVA API documentation corresponding to the version of JAVA you are using.

You can append query options to the URI in the following format, ?option=value&option=value&...


Table 14. 


Default Value




The base DN for searches.



Specifies how deeply to search the tree of entries, starting at the base DN. Value can be object, onelevel, or subtree.


no paging used

When specified the ldap module uses paging to retrieve all results (most LDAP Servers throw an exception when trying to retrieve more than 1000 entries in one query). To be able to use this a LdapContext (subclass of DirContext) has to be passed in as ldapServerBean (otherwise an exception is thrown)


depends on LDAP Server (could be all or none)

Comma-separated list of attributes that should be set in each entry of the result


The result is returned in the Out body as a ArrayList<> object.


The URI, ldap:ldapserver, references a Spring bean with the ID, ldapserver. The ldapserver bean may be defined as follows:

<bean id="ldapserver" class="" 
      <prop key="java.naming.provider.url">ldap://localhost:10389</prop>       
      <prop key="">none</prop>

The preceding example declares a regular Sun based LDAP DirContext that connects anonymously to a locally hosted LDAP server.


DirContext objects are not required to support concurrency by contract. It is therefore important that the directory context is declared with the setting, scope="prototype", in the bean definition or that the context supports concurrency. In the Spring framework, prototype scoped objects are instantiated each time they are looked up.


Following on from the Spring configuration above, the code sample below sends an LDAP request to filter search a group for a member. The Common Name is then extracted from the response.

ProducerTemplate<Exchange> template = exchange

Collection<?> results = (Collection<?>) (template

if (results.size() > 0) {
  // Extract what we need from the device's profile
  Iterator<?> resultIter = results.iterator();
  SearchResult searchResult = (SearchResult) resultIter
  Attributes attributes = searchResult
  Attribute deviceCNAttr = attributes.get("cn");
  String deviceCN = (String) deviceCNAttr.get();


If no specific filter is required - for example, you just need to look up a single entry - specify a wildcard filter expression. For example, if the LDAP entry has a Common Name, use a filter expression like:


Binding using credentials

A Camel end user donated this sample code he used to bind to the ldap server using credentials.

Properties props = new Properties();
props.setProperty(Context.PROVIDER_URL, "ldap://localhost:389");
props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
props.setProperty(Context.REFERRAL, "ignore");
props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
props.setProperty(Context.SECURITY_PRINCIPAL, "cn=Manager");
props.setProperty(Context.SECURITY_CREDENTIALS, "secret");

SimpleRegistry reg = new SimpleRegistry();
reg.put("myldap", new InitialLdapContext(props, null));

CamelContext context = new DefaultCamelContext(reg);
    new RouteBuilder() {
        public void configure() throws Exception { 

ProducerTemplate template = context.createProducerTemplate();

Endpoint endpoint = context.getEndpoint("direct:start");
Exchange exchange = endpoint.createExchange();
Exchange out = template.send(endpoint, exchange);

Collection<SearchResult> data = out.getOut().getBody(Collection.class);
assert data != null;
assert !data.isEmpty();