From 15610e4f0ddd0b9cf4cbc3354122a3382577490e Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 7 Feb 2011 09:23:12 +0000 Subject: [PATCH] LDAP: fix 3166460, do not fail on NOT (0xa2) filter git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1620 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/ldap/LdapConnection.java | 8 ++++++-- src/test/davmail/ldap/TestLdap.java | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index dc0d902c..e50e1c17 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -310,6 +310,7 @@ public class LdapConnection extends AbstractConnection { // LDAP filter code static final int LDAP_FILTER_AND = 0xa0; static final int LDAP_FILTER_OR = 0xa1; + static final int LDAP_FILTER_NOT = 0xa2; // LDAP filter operators static final int LDAP_FILTER_SUBSTRINGS = 0xa4; @@ -604,7 +605,8 @@ public class LdapConnection extends AbstractConnection { protected LdapFilter parseNestedFilter(BerDecoder reqBer, int ldapFilterType, int end) throws IOException { LdapFilter nestedFilter; - if ((ldapFilterType == LDAP_FILTER_OR) || (ldapFilterType == LDAP_FILTER_AND)) { + if ((ldapFilterType == LDAP_FILTER_OR) || (ldapFilterType == LDAP_FILTER_AND) + || ldapFilterType == LDAP_FILTER_NOT) { nestedFilter = new CompoundFilter(ldapFilterType); while (reqBer.getParsePosition() < end && reqBer.bytesLeft() > 0) { @@ -915,8 +917,10 @@ public class LdapConnection extends AbstractConnection { if (type == LDAP_FILTER_OR) { buffer.append("(|"); - } else { + } else if (type == LDAP_FILTER_AND) { buffer.append("(&"); + } else { + buffer.append("(!"); } for (LdapFilter child : criteria) { diff --git a/src/test/davmail/ldap/TestLdap.java b/src/test/davmail/ldap/TestLdap.java index 94533d1e..b8943715 100644 --- a/src/test/davmail/ldap/TestLdap.java +++ b/src/test/davmail/ldap/TestLdap.java @@ -36,6 +36,7 @@ import java.util.Hashtable; /** * Test LDAP. */ +@SuppressWarnings({"JavaDoc"}) public class TestLdap extends AbstractExchangeSessionTestCase { InitialLdapContext ldapContext; @@ -151,5 +152,20 @@ public class TestLdap extends AbstractExchangeSessionTestCase { searchControls.setReturningAttributes(new String[]{"postalcode", "labeleduri", "street", "givenname", "telephonenumber", "facsimiletelephonenumber", "title", "imhandle", "homepostaladdress", "st", "homephone", "applefloor", "jpegphoto", "pager", "mail", "sn", "buildingname", "ou", "destinationindicator", "c", "o", "l", "co", "postaladdress", "cn", "mobile"}); NamingEnumeration searchResults = ldapContext.search("ou=people", "(|(mail=Test*)(cn=Test*)(givenname=Test*)(sn=Test*))", searchControls); } - + + public void testThunderbird() throws NamingException { + String filter = "(|(sn=*stocker*)(givenname=*stocker*)(mail=*stocker*)(cn=*stocker*))"; + String[] returningAttributes = new String[]{"custom1", "mozillausehtmlmail", "postalcode", "custom2", "custom3", "custom4", "street", "surname", "telephonenumber", "mozillahomelocalityname", "orgunit", "mozillaworkstreet2", "xmozillanickname", "mozillahomestreet", "description", "cellphone", "homeurl", "mozillahomepostalcode", "departmentnumber", "postofficebox", "st", "objectclass", "sn", "ou", "fax", "mozillahomeurl", "mozillahomecountryname", "streetaddress", "cn", "company", "mozillaworkurl", "mobile", "region", "birthmonth", "birthday", "labeleduri", "carphone", "department", "xmozillausehtmlmail", "givenname", "nsaimid", "workurl", "facsimiletelephonenumber", "mozillanickname", "title", "nscpaimscreenname", "xmozillasecondemail", "mozillacustom3", "countryname", "mozillacustom4", "mozillacustom1", "mozillacustom2", "homephone", "mozillasecondemail", "pager", "zip", "mail", "c", "mozillahomestate", "o", "l", "birthyear", "modifytimestamp", "locality", "commonname", "notes", "pagerphone", "mozillahomestreet2"}; + SearchControls searchControls = new SearchControls(); + searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); + searchControls.setReturningAttributes(returningAttributes); + NamingEnumeration searchResults = ldapContext.search("ou=people", filter, searchControls); + } + + public void testSearchNotFilter() throws NamingException { + SearchControls searchControls = new SearchControls(); + searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); + searchControls.setReturningAttributes(new String[]{"mail"}); + NamingEnumeration searchResults = ldapContext.search("ou=people", "(!(objectclass=test))", searchControls); + } }