Sunday, 7 September 2014

Spring LDAP + Apache DS

Software/tools required:

1. LDAP server : Apache Directory Studio 2.0.0
2. IDE :Eclipse Kepler
3. JDK 1.6
4. Spring LDAP core 2.0.2 release
5. MAVEN 4.0.0


Basics of LDAP:

LDAP stands for Light weight Directory Access protocol for accessing directory servers and LDAP server is mainly used by the most of the organisation to maintain the company information like employee details with proper hierarchy.This is very simple example how basically LDAP can be used.

There are different vendors available in market for LDAP server for example Microsoft Active Directory, Novel ,OpenDS and Apache DS etc.

Apache DS :

Installation & Server configuration:

1. Download Apache directory Studio from link  http://directory.apache.org/studio/
2. Install the server
3. Fallow the link for server configuration: http://directory.apache.org/studio/users- guide/apacheds_configuration/configuration_editor_1.5.0_general.html
4. Now start the server. Server should be up and listening to the port : 10389

Connection Configuration:


Adding/Feeding  Data to the server:

Feed the data using UI or upload the data by upload option. Before uploading prepare the data as given below:
https://directory.apache.org/apacheds/basic-ug/2.1.1-adding-entries.html

File format shall be LDIF. LDIF stands for LDAP Data Interchange format.
Example:

# File prashant_savadi.ldif
dn: ou=people,o=sevenSeas
objectclass: organizationalUnit
objectclass: top
ou: people

dn: cn=Prashant Savadi,ou=people,o=sevenSeas
objectclass: inetOrgPerson
objectclass: organizationalPerson
objectclass: person
objectclass: top
cn: Prashant Savadi
description: A pirate captain and Peter Pan's nemesis
sn: Savadi
mail: gsprashant@xyz.com
userpassword: abcdef

 MAVEN 4.0.0:

Add below maven dependency to the POM.xml file.

<dependency>
 <groupId>org.springframework.ldap</groupId>
 <artifactId>spring-ldap-core</artifactId>
 <version>2.0.2.RELEASE</version>
</dependency>

At a minimum, to use Spring LDAP you need:
  • spring-ldap-core (the Spring LDAP library)
  • spring-core (miscellaneous utility classes used internally by the framework)
  • spring-beans (contains interfaces and classes for manipulating Java beans)
  • spring-data-commons (base infrastructure for repository suppport, etc.)
  • slf4j (a simple logging facade, used internally)
  • spring-context

 Spring LDAP:

Before Spring LDAP API Java Naming and Directory Interfaced (JNDI) was used to interact with LDAP based applications.How Spring JDBC simplified the dabase base access in java similary Spring LDAP made easy interaction with LDAP applications.
Pros:
1. No exception handling.
2. No resource handling (opening/closing resource connection).
3. No plumbing code to even achive simple task.

Spring LDAP is designed to simplify LDAP programming in Java. Some of the features provided by the library are:
  • JdbcTemplate-style template simplifications to LDAP programming(LDAPTemplate).
  • JPA/Hibernate-style annotation-based object/directory mapping.
  • Spring Data repository support, including support for QueryDSL.
  • Utilities to simplify building LDAP queries and distinguished names.
  • Proper LDAP connection pooling.
  • Client-side LDAP compensating transaction support.
Below link shall help you understand the SpringLdap API:

http://docs.spring.io/autorepo/docs/spring-ldap/2.0.2.RELEASE/reference/#introduction








No comments:

Post a Comment