Chapter 211. LDAP Component
Available as of Camel version 1.5
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:
211.1. URI format Copy linkLink copied to clipboard!
ldap:ldapServerBean[?options]
ldap:ldapServerBean[?options]
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.
You can append query options to the URI in the following format, ?option=value&option=value&…
211.2. Options Copy linkLink copied to clipboard!
The LDAP component has no options.
The LDAP endpoint is configured using URI syntax:
ldap:dirContextName
ldap:dirContextName
with the following path and query parameters:
211.2.1. Path Parameters (1 parameters): Copy linkLink copied to clipboard!
Name | Description | Default | Type |
---|---|---|---|
dirContextName | Required Name of either a javax.naming.directory.DirContext, or java.util.Hashtable, or Map bean to lookup in the registry. If the bean is either a Hashtable or Map then a new javax.naming.directory.DirContext instance is created for each use. If the bean is a javax.naming.directory.DirContext then the bean is used as given. The latter may not be possible in all situations where the javax.naming.directory.DirContext must not be shared, and in those situations it can be better to use java.util.Hashtable or Map instead. | String |
211.2.2. Query Parameters (5 parameters): Copy linkLink copied to clipboard!
Name | Description | Default | Type |
---|---|---|---|
base (producer) | The base DN for searches. | ou=system | String |
pageSize (producer) | 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) | Integer | |
returnedAttributes (producer) | Comma-separated list of attributes that should be set in each entry of the result | String | |
scope (producer) | Specifies how deeply to search the tree of entries, starting at the base DN. | subtree | String |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
211.3. Spring Boot Auto-Configuration Copy linkLink copied to clipboard!
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.ldap.enabled | Enable ldap component | true | Boolean |
camel.component.ldap.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
211.4. Result Copy linkLink copied to clipboard!
The result is returned in the Out body as a ArrayList<javax.naming.directory.SearchResult>
object.
211.5. DirContext Copy linkLink copied to clipboard!
The URI, ldap:ldapserver
, references a Spring bean with the ID, ldapserver
. The ldapserver
bean may be defined as follows:
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.
211.6. Samples Copy linkLink copied to clipboard!
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.
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:
(cn=*)
(cn=*)
211.6.1. Binding using credentials Copy linkLink copied to clipboard!
A Camel end user donated this sample code he used to bind to the ldap server using credentials.
211.7. Configuring SSL Copy linkLink copied to clipboard!
All required is to create a custom socket factory and reference it in the InitialDirContext bean - see below sample.
SSL Configuration
Custom Socket Factory
211.8. See Also Copy linkLink copied to clipboard!
- Configuring Camel
- Component
- Endpoint
- Getting Started