From ec5063505dd2df9ce309b4e1e30183d32caa0406 Mon Sep 17 00:00:00 2001 From: mguessan Date: Fri, 13 Aug 2010 21:52:05 +0000 Subject: [PATCH] LDAP: Improve sizeLimit handling and ignore attributes git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1336 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/ldap/LdapConnection.java | 12 +++++++++--- src/test/davmail/ldap/TestLdap.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 463cbdd1..d26eca4d 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -291,7 +291,9 @@ public class LdapConnection extends AbstractConnection { LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomestreet2", null); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("labeleduri", null); - + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-generateduid", null); + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-serviceslocator", null); + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("uidnumber", null); } /** @@ -963,7 +965,11 @@ public class LdapConnection extends AbstractConnection { Map persons = null; for (LdapFilter child : criteria) { - Map childFind = child.findInGAL(session, returningAttributes, sizeLimit); + int currentSizeLimit = sizeLimit; + if (persons != null) { + currentSizeLimit -= persons.size(); + } + Map childFind = child.findInGAL(session, returningAttributes, currentSizeLimit); if (childFind != null) { if (persons == null) { @@ -1319,7 +1325,7 @@ public class LdapConnection extends AbstractConnection { } } if (!abandon && persons.size() < sizeLimit) { - for (ExchangeSession.Contact person : ldapFilter.findInGAL(session, returningAttributes, sizeLimit).values()) { + for (ExchangeSession.Contact person : ldapFilter.findInGAL(session, returningAttributes, sizeLimit - persons.size()).values()) { if (persons.size() == sizeLimit) { break; } diff --git a/src/test/davmail/ldap/TestLdap.java b/src/test/davmail/ldap/TestLdap.java index 605af57a..e17ff807 100644 --- a/src/test/davmail/ldap/TestLdap.java +++ b/src/test/davmail/ldap/TestLdap.java @@ -98,4 +98,20 @@ public class TestLdap extends AbstractExchangeSessionTestCase { assertEquals(session.getAlias(), attribute.get()); assertNotNull(attributes.get("givenName")); } + + public void testOSXSearch() throws NamingException { + SearchControls searchControls = new SearchControls(); + searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); + searchControls.setReturningAttributes(new String[]{"uid", "jpegphoto", "postalcode", "mail", "sn", "apple-emailcontacts", "c", "street", "givenname", "l", "apple-user-picture", "telephonenumber", "cn", "st", "apple-imhandle"}); + NamingEnumeration searchResults = ldapContext.search("cn=users, o=od", "(&(objectclass=inetOrgPerson)(|(givenname=Charles*)(|(uid=Charles*)(cn=Charles*))(sn=Charles*))(objectclass=shadowAccount)(objectclass=extensibleObject)(objectclass=posixAccount)(objectclass=apple-user))", searchControls); + assertTrue(searchResults.hasMore()); + } + + public void testAnotherOSXSearch() throws NamingException { + SearchControls searchControls = new SearchControls(); + searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); + searchControls.setReturningAttributes(new String[]{"uid", "mail", "sn", "cn", "description", "apple-generateduid", "givenname", "apple-serviceslocator", "uidnumber"}); + NamingEnumeration searchResults = ldapContext.search("cn=users, o=od", + "(&(objectclass=inetOrgPerson)(objectclass=extensibleObject)(objectclass=apple-user)(|(|(uid=fair*)(cn=fair*))(givenname=fair*)(sn=fair*)(cn=fair*)(mail=fair*))(objectclass=posixAccount)(objectclass=shadowAccount))", searchControls); + } }