Hi Udaya,
I had done the same thing that you required with liferay 6.0 sp1.
Please check the below method.
1
2
3public List<User> getAllLDAPPersons()
4 {
5 // check the cache first... if present return from cache
6 final String searchPattern = "(&(objectclass=Person))"; // made dynamic search query according to your requirement to get users from the ldap
7 final List<User> users = new ArrayList<User>();
8 NamingEnumeration<SearchResult> results = null;
9
10 try
11 {
12 final SearchControls controls = new SearchControls();
13 controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
14 // context was opened in constructor so we don't alway re-open
15 results = this.ctx.search("", searchPattern, controls);
16
17 while (results.hasMore())
18 {
19 final SearchResult searchResult = results.next();
20 final Attributes attributes = searchResult.getAttributes();
21 final Attribute cnAttr = attributes.get("cn");
22 User user = new User(); // It was my own pojo class to set and get user field from LDAP.
23 if (cnAttr != null)
24 {
25 final String cn = (String) cnAttr.get();
26 user.setCn(cn);
27 }
28 users.add(user);
29 }
30
31 } catch (final NameNotFoundException e)
32 {
33 log.error("name not found", e);
34 } catch (final NamingException e)
35 {
36 log.error("naming issue", e);
37 } finally
38 {
39
40 results.close();
41
42 }
43 return users;
44
45 }
Hope it helps.
Thanks & Regards,
Amit Doshi
Firmi prego dentro per inbandierare questo come inadeguato.