|
LDAP has been edited by Christopher Hunt (May 05, 2009). Change summary: Enhanced to include more information on how to use the LDAP component. Also re-wrote the examples in support of using a context that uses a prototype scoped object. LDAP ComponentThe ldap: component allows you to perform searches in LDAP servers using filters as the message payload. URI formatldap:ldapServerBean?options This component only supports producer, meaning that you can not use routes with this component in the from type.
ResultThe result is returned in the out body as a ArrayList<javax.naming.directory.SearchResult> list object with the result. DirContextThe ldapServerBean portion of the URI refers to a DirContext Given an ldapServerBean of "ldapserver", a bean may be declared via Spring as: <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 above 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 i.e. you just need to look an entry up, specify a wildcard filter _expression_. In the case where there is a common name use a filter _expression_ like: (cn=*) See Also |
Unsubscribe or edit your notifications preferences
