### Eclipse Workspace Patch 1.0 #P james-server-user-function Index: src/main/java/org/apache/james/userrepository/ReadOnlyUsersLDAPRepository.java =================================================================== --- src/main/java/org/apache/james/userrepository/ReadOnlyUsersLDAPRepository.java (revision 954882) +++ src/main/java/org/apache/james/userrepository/ReadOnlyUsersLDAPRepository.java (working copy) @@ -33,6 +33,8 @@ import javax.naming.NamingException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; @@ -74,6 +76,7 @@ * credentials="password" * userBase="ou=People,o=myorg.com,ou=system" * userIdAttribute="uid"/> + * userObjectClass="inetOrgPerson"/> * </users-store> * * @@ -94,6 +97,11 @@ * userIdAttribute:The name of the LDAP attribute which holds user ids. * For example "uid" for Apache DS, or "sAMAccountName" for * Microsoft Active Directory. + *
  • + * userObjectClass:The objectClass value for user nodes below the userBase. + * For example "inetOrgPerson" for Apache DS, or "user" for + * Microsoft Active Directory. + *
  • * *

    * @@ -150,6 +158,15 @@ *

    */ private String userIdAttribute; + + /** + *

    + * The value of this field is taken from the configuration attribute + * "userObjectClass". This is the LDAP object class to use + * in the search filter for user nodes under the userBase value. + *

    + */ + private String userObjectClass; /** *

    @@ -215,6 +232,7 @@ credentials = configuration.getString("[@credentials]"); userBase = configuration.getString("[@userBase]"); userIdAttribute = configuration.getString("[@userIdAttribute]"); + userObjectClass = configuration.getString("[@userObjectClass]"); restriction = new ReadOnlyLDAPGroupRestriction(configuration.configurationAt("restriction")); @@ -295,12 +313,15 @@ */ private Set getAllUsersFromLDAP() throws NamingException { Set result = new HashSet(); - NamingEnumeration boundNames = ldapConnection.getLdapContext().list(userBase); - NameClassPair elementInfo; - while (boundNames.hasMore()) { - elementInfo = (NameClassPair) boundNames.next(); - result.add(elementInfo.getNameInNamespace()); + SearchControls sc = new SearchControls (); + sc.setSearchScope (SearchControls.SUBTREE_SCOPE); + sc.setReturningAttributes (new String[] { "distinguishedName" }); + NamingEnumeration sr = ldapConnection.getLdapContext ().search (userBase, "(objectClass=" + userObjectClass + ")", sc); + while(sr.hasMore ()) + { + SearchResult r = sr.next (); + result.add (r.getNameInNamespace ()); } return result;