11
Home Prometric Centers Contact Us Advertise TechBreaths Subscribe: Posts | Comments JavaBeat Java / J2EE » Web Frameworks » XML Technologies » Tools & IDEs » RIA » Web Servers » Internet » Scripting » Introduction to Spring LDAP May 5, 2011 Spring MVC « » Spring LDAP Introduction In this article Spring LDAP which provides a simplified wrapper framework around LDAP implementations is covered in detail. This article assumes that the reader has a basic understanding on Spring framework and LDAP directory server. The first section of the article covers the various operations that can be performed on LDAP. Support for parsing externally stored LDAP data is also covered with the help of LDIF data. The ODM Manager APIs for mapping LDAP objects directly to java objects have also been explored in this article. If you are beginner in learning spring framework, please read Introduction to Spring Framework. Download Spring LDAP Sample Code Source Code for Spring LDAP LDAP operations In this section, we will illustrate the usage of various operations that can be performed on LDAP directory using Spring. The examples given here are tested with Apache Directory server, however the code should work with any LDAP implementations. The operations that will be getting covered in the following sections are, Searching Adding objects Removing objects Modifying objects Searching objects For illustrating search operations in LDAP, we will create objects under the node system/users. We will be creating objects of type person in this node. Note that for having an object oriented access for the person type, we will create a java class User that maps to it. Have a look at the declaration of this class. 1 2 package net.javabeat.articles.spring.ldap; Ads by Google Hosting Java Java Download Java Java Tutorial Nearshore Software Entwicklung, Qualittssicherung, Support , AMS etc. in Deutsch www.ebsromania.com AMQP meets JMS AMQP 1.0 fully integrated with JMS, free AMQP 1.0 Client! www.swiftmq.com Sind Sie der Java Hirsch? Gesucht: talentierte SW Entwickler in agilem/innovativem Umfeld. www.baloise.com/karriere Adaxes: AD im Griff benutzerfreundliche Verwaltung von Active Directory www.syntlogo.de Introduction to Spring LDAP http://www.javabeat.net/2011/05/introduction-to-spring-ldap/all/1/ 1 von 11 27.05.2012 04:33

Introduction to Spring LDAP__tmp5129f01b

Embed Size (px)

Citation preview

Home

Prometric Centers

Contact Us

Advertise

TechBreaths

Subscribe Posts | Comments

JavaBeat

Java J2EE raquo

Web Frameworks raquo

XML Technologies raquo

Tools amp IDEs raquo

RIA raquo

Web Servers raquo

Internet raquo

Scripting raquo

Introduction to Spring LDAPMay 5 2011

Spring MVC

laquo raquo

Spring LDAP

Introduction

In this article Spring LDAP which provides a simplified wrapper framework around LDAP implementations is

covered in detail This article assumes that the reader has a basic understanding on Spring framework and

LDAP directory server The first section of the article covers the various operations that can be performed on

LDAP Support for parsing externally stored LDAP data is also covered with the help of LDIF data The ODM

Manager APIs for mapping LDAP objects directly to java objects have also been explored in this article If

you are beginner in learning spring framework please read Introduction to Spring Framework

Download Spring LDAP Sample Code

Source Code for Spring LDAP

LDAP operations

In this section we will illustrate the usage of various operations that can be performed on LDAP directory using Spring The examples given here are tested with

Apache Directory server however the code should work with any LDAP implementations The operations that will be getting covered in the following sections are

Searching

Adding objects

Removing objects

Modifying objects

Searching objects

For illustrating search operations in LDAP we will create objects under the node systemusers We will be creating objects of type person in this node Note that for

having an object oriented access for the person type we will create a java class User that maps to it Have a look at the declaration of this class

12

package netjavabeatarticlesspringldap

Ads by Google Hosting Java Java Download Java Java Tutorial

Nearshore Software

Entwicklung Qualitaumltssicherung Support AMS

etc in Deutschwwwebsromaniacom

AMQP meets JMS

AMQP 10 fully integrated with JMS free AMQP10 Clientwwwswiftmqcom

Sind Sie der Java Hirsch

Gesucht talentierte SW Entwickler inagileminnovativem Umfeldwwwbaloisecomkarriere

Adaxes AD im Griff

benutzerfreundliche Verwaltung von ActiveDirectorywwwsyntlogode

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

1 von 11 27052012 0433

id23894359 pdfMachine by Broadgun Software - a great PDF writer - a great PDF creator - httpwwwpdfmachinecom httpwwwbroadguncom

3456789101112131415161718192021222324252627

public class User

private String commonNameprivate String telephone

public String getCommonName()

return commonName

public void setCommonName(String commonName)

thiscommonName = commonName

public String getTelephone()

return telephone

public void setTelephone(String telephone)

thistelephone = telephone

public String toString()

return commonName + - + telephone

The class definition is pretty simple It defines two simple properties commonName and telephone The search class that makes use of Spring libraries is given below

Go through the following code carefully

123456789101112131415161718192021222324252627282930313233343536373839

package netjavabeatarticlesspringldapoperations import javautilHashSetimport javautilSet import netjavabeatarticlesspringldapUserimport netjavabeatarticlesspringldapUserAttributesMapper import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreLdapTemplate public class SimpleSearch

private LdapTemplate ldapTemplate

SuppressWarnings(unchecked)public SetltUsergt getAllUsers()

UserAttributesMapper mapper = new UserAttributesMapper()return new HashSetltUsergt(

ldapTemplatesearch(ou=usersou=system (objectClass=person) mapper))

public void setLdapTemplate(LdapTemplate ldapTemplate)

thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Note that the class defines an instance of LdapTemplate class This template class follows the template pattern and is very similar to the existing template classes like

JdbcTemplate JmsTemplate etc Performing operations on the LDAP directory becomes simple with this template class Note that before using this template class it

has to be configured with various properties such as username password and the url of the directory server We will see the configuration in the later section of this

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

2 von 11 27052012 0433

article

Carefully examine the method getAllUsers() This method calls the search() method defined on LdapTemplate for searching objects in the directory server Note that this

method takes two parameters the first being the base domain name and the second one defines the filter In our case since the objects are located under the node

systemusers the base domain name happens to be ou=usersou=system here ou stands for organizational unit For the second parameter we have used the value

objectClass=person which means that we want to search objects of type person Note that since LDAP can store objects of any type the return objects have to be

mapped to some implementation representing a custom model and for the same purpose we have used the customized implementation of AttributesMapper

implementation which is UserAttributesMapper

1234567891011121314151617181920212223242526

package netjavabeatarticlesspringldap import javaxnamingNamingExceptionimport javaxnamingdirectoryAttributes import orgspringframeworkldapcoreAttributesMapper public class UserAttributesMapper implements AttributesMapper

Overridepublic User mapFromAttributes(Attributes attributes) throws NamingException

User userObject = new User()

String commonName = (String)attributesget(cn)get()userObjectsetCommonName(commonName)if (attributesget(telephoneNumber) == null)

Systemoutprintln(Telephone is null for + commonName)else

String telephone = attributesget(telephoneNumber)get()toString()userObjectsetTelephone(telephone)

return userObject

Note that in the above class the method mapFromAttributes() is overridden which takes the input as Attributes which represents a general purpose attribute collection

The implementation creates a customized flavor of model implementation by gathering the relevant attributes and then constructs the object accordingly

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldapoperations import javautilHashSetimport javautilSet import netjavabeatarticlesspringldapUserimport netjavabeatarticlesspringldapUserAttributesMapper import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreLdapTemplateimport orgspringframeworkldapfilterAndFilterimport orgspringframeworkldapfilterEqualsFilter public class DynamicSearch

private LdapTemplate ldapTemplate

SuppressWarnings(unchecked)public SetltUsergt getAllUsers(String surName)

UserAttributesMapper mapper = new UserAttributesMapper()

AndFilter filterObject = new AndFilter()filterObjectand(new EqualsFilter(objectClass person))filterObjectand(new EqualsFilter(sn surName))

return new HashSetltUsergt(

ldapTemplatesearch(ou=usersou=system filterObjectencode() mapper))

public void setLdapTemplate(LdapTemplate ldapTemplate)

thisldapTemplate = ldapTemplate

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

3 von 11 27052012 0433

3435363738394041424344454647

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

DynamicSearch dynamicSearch = new DynamicSearch()dynamicSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user dynamicSearchgetAllUsers(David))

Systemoutprintln(user)

A variation of searching objects dynamically in the directory server is given above In the above code the obvious variation is the search filter being dynamically

constructed using Filter APIs We have dynamically constructed search parameters objectClass sn and have anded them using AndFilter Rest of the code in the

above section remains the same

Adding objects

In this section we will see how to add objects in the LDAP directory For adding objects the bind() defined on LdapTemplate can be used Note that the bind()

methods takes the distinguished name and the list of attributes as parameters Note that the unique distinguished name represents the combination of base name and

the common name The base name is ou=usersou=system in our case and the common name will come as user input

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributesimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryBasicAttributes import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class AddUser

private LdapTemplate ldapTemplate

public void add(String commonName String surName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attributes userAttributes = new BasicAttributes()userAttributesput(sn surName)userAttributesput(telephoneNumber telephone)

BasicAttribute classAttribute = new BasicAttribute(objectclass)classAttributeadd(top)classAttributeadd(person)userAttributesput(classAttribute)

ldapTemplatebind(distinguisedName null userAttributes)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

AddUser addPerson = new AddUser()addPersonsetLdapTemplate(ldapTemplate)addPersonadd(New User User 12345)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

4 von 11 27052012 0433

4849505152535455

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

For adding simple attributes we can use the put() method defined on the BasicAttributes class The attribute objectClass is a multi-valued attribute By default any

object defined in LDAP will have the objectClass set to top Hence in our case the object type for the person objects will be top person Hence for adding a

multi-valued attribute such as objectClass the attribute values have to be packaged as a BasicAttribute object and then have to be added to the main attribute

Removing objects

For removing objects from the directory server the method unbind() can be used Because a distinguished name represents a unique name in the directory server the

unbind() method takes an instance of distinguished name as an argument

123456789101112131415161718192021222324252627282930313233343536373839404142

package netjavabeatarticlesspringldapoperations import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class RemoveUser

private LdapTemplate ldapTemplate

public void remove(String commonName)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

ldapTemplateunbind(distinguisedName)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

RemoveUser removePerson = new RemoveUser()removePersonsetLdapTemplate(ldapTemplate)removePersonremove(New User)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

The above code tries to remove a person and then queries for the list of person objects in the directory server

Modifying objects

Existing objects can be modified by invoking the method modifyAttributes() defined on the LdapTemplate class Note that the arguments to this method are the

distinguished name and the list of attributes to be modified

Online Dashboard software

Online reporting solution to manage KPIs in web based dashboardswwwbittle-solutionscom

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

5 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

3456789101112131415161718192021222324252627

public class User

private String commonNameprivate String telephone

public String getCommonName()

return commonName

public void setCommonName(String commonName)

thiscommonName = commonName

public String getTelephone()

return telephone

public void setTelephone(String telephone)

thistelephone = telephone

public String toString()

return commonName + - + telephone

The class definition is pretty simple It defines two simple properties commonName and telephone The search class that makes use of Spring libraries is given below

Go through the following code carefully

123456789101112131415161718192021222324252627282930313233343536373839

package netjavabeatarticlesspringldapoperations import javautilHashSetimport javautilSet import netjavabeatarticlesspringldapUserimport netjavabeatarticlesspringldapUserAttributesMapper import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreLdapTemplate public class SimpleSearch

private LdapTemplate ldapTemplate

SuppressWarnings(unchecked)public SetltUsergt getAllUsers()

UserAttributesMapper mapper = new UserAttributesMapper()return new HashSetltUsergt(

ldapTemplatesearch(ou=usersou=system (objectClass=person) mapper))

public void setLdapTemplate(LdapTemplate ldapTemplate)

thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Note that the class defines an instance of LdapTemplate class This template class follows the template pattern and is very similar to the existing template classes like

JdbcTemplate JmsTemplate etc Performing operations on the LDAP directory becomes simple with this template class Note that before using this template class it

has to be configured with various properties such as username password and the url of the directory server We will see the configuration in the later section of this

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

2 von 11 27052012 0433

article

Carefully examine the method getAllUsers() This method calls the search() method defined on LdapTemplate for searching objects in the directory server Note that this

method takes two parameters the first being the base domain name and the second one defines the filter In our case since the objects are located under the node

systemusers the base domain name happens to be ou=usersou=system here ou stands for organizational unit For the second parameter we have used the value

objectClass=person which means that we want to search objects of type person Note that since LDAP can store objects of any type the return objects have to be

mapped to some implementation representing a custom model and for the same purpose we have used the customized implementation of AttributesMapper

implementation which is UserAttributesMapper

1234567891011121314151617181920212223242526

package netjavabeatarticlesspringldap import javaxnamingNamingExceptionimport javaxnamingdirectoryAttributes import orgspringframeworkldapcoreAttributesMapper public class UserAttributesMapper implements AttributesMapper

Overridepublic User mapFromAttributes(Attributes attributes) throws NamingException

User userObject = new User()

String commonName = (String)attributesget(cn)get()userObjectsetCommonName(commonName)if (attributesget(telephoneNumber) == null)

Systemoutprintln(Telephone is null for + commonName)else

String telephone = attributesget(telephoneNumber)get()toString()userObjectsetTelephone(telephone)

return userObject

Note that in the above class the method mapFromAttributes() is overridden which takes the input as Attributes which represents a general purpose attribute collection

The implementation creates a customized flavor of model implementation by gathering the relevant attributes and then constructs the object accordingly

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldapoperations import javautilHashSetimport javautilSet import netjavabeatarticlesspringldapUserimport netjavabeatarticlesspringldapUserAttributesMapper import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreLdapTemplateimport orgspringframeworkldapfilterAndFilterimport orgspringframeworkldapfilterEqualsFilter public class DynamicSearch

private LdapTemplate ldapTemplate

SuppressWarnings(unchecked)public SetltUsergt getAllUsers(String surName)

UserAttributesMapper mapper = new UserAttributesMapper()

AndFilter filterObject = new AndFilter()filterObjectand(new EqualsFilter(objectClass person))filterObjectand(new EqualsFilter(sn surName))

return new HashSetltUsergt(

ldapTemplatesearch(ou=usersou=system filterObjectencode() mapper))

public void setLdapTemplate(LdapTemplate ldapTemplate)

thisldapTemplate = ldapTemplate

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

3 von 11 27052012 0433

3435363738394041424344454647

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

DynamicSearch dynamicSearch = new DynamicSearch()dynamicSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user dynamicSearchgetAllUsers(David))

Systemoutprintln(user)

A variation of searching objects dynamically in the directory server is given above In the above code the obvious variation is the search filter being dynamically

constructed using Filter APIs We have dynamically constructed search parameters objectClass sn and have anded them using AndFilter Rest of the code in the

above section remains the same

Adding objects

In this section we will see how to add objects in the LDAP directory For adding objects the bind() defined on LdapTemplate can be used Note that the bind()

methods takes the distinguished name and the list of attributes as parameters Note that the unique distinguished name represents the combination of base name and

the common name The base name is ou=usersou=system in our case and the common name will come as user input

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributesimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryBasicAttributes import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class AddUser

private LdapTemplate ldapTemplate

public void add(String commonName String surName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attributes userAttributes = new BasicAttributes()userAttributesput(sn surName)userAttributesput(telephoneNumber telephone)

BasicAttribute classAttribute = new BasicAttribute(objectclass)classAttributeadd(top)classAttributeadd(person)userAttributesput(classAttribute)

ldapTemplatebind(distinguisedName null userAttributes)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

AddUser addPerson = new AddUser()addPersonsetLdapTemplate(ldapTemplate)addPersonadd(New User User 12345)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

4 von 11 27052012 0433

4849505152535455

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

For adding simple attributes we can use the put() method defined on the BasicAttributes class The attribute objectClass is a multi-valued attribute By default any

object defined in LDAP will have the objectClass set to top Hence in our case the object type for the person objects will be top person Hence for adding a

multi-valued attribute such as objectClass the attribute values have to be packaged as a BasicAttribute object and then have to be added to the main attribute

Removing objects

For removing objects from the directory server the method unbind() can be used Because a distinguished name represents a unique name in the directory server the

unbind() method takes an instance of distinguished name as an argument

123456789101112131415161718192021222324252627282930313233343536373839404142

package netjavabeatarticlesspringldapoperations import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class RemoveUser

private LdapTemplate ldapTemplate

public void remove(String commonName)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

ldapTemplateunbind(distinguisedName)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

RemoveUser removePerson = new RemoveUser()removePersonsetLdapTemplate(ldapTemplate)removePersonremove(New User)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

The above code tries to remove a person and then queries for the list of person objects in the directory server

Modifying objects

Existing objects can be modified by invoking the method modifyAttributes() defined on the LdapTemplate class Note that the arguments to this method are the

distinguished name and the list of attributes to be modified

Online Dashboard software

Online reporting solution to manage KPIs in web based dashboardswwwbittle-solutionscom

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

5 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

article

Carefully examine the method getAllUsers() This method calls the search() method defined on LdapTemplate for searching objects in the directory server Note that this

method takes two parameters the first being the base domain name and the second one defines the filter In our case since the objects are located under the node

systemusers the base domain name happens to be ou=usersou=system here ou stands for organizational unit For the second parameter we have used the value

objectClass=person which means that we want to search objects of type person Note that since LDAP can store objects of any type the return objects have to be

mapped to some implementation representing a custom model and for the same purpose we have used the customized implementation of AttributesMapper

implementation which is UserAttributesMapper

1234567891011121314151617181920212223242526

package netjavabeatarticlesspringldap import javaxnamingNamingExceptionimport javaxnamingdirectoryAttributes import orgspringframeworkldapcoreAttributesMapper public class UserAttributesMapper implements AttributesMapper

Overridepublic User mapFromAttributes(Attributes attributes) throws NamingException

User userObject = new User()

String commonName = (String)attributesget(cn)get()userObjectsetCommonName(commonName)if (attributesget(telephoneNumber) == null)

Systemoutprintln(Telephone is null for + commonName)else

String telephone = attributesget(telephoneNumber)get()toString()userObjectsetTelephone(telephone)

return userObject

Note that in the above class the method mapFromAttributes() is overridden which takes the input as Attributes which represents a general purpose attribute collection

The implementation creates a customized flavor of model implementation by gathering the relevant attributes and then constructs the object accordingly

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldapoperations import javautilHashSetimport javautilSet import netjavabeatarticlesspringldapUserimport netjavabeatarticlesspringldapUserAttributesMapper import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreLdapTemplateimport orgspringframeworkldapfilterAndFilterimport orgspringframeworkldapfilterEqualsFilter public class DynamicSearch

private LdapTemplate ldapTemplate

SuppressWarnings(unchecked)public SetltUsergt getAllUsers(String surName)

UserAttributesMapper mapper = new UserAttributesMapper()

AndFilter filterObject = new AndFilter()filterObjectand(new EqualsFilter(objectClass person))filterObjectand(new EqualsFilter(sn surName))

return new HashSetltUsergt(

ldapTemplatesearch(ou=usersou=system filterObjectencode() mapper))

public void setLdapTemplate(LdapTemplate ldapTemplate)

thisldapTemplate = ldapTemplate

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

3 von 11 27052012 0433

3435363738394041424344454647

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

DynamicSearch dynamicSearch = new DynamicSearch()dynamicSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user dynamicSearchgetAllUsers(David))

Systemoutprintln(user)

A variation of searching objects dynamically in the directory server is given above In the above code the obvious variation is the search filter being dynamically

constructed using Filter APIs We have dynamically constructed search parameters objectClass sn and have anded them using AndFilter Rest of the code in the

above section remains the same

Adding objects

In this section we will see how to add objects in the LDAP directory For adding objects the bind() defined on LdapTemplate can be used Note that the bind()

methods takes the distinguished name and the list of attributes as parameters Note that the unique distinguished name represents the combination of base name and

the common name The base name is ou=usersou=system in our case and the common name will come as user input

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributesimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryBasicAttributes import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class AddUser

private LdapTemplate ldapTemplate

public void add(String commonName String surName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attributes userAttributes = new BasicAttributes()userAttributesput(sn surName)userAttributesput(telephoneNumber telephone)

BasicAttribute classAttribute = new BasicAttribute(objectclass)classAttributeadd(top)classAttributeadd(person)userAttributesput(classAttribute)

ldapTemplatebind(distinguisedName null userAttributes)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

AddUser addPerson = new AddUser()addPersonsetLdapTemplate(ldapTemplate)addPersonadd(New User User 12345)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

4 von 11 27052012 0433

4849505152535455

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

For adding simple attributes we can use the put() method defined on the BasicAttributes class The attribute objectClass is a multi-valued attribute By default any

object defined in LDAP will have the objectClass set to top Hence in our case the object type for the person objects will be top person Hence for adding a

multi-valued attribute such as objectClass the attribute values have to be packaged as a BasicAttribute object and then have to be added to the main attribute

Removing objects

For removing objects from the directory server the method unbind() can be used Because a distinguished name represents a unique name in the directory server the

unbind() method takes an instance of distinguished name as an argument

123456789101112131415161718192021222324252627282930313233343536373839404142

package netjavabeatarticlesspringldapoperations import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class RemoveUser

private LdapTemplate ldapTemplate

public void remove(String commonName)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

ldapTemplateunbind(distinguisedName)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

RemoveUser removePerson = new RemoveUser()removePersonsetLdapTemplate(ldapTemplate)removePersonremove(New User)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

The above code tries to remove a person and then queries for the list of person objects in the directory server

Modifying objects

Existing objects can be modified by invoking the method modifyAttributes() defined on the LdapTemplate class Note that the arguments to this method are the

distinguished name and the list of attributes to be modified

Online Dashboard software

Online reporting solution to manage KPIs in web based dashboardswwwbittle-solutionscom

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

5 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

3435363738394041424344454647

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)

DynamicSearch dynamicSearch = new DynamicSearch()dynamicSearchsetLdapTemplate(contextgetBean(ldapTemplate LdapTemplateclass))for (User user dynamicSearchgetAllUsers(David))

Systemoutprintln(user)

A variation of searching objects dynamically in the directory server is given above In the above code the obvious variation is the search filter being dynamically

constructed using Filter APIs We have dynamically constructed search parameters objectClass sn and have anded them using AndFilter Rest of the code in the

above section remains the same

Adding objects

In this section we will see how to add objects in the LDAP directory For adding objects the bind() defined on LdapTemplate can be used Note that the bind()

methods takes the distinguished name and the list of attributes as parameters Note that the unique distinguished name represents the combination of base name and

the common name The base name is ou=usersou=system in our case and the common name will come as user input

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributesimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryBasicAttributes import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class AddUser

private LdapTemplate ldapTemplate

public void add(String commonName String surName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attributes userAttributes = new BasicAttributes()userAttributesput(sn surName)userAttributesput(telephoneNumber telephone)

BasicAttribute classAttribute = new BasicAttribute(objectclass)classAttributeadd(top)classAttributeadd(person)userAttributesput(classAttribute)

ldapTemplatebind(distinguisedName null userAttributes)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

AddUser addPerson = new AddUser()addPersonsetLdapTemplate(ldapTemplate)addPersonadd(New User User 12345)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

4 von 11 27052012 0433

4849505152535455

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

For adding simple attributes we can use the put() method defined on the BasicAttributes class The attribute objectClass is a multi-valued attribute By default any

object defined in LDAP will have the objectClass set to top Hence in our case the object type for the person objects will be top person Hence for adding a

multi-valued attribute such as objectClass the attribute values have to be packaged as a BasicAttribute object and then have to be added to the main attribute

Removing objects

For removing objects from the directory server the method unbind() can be used Because a distinguished name represents a unique name in the directory server the

unbind() method takes an instance of distinguished name as an argument

123456789101112131415161718192021222324252627282930313233343536373839404142

package netjavabeatarticlesspringldapoperations import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class RemoveUser

private LdapTemplate ldapTemplate

public void remove(String commonName)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

ldapTemplateunbind(distinguisedName)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

RemoveUser removePerson = new RemoveUser()removePersonsetLdapTemplate(ldapTemplate)removePersonremove(New User)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

The above code tries to remove a person and then queries for the list of person objects in the directory server

Modifying objects

Existing objects can be modified by invoking the method modifyAttributes() defined on the LdapTemplate class Note that the arguments to this method are the

distinguished name and the list of attributes to be modified

Online Dashboard software

Online reporting solution to manage KPIs in web based dashboardswwwbittle-solutionscom

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

5 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

4849505152535455

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

For adding simple attributes we can use the put() method defined on the BasicAttributes class The attribute objectClass is a multi-valued attribute By default any

object defined in LDAP will have the objectClass set to top Hence in our case the object type for the person objects will be top person Hence for adding a

multi-valued attribute such as objectClass the attribute values have to be packaged as a BasicAttribute object and then have to be added to the main attribute

Removing objects

For removing objects from the directory server the method unbind() can be used Because a distinguished name represents a unique name in the directory server the

unbind() method takes an instance of distinguished name as an argument

123456789101112131415161718192021222324252627282930313233343536373839404142

package netjavabeatarticlesspringldapoperations import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class RemoveUser

private LdapTemplate ldapTemplate

public void remove(String commonName)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

ldapTemplateunbind(distinguisedName)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

RemoveUser removePerson = new RemoveUser()removePersonsetLdapTemplate(ldapTemplate)removePersonremove(New User)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

The above code tries to remove a person and then queries for the list of person objects in the directory server

Modifying objects

Existing objects can be modified by invoking the method modifyAttributes() defined on the LdapTemplate class Note that the arguments to this method are the

distinguished name and the list of attributes to be modified

Online Dashboard software

Online reporting solution to manage KPIs in web based dashboardswwwbittle-solutionscom

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

5 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

package netjavabeatarticlesspringldapoperations import javaxnamingdirectoryAttributeimport javaxnamingdirectoryBasicAttributeimport javaxnamingdirectoryDirContextimport javaxnamingdirectoryModificationItem import netjavabeatarticlesspringldapUser import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapcoreLdapTemplate public class ModifyUser

private LdapTemplate ldapTemplate

public void modify(String commonName String telephone)

String baseDn = ou=usersou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn commonName)

Attribute telephoneAttribute = new BasicAttribute(telephoneNumber telephone)ModificationItem telephoneItem = new ModificationItem(

DirContextREPLACE_ATTRIBUTE telephoneAttribute)ldapTemplatemodifyAttributes(distinguisedName new ModificationItem[]telephoneItem)

public void setLdapTemplate(LdapTemplate ldapTemplate)thisldapTemplate = ldapTemplate

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(searchxml)LdapTemplate ldapTemplate = contextgetBean(ldapTemplate LdapTemplateclass)

ModifyUser modifyPerson = new ModifyUser()modifyPersonsetLdapTemplate(ldapTemplate)modifyPersonmodify(Steve David 9999999)

SimpleSearch simpleSearch = new SimpleSearch()simpleSearchsetLdapTemplate(ldapTemplate)for (User user simpleSearchgetAllUsers())

Systemoutprintln(user)

Each attribute to be modified must be represented through a ModificationItem object which specifies the flag whether the value of the existing attribute has to be

replaced or a new attribute can be created of the attribute if it doesnt exist In the above sample for modifying the telephoneNumber attribute we have used the

REPLACE_ATTRIBUTE flag which will replace the existing attribute value for the person object

12345678910111213141516

ltxml version=10 encoding=UTF-8gtltbeans xmlns=httpwwwspringframeworkorgschemabeans xmlnsxsi=httpwwww3org2001XMLSchema-instance xmlnsutil=httpwwwspringframeworkorgschemautil xsischemaLocation=httpwwwspringframeworkorgschemabeans httpwwwspringframeworkorgschemabeansspring-beans-25xsd httpwwwspringframeworkorgschemautil httpwwwspringframeworkorgschemautilspring-util-25xsdgt ltbean id=ldapTemplate class=orgspringframeworkldapcoreLdapTemplategt ltproperty name=contextSource ref=contextSource gt ltbeangt ltbean id=contextSource class=orgspringframeworkldapcoresupportLdapContextSourcegt ltproperty name=url value=ldaplocalhost10389 gt ltproperty name=userDn value=uid=adminou=system gt ltproperty name=password value=secret gt ltproperty name=pooled value=false gt

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

6 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

171819

ltbeangt ltbeansgt

The Spring configuration file for configuring LdapTemplate instance is given below Note that the property contextSource has to be populated The contextSource

property is of type LdapContextSource and the mandatory properties userDn password and url have to be specified

~~~~~~~~~~~~

LDIF Parser

LDIF stands for LDAP Directory Interchange Format and it represents the way of storing LDAP objects information in a flat file so that they can be easily transported to

different machines hosting LDAP servers Spring LDAP framework provides support for parsing LDAP objects available in a text file and this section illustrates the

usage of these APIs

Download Spring LDAP Sample Code

Source Code for Spring LDAP

A simple text file containing sample LDAP object information in a text file is given below

12345678910111213

dn ou=usersou=systemsn SN-1telephoneNumber 33333objectClass personobjectClass topcn CN-1 dn ou=usersou=systemsn SN-2telephoneNumber 77777objectClass personobjectClass topcn CN-2

Now we will see how to make use of LDIF parser The program constructs an instance of LdifParser object and then calls the hasMoreRecords() and getRecord() for

reading all attribute information from the text file A call to getRecord() will retrieve a single record information from the file The method getAll() will return all the attribute

names for the record Since there is a possibility for an attribute to contain multiple values we again call getAll() method to collect the attribute values

123456789101112131415161718192021222324252627282930313233

package netjavabeatarticlesspringldif import javaxnamingNamingEnumerationimport javaxnamingdirectoryAttributeimport javaxnamingdirectoryAttributes import orgspringframeworkcoreioFileSystemResourceimport orgspringframeworkldapldifparserLdifParserimport orgspringframeworkldapldifparserParser public class LdifTest

public static void main(String[] args) throws Exception

Parser parser = new LdifParser()

parsersetResource(new FileSystemResource(binusersldif))parseropen()

while (parserhasMoreRecords())

Attributes attributes = parsergetRecord()String personDetails = getPersonDetails(attributes)Systemoutprintln(personDetails)

private static String getPersonDetails(Attributes attributes) throws Exception

StringBuilder personDetails = new StringBuilder()personDetailsappend()

NamingEnumerationlt extends Attributegt attributeNames = attributesgetAll()

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

7 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

343536373839404142434445464748495051

while (attributeNameshasMoreElements())

Attribute attribute = attributeNamesnext()personDetailsappend([ + attributegetID())

SuppressWarnings(unchecked)NamingEnumerationltStringgt attributeValues = (NamingEnumerationltStringgt) attributegetAll()while (attributeValueshasMoreElements())

String attributeValue = attributeValuesnext()personDetailsappend(()append(attributeValue)append())

personDetailsappend(])

personDetailsappend()return personDetailstoString()

ODM Manager

ODM stands for Object Directory Mapping and this facilitates mapping of the LDAP objects directly to java objects with the help of annotations For this example we will

create a customized type applicationEntity under the node systemconfigurationservices We will start with the java model class ApplicationEntity which will have the

core attributes cn description and presentationAddress

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

package netjavabeatarticesspringodm import javautilArrayListimport javautilList import javaxnamingName import orgspringframeworkldapodmannotationsAttributeimport orgspringframeworkldapodmannotationsEntryimport orgspringframeworkldapodmannotationsId Entry(objectClasses = applicationEntity top)public class ApplicationEntity

Idprivate Name distinguisedName

Attribute(name=cn)private String cn

Attribute(name=description)private String description

Attribute(name=presentationAddress)private String presentationAddress

Attribute(name=objectClass)private ListltStringgt objectClassNames

public ApplicationEntity()

objectClassNames = new ArrayListltStringgt()

public Name getDistinguisedName()

return distinguisedName

public void setDistinguisedName(Name distinguisedName)

thisdistinguisedName = distinguisedName

public String getCn()

return cn

public void setCn(String cn)

thiscn = cn

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

8 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

484950515253545556575859606162636465666768697071727374757677

public String getDescription() return description

public void setDescription(String description) thisdescription = description

public String getPresentationAddress() return presentationAddress

public void setPresentationAddress(String presentationAddress) thispresentationAddress = presentationAddress

public ListltStringgt getObjectClassNames() return objectClassNames

public void setObjectClassNames(ListltStringgt objectClassNames) thisobjectClassNames = objectClassNames

public String toString()return cn + + description + + objectClassNames + + presentationAddress

To specify that the java class maps directly to some ldap object the annotation Entry has to be used Note that this annotation has to be configured with the list of

object types in our case this happens to be top and applicationEntiy One mandatory attribute of type Name representing the distinguished name has to be defined

and has to be annotated with Id The attributes for this entity can then be defined each annotated with Attribute annotation

12345678910111213141516171819202122232425262728293031323334353637

package netjavabeatarticesspringodm import javautilList import javaxnamingdirectorySearchControls import orgspringframeworkcontextApplicationContextimport orgspringframeworkcontextsupportClassPathXmlApplicationContextimport orgspringframeworkldapcoreDistinguishedNameimport orgspringframeworkldapodmcoreOdmManager public class Main

public static void main(String[] args)

ApplicationContext context = new ClassPathXmlApplicationContext(configxml)OdmManager odmManager = contextgetBean(odmManager OdmManagerclass)

create(odmManager)list(odmManager)read(odmManager)

private static void create(OdmManager odmManager)

ApplicationEntity addressEntity = new ApplicationEntity()

DistinguishedName distinguishedName = new DistinguishedName(ou=servicesou=configurationou=system)distinguishedNameadd(cn Address)addressEntitysetDistinguisedName(distinguishedName)addressEntitysetCn(Address)addressEntitysetDescription(Contains information about the Address entity)addressEntitysetPresentationAddress(Address)

addressEntitygetObjectClassNames()add(top)addressEntitygetObjectClassNames()add(applicationEntity)

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

9 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

38394041424344454647484950515253545556575859606162636465

odmManagercreate(addressEntity)

private static void read(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)distinguisedNameadd(cn Book)

ApplicationEntity applicationEntity = odmManagerread(ApplicationEntityclass distinguisedName)Systemoutprintln(applicationEntity)

private static void list(OdmManager odmManager)

String baseDn = ou=servicesou=configurationou=systemDistinguishedName distinguisedName = new DistinguishedName(baseDn)

SearchControls searchControls = new SearchControls()

ListltApplicationEntitygt applicationEntityList = odmManagerfindAll(

ApplicationEntityclass distinguisedName searchControls)for (ApplicationEntity applicationEntity applicationEntityList)

Systemoutprintln(applicationEntity)

For creating a new object we can use the method create() defined on OdmManager class An instance of ApplicationEntity is created and the distinguished name is set

by calling the setDistinguishedName() method After that the various attributes like cn address and presentationAddress is populated on the entity object For

reading an entity the method read() can be used by passing in an instance of distinguished name For listing all the objects of a particular object type the method

findAll() defined on OdmManager class can be used This method takes the entity type and the distinguished name as parameters

Conclusion

This article started with covering the basics of Spring LDAP by illustrating the various operations such as search add remove modify etc that can be performed

Lots of samples were also given for the better illustration of these concepts LDAP directory data can be stored externally in a file for easier migration and hence

Spring LDAP supports parsing data from such files with the help of LDIF Parser The final section of the article illustrated the usage of ODM Manager which provides a

directory mapping between ldap objects and java objects through annotations

laquo raquo

Comments

0 comments

Related posts

Introduction to Spring JDBC Framework1

Introduction to Spring OXM2

Introduction to Spring Converters and Formatters3

Introduction to Spring Expression Language (SpEL)4

Introduction to Spring Validation5

Spring LDAP

About krishnas

View all posts by krishnas rarrlarr How to integrate legacy views with designer tools in Griffon

Ads by Google Hosting Java Java Download Java Java Tutorial

Facebook social plugin

Add a comment

Comment using

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

10 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433

Like

M Subscribe by email S RSS

Routing Using Camels Implementation of the EIPs rarr

Showing 0 comments

Subscribe

Submit your email id to receive the latest news on Java Technology

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

Recent Comments

Annotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Introduction to Spring Web FrameworkAnnotation Based Bean Wiring Autowired in Spring frameworkJavaBeat on Spring Framework Interview QuestionsEnhanced Collections API in Java 8- Supports Lambda expressionsJavaBeat on Virtual Extension (or Defender) Methods in Java 8Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60Shahjoyful on Mapping Java Objects and XML Documents using JAXB in Java 60

Popular Posts

Spring Framework Interview Questions 6 comment(s) | 111 view(s)Introduction to Spring MVC Framework 2 comment(s) | 74 view(s)File Upload and Download using Java 10 comment(s) | 72 view(s)Introduction to Hibernate Caching 0 comment(s) | 63 view(s)Design Patterns Interview Questions 0 comment(s) | 61 view(s)Spring and Hibernate ORM Framework Integration 2 comment(s) | 52 view(s)

TechBreaths

Greenshot A Free Screenshot Tool for WindowsHow to add Post Statistics link for JetPack pluginDesktop App for Amazon Cloud DriveGoogle Drive offers 5GB Free StorageHow to add author RSS Feed in WordPress Blog

Archives

Categories

May 2011M T W T F S S

laquo Apr Jun raquo

12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Recent Posts

Annotation Based Bean Wiring Autowired in Spring frameworkEnhanced Collections API in Java 8- Supports Lambda expressionsA sneak peak at the Lambda Expressions in Java 8Whats new in Spring 30What are Functional Interfaces and Functional Descriptor

JavaBeat Copyright copy 2012 All Rights Reserved

LoginAdd New Comment

Introduction to Spring LDAP httpwwwjavabeatnet201105introduction-to-spring-ldapall1

11 von 11 27052012 0433