1 package com.atlassian.user.impl.ldap.search.page;
2
3 import com.atlassian.user.EntityException;
4 import com.atlassian.user.Group;
5 import com.atlassian.user.impl.ldap.LDAPEntityFactory;
6 import com.atlassian.user.impl.ldap.LDAPGroupFactory;
7 import com.atlassian.user.impl.ldap.repository.LdapContextFactory;
8 import com.atlassian.user.impl.ldap.search.LDAPPagerInfo;
9 import org.apache.log4j.Category;
10
11 import javax.naming.NamingEnumeration;
12 import javax.naming.directory.Attribute;
13 import javax.naming.directory.Attributes;
14 import javax.naming.directory.SearchResult;
15 import java.util.List;
16
17 public class LDAPListOfGroupsPager extends LDAPEntityPager<Group>
18 {
19 public static final Category log = Category.getInstance(LDAPListOfGroupsPager.class);
20
21 public LDAPListOfGroupsPager(LdapContextFactory contextFactory, LDAPEntityFactory<? extends Group> groupFactory, LDAPPagerInfo info)
22 {
23 super(contextFactory, groupFactory, info);
24 }
25
26 protected List<Group> preloadSearchResult(SearchResult result, List<Group> prefetched) throws EntityException
27 {
28 try
29 {
30 Attributes entityAttributes = result.getAttributes();
31 Attribute listOfEntitiesAttribute = entityAttributes.get(returningAttributes[0]);
32
33 NamingEnumeration listOfEntitiesEnumeration = listOfEntitiesAttribute.getAll();
34
35 while (listOfEntitiesEnumeration.hasMoreElements())
36 {
37 String groupDN = (String) listOfEntitiesEnumeration.nextElement();
38 log.debug("got group dn '" + groupDN + "' from pager");
39 try
40 {
41 Group group = ((LDAPGroupFactory) entityFactory).getGroup(groupDN);
42 prefetched.add(group);
43 }
44 catch (Exception e)
45 {
46 log.error("Error converting DN: " + groupDN + " into a group entity.", e);
47 }
48 }
49 }
50 catch (Throwable e)
51 {
52 log.error("Could not covnert search result: " + result + " into a list of groups.", e);
53 }
54
55 return prefetched;
56 }
57 }