This module offers you the possibilty to inject a leightweight LDAP search functionality to your application.
First create a property file (like "ldap.properties") where you store your access information to connect the LDAP server.
Not only a properties based configuration is possible. Please read the "Configuration" section in the core module for further information.
#
# choose the LDAP version, maybe 2 or 3
# default = 3
#
ldap.version = 3
#
# set the hostname/ip of the LDAP server
#
ldap.hostname = x500.bund.de
#
# set the port of the LDAP server
# default = 389
#
ldap.hostport = 389
#
# if the LDAP server require to authenticate
# insert your auth DN here
# default is empty
#
ldap.authdn =
#
# if the LDAP server require to authenticate
# insert your auth password here
# default is empty
#
ldap.authpwd =
Next, let the SearchService know, where to find the configuration file. Add to your Application Module (Tapestry IOC) the contribution:
public static void contributeSimpleLdapSearcherService(ClassFactory classFactory,
MappedConfiguration<String, Resource> configuration)
{
Resource resource = new ClasspathResource(classFactory.getClassLoader(), "ldap.properties");
configuration.add(SearcherService.CONFIG_KEY, resource);
}
Now your are able to use the LDAP search service. Here a short example:
String baseDN = "o=Bund,c=DE";
String filter = "(cn=Bund*)";
String attribute = "mail";
List<LDAPEntry> matches = searcherService.search(baseDN, filter, attribute);
for (LDAPEntry match : matches)
{
Enumeration values = match.getAttribute(attribute).getStringValues();
while (values.hasMoreElements())
{
String value = (String) values.nextElement();
System.err.println(String.format("value of attribute '%s': %s", attribute, value));
}
}