luczak (16) [Avatar] Offline
#1
Hi there,

I was wondering if there will be any chapter on accessing LDAP directory? If not, could you show me a simple example on how to properly use this component (preferably in pure Java, without Spring). Also, do you know how to login to LDAP using Camel? As far as I know LDAP's URI format only supports base and scope as options. Thanks in advance
davsclaus (321) [Avatar] Offline
#2
Re: accessing LDAP
the camel-ldap component will not be covered in the book.

You can check the source code for the component and see the unit tests to see a Java based example.
https://svn.apache.org/repos/asf/camel/trunk/components/camel-ldap/src/test/
luczak (16) [Avatar] Offline
#3
Re: accessing LDAP
Thanks for the files. I'm still not sure if its possible to bind to LDAP using some DN [Distinguished Name] (since I'm not using anonymous access)? If it's possible, could you paste a short howto-snippet?
davsclaus (321) [Avatar] Offline
#4
Re: accessing LDAP
I did now write the camel-ldap component.

In the past I have used the powerful Spring LDAP template framework
http://www.springsource.org/ldap

It can bind using credentials.

I will create a JIRA ticket at Apache Camel to look into how to bind using a DN.
davsclaus (321) [Avatar] Offline
#5
Re: accessing LDAP
luczak (16) [Avatar] Offline
#6
Re: accessing LDAP
great, thanks!
jwagenleitner (1) [Avatar] Offline
#7
Re: accessing LDAP
The following works for me in order to bind using credentials using 2.3.0 and in 2.5-SNAPSHOT

---
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
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);
context.addRoutes(
new RouteBuilder() {
public void configure() throws Exception {
from("direct:start").to("ldap:myldap?base=ou=test");
}
}
);
context.start();

ProducerTemplate template = context.createProducerTemplate();

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

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

System.out.println(out.getOut().getBody());

context.stop();
---
442968 (1) [Avatar] Offline
#8
Any examples to do create/delete operations in LDAP using apache camel?