LDAPPage edited by Fintan BoltonCopy edits and some rewordingLDAP ComponentThe ldap component allows you to perform searches in LDAP servers using filters as the message payload. URI formatldap: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.
ResultThe result is returned in the Out body as a ArrayList<javax.naming.directory.SearchResult> object. DirContextThe URI, ldap:ldapserver, references a Spring bean with the ID, ldapserver. The ldapserver bean may be defined as follows: <bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype"> <constructor-arg> <props> <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop> <prop key="java.naming.provider.url">ldap://localhost:10389</prop> <prop key="java.naming.security.authentication">none</prop> </props> </constructor-arg> </bean> The preceding example declares a regular Sun based LDAP DirContext that connects anonymously to a locally hosted LDAP server.
SamplesFollowing 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
.getContext().createProducerTemplate();
Collection<?> results = (Collection<?>) (template
.sendBody(
"ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system",
"(member=uid=huntc,ou=users,ou=system)"));
if (results.size() > 0) {
// Extract what we need from the device's profile
Iterator<?> resultIter = results.iterator();
SearchResult searchResult = (SearchResult) resultIter
.next();
Attributes attributes = searchResult
.getAttributes();
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: (cn=*) See Also
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > LDAP confluence
- [CONF] Apache Camel > LDAP confluence
