이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 84. LDAP
Since Camel 1.5
Only producer is supported
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.
84.1. Dependencies 링크 복사링크가 클립보드에 복사되었습니다!
When using ldap with Red Hat build of Camel Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-ldap-starter</artifactId> </dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-ldap-starter</artifactId>
</dependency>
84.2. URI format 링크 복사링크가 클립보드에 복사되었습니다!
ldap:ldapServerBean[?options]
ldap:ldapServerBean[?options]
The ldapServerBean in 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.
84.3. Configuring Options 링크 복사링크가 클립보드에 복사되었습니다!
Camel components are configured on two separate levels:
- component level
- endpoint level
84.3.1. Configuring Component Options 링크 복사링크가 클립보드에 복사되었습니다!
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
84.3.2. Configuring Endpoint Options 링크 복사링크가 클립보드에 복사되었습니다!
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL as a type safe way of configuring endpoints.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
84.4. Component Options 링크 복사링크가 클립보드에 복사되었습니다!
The 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 |
84.5. Endpoint Options 링크 복사링크가 클립보드에 복사되었습니다!
The LDAP endpoint is configured using URI syntax:
ldap:dirContextName
ldap:dirContextName
with the following path and query parameters:
84.5.1. Path Parameters (1 parameters) 링크 복사링크가 클립보드에 복사되었습니다!
| Name | Description | Default | Type |
|---|---|---|---|
| dirContextName (producer) | 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 |
84.5.2. Query Parameters (5 parameters) 링크 복사링크가 클립보드에 복사되었습니다!
| 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. Enum values:
| 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 |
84.6. Result 링크 복사링크가 클립보드에 복사되었습니다!
The result is returned to Out body as a List<javax.naming.directory.SearchResult> object.
84.7. DirContext 링크 복사링크가 클립보드에 복사되었습니다!
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.
84.9. Samples 링크 복사링크가 클립보드에 복사되었습니다!
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=*)
84.9.1. Binding using credentials 링크 복사링크가 클립보드에 복사되었습니다!
A Camel end user donated this sample code he used to bind to the ldap server using credentials.
84.10. Configuring SSL 링크 복사링크가 클립보드에 복사되었습니다!
All that is required is to create a custom socket factory and reference it in the InitialDirContext bean - see below sample.
SSL Configuration
Custom Socket Factory
84.11. Spring Boot Auto-Configuration 링크 복사링크가 클립보드에 복사되었습니다!
The component supports 3 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
| camel.component.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.ldap.enabled | Whether to enable auto configuration of the ldap component. This is enabled by default. | Boolean | |
| camel.component.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 |