harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r651568 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ main/java/org/apache/harmony/jndi/provider/ldap/asn1/ test/java/org/apache/harmony/jndi/provider/ldap/
Date Fri, 25 Apr 2008 10:33:21 GMT
Author: tonywu
Date: Fri Apr 25 03:33:18 2008
New Revision: 651568

URL: http://svn.apache.org/viewvc?rev=651568&view=rev
Log:
Apply patch for HARMONY-5793 ([classlib][jndi][ldap] - incorrect search filter when Attributes
has only one attribute with on value in search(Name, Attributes, String[]))

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=651568&r1=651567&r2=651568&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Fri Apr 25 03:33:18 2008
@@ -557,7 +557,10 @@
         List<LdapAttribute> la = new ArrayList<LdapAttribute>(attrs.size());
         NamingEnumeration<? extends Attribute> enu = attrs.getAll();
         while (enu.hasMore()) {
-            la.add(new LdapAttribute(enu.next(), this));
+            Attribute att = enu.next();
+            if (att.size() > 0) {
+                la.add(new LdapAttribute(att, this));
+            }
         }
 
         // do add operation
@@ -1282,17 +1285,27 @@
             filter = new Filter(Filter.PRESENT_FILTER);
             filter.setValue("objectClass");
         } else {
-            NamingEnumeration<? extends Attribute> attrs = attributes.getAll();
-            filter = new Filter(Filter.AND_FILTER);
-            while (attrs.hasMore()) {
-                Attribute attr = attrs.next();
-                String type = attr.getID();
-                NamingEnumeration<?> enuValues = attr.getAll();
-                while (enuValues.hasMore()) {
-                    Object value = enuValues.next();
-                    Filter child = new Filter(Filter.EQUALITY_MATCH_FILTER);
-                    child.setValue(new AttributeTypeAndValuePair(type, value));
-                    filter.addChild(child);
+            // only one attribute type and value pair
+            if (attributes.size() == 1 && attributes.getAll().next().size() == 1)
{
+                filter = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                Attribute att = attributes.getAll().next();
+                filter.setValue(new AttributeTypeAndValuePair(att.getID(), att
+                        .get()));
+            } else {
+                NamingEnumeration<? extends Attribute> attrs = attributes
+                        .getAll();
+                filter = new Filter(Filter.AND_FILTER);
+                while (attrs.hasMore()) {
+                    Attribute attr = attrs.next();
+                    String type = attr.getID();
+                    NamingEnumeration<?> enuValues = attr.getAll();
+                    while (enuValues.hasMore()) {
+                        Object value = enuValues.next();
+                        Filter child = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                        child.setValue(new AttributeTypeAndValuePair(type,
+                                value));
+                        filter.addChild(child);
+                    }
                 }
             }
         }
@@ -1680,6 +1693,10 @@
         }
 
         if (name instanceof CompositeName) {
+            if (name.size() == 0) {
+                return new BasicAttributes(true);
+            }
+
             LdapName lname = new LdapName(name.get(0));
             Rdn rdn = lname.getRdn(lname.size() - 1);
             return rdn.toAttributes();
@@ -2072,7 +2089,7 @@
     }
 
     private boolean hasAttribute(Attributes attributes, String type,
-            Object value) throws NamingException {
+            String value) throws NamingException {
         Attribute attr = attributes.get(type);
         if (attr == null) {
             return false;
@@ -2081,7 +2098,7 @@
         NamingEnumeration<?> enu = attr.getAll();
         while (enu.hasMore()) {
             Object o = enu.next();
-            if (value.equals(o)) {
+            if (value.equalsIgnoreCase(Utils.getString(o))) {
                 return true;
             }
         }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java?rev=651568&r1=651567&r2=651568&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/asn1/ASN1LdapFilter.java
Fri Apr 25 03:33:18 2008
@@ -61,8 +61,8 @@
             out.content = bytes;
             out.length = bytes.length;
         }
-        // TODO: Any way better to do this(append out.content to out.encoded)?
-        out.encodeString();
+
+        out.encodeANY();
     }
 
     @Override
@@ -93,4 +93,8 @@
         out.length = bytes.length;
     }
 
+    @Override
+    public int getEncodedLength(BerOutputStream out) {
+        return out.length;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java?rev=651568&r1=651567&r2=651568&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ldapURLContext.java
Fri Apr 25 03:33:18 2008
@@ -102,6 +102,7 @@
 
         if (name.size() == 1) {
             bind(name.get(0), obj, attributes);
+            return;
         }
 
         DirContext context = getContinuationContext(name);
@@ -359,6 +360,7 @@
 
         if (name.size() == 1) {
             rebind(name.get(0), obj, attributes);
+            return;
         }
 
         DirContext context = getContinuationContext(name);
@@ -518,20 +520,27 @@
                     filter = new Filter(Filter.PRESENT_FILTER);
                     filter.setValue("objectClass");
                 } else {
-                    NamingEnumeration<? extends Attribute> attrs = attributes
-                            .getAll();
-                    filter = new Filter(Filter.AND_FILTER);
-                    while (attrs.hasMore()) {
-                        Attribute attr = attrs.next();
-                        String type = attr.getID();
-                        NamingEnumeration<?> enuValues = attr.getAll();
-                        while (enuValues.hasMore()) {
-                            Object value = enuValues.next();
-                            Filter child = new Filter(
-                                    Filter.EQUALITY_MATCH_FILTER);
-                            child.setValue(new AttributeTypeAndValuePair(type,
-                                    value));
-                            filter.addChild(child);
+                    if (attributes.size() == 1) {
+                        filter = new Filter(Filter.EQUALITY_MATCH_FILTER);
+                        Attribute att = attributes.getAll().next();
+                        filter.setValue(new AttributeTypeAndValuePair(att
+                                .getID(), att.get()));
+                    } else {
+                        NamingEnumeration<? extends Attribute> attrs = attributes
+                                .getAll();
+                        filter = new Filter(Filter.AND_FILTER);
+                        while (attrs.hasMore()) {
+                            Attribute attr = attrs.next();
+                            String type = attr.getID();
+                            NamingEnumeration<?> enuValues = attr.getAll();
+                            while (enuValues.hasMore()) {
+                                Object value = enuValues.next();
+                                Filter child = new Filter(
+                                        Filter.EQUALITY_MATCH_FILTER);
+                                child.setValue(new AttributeTypeAndValuePair(
+                                        type, value));
+                                filter.addChild(child);
+                            }
                         }
                     }
                 }
@@ -549,6 +558,10 @@
                 list.add(sr);
             }
 
+            if (list.size() == 0 && result.getException() != null) {
+                throw result.getException();
+            }
+
             return new LdapNamingEnumeration<SearchResult>(list, result
                     .getException());
         } finally {
@@ -604,6 +617,10 @@
                         .get(name));
                 sr.setNameInNamespace(name);
                 list.add(sr);
+            }
+
+            if (list.size() == 0 && result.getException() != null) {
+                throw result.getException();
             }
 
             return new LdapNamingEnumeration<SearchResult>(list, result

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java?rev=651568&r1=651567&r2=651568&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/FilterTest.java
Fri Apr 25 03:33:18 2008
@@ -17,9 +17,8 @@
 
 package org.apache.harmony.jndi.provider.ldap;
 
-import java.util.ArrayList;
-
 import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+import org.apache.harmony.jndi.provider.ldap.Filter.MatchingRuleAssertion;
 import org.apache.harmony.jndi.provider.ldap.Filter.SubstringFilter;
 import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
 import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
@@ -73,7 +72,21 @@
         filter = new Filter(Filter.APPROX_MATCH_FILTER);
         filter.setValue(new AttributeTypeAndValuePair("cn", "test"));
         ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+        
+        filter = new Filter(Filter.EXTENSIBLE_MATCH_FILTER);
+        MatchingRuleAssertion value = new MatchingRuleAssertion();
+        value.setDnAttributes(true);
+        assertTrue(value.isDnAttributes());
+        value.setMatchingRule("equal");
+        assertEquals("equal", value.getMatchingRule());
+        value.setMatchValue("cn");
+        assertEquals("cn", value.getMatchValue());
+        value.setType("type");
+        assertEquals("type", value.getType());
+        filter.setValue(value);
 
+        ASN1TestUtils.checkEncode(filter, LdapASN1Constant.Filter);
+        
         // composite filter
         filter = new Filter(Filter.AND_FILTER);
         Filter equal = new Filter(Filter.EQUALITY_MATCH_FILTER);

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java?rev=651568&r1=651567&r2=651568&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
Fri Apr 25 03:33:18 2008
@@ -306,7 +306,7 @@
         assertEquals("cn=what,cn=test", op.getEntry());
         assertEquals("cn=how", op.getNewrdn());
         assertEquals("cn=test", op.getNewSuperior());
-        assertEquals(true, op.isDeleteoldrdn());
+        assertTrue(op.isDeleteoldrdn());
 
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
         env.put("java.naming.ldap.deleteRDN", "false");
@@ -318,7 +318,7 @@
         assertEquals("cn=what,o=harmony,cn=test", op.getEntry());
         assertEquals("o=apache", op.getNewrdn());
         assertEquals("cn=test", op.getNewSuperior());
-        assertEquals(false, op.isDeleteoldrdn());
+        assertFalse(op.isDeleteoldrdn());
 
         try {
             context.rename(null, "cn=hello");
@@ -402,7 +402,7 @@
         assertEquals(controls.length + 1, actual.length);
     }
 
-    public void test_search_LAttribute() throws Exception {
+    public void test_search_LAttributes() throws Exception {
         MockLdapClient client = new MockLdapClient();
         context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
                 "cn=test");
@@ -421,9 +421,9 @@
         SearchControls controls = op.getControls();
         assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
         assertEquals(0, controls.getCountLimit());
-        assertEquals(false, controls.getDerefLinkFlag());
-        assertEquals(false, controls.getReturningObjFlag());
-        assertEquals(null, controls.getReturningAttributes());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
 
         Filter filter = op.getFilter();
         assertEquals(Filter.AND_FILTER, filter.getType());
@@ -463,6 +463,35 @@
         }
     }
 
+    public void test_search_LAttributes_single() throws Exception {
+        MockLdapClient client = new MockLdapClient();
+        context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+                "cn=test");
+
+        Attributes attrs = new BasicAttributes();
+        attrs.put("cn", "hello");
+
+        context.search("cn=hello", attrs);
+
+        SearchOp op = (SearchOp) client.getRequest();
+        assertEquals("cn=hello,cn=test", op.getBaseObject());
+        SearchControls controls = op.getControls();
+        assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
+        assertEquals(0, controls.getCountLimit());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
+
+        Filter filter = op.getFilter();
+        assertNull(filter.getChildren());
+        assertEquals(Filter.EQUALITY_MATCH_FILTER, filter.getType());
+        AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) filter
+                .getValue();
+        assertEquals("cn", pair.getType());
+        assertEquals("hello", pair.getValue());
+    }
+        
+
     public void test_search_with_filter() throws Exception {
         MockLdapClient client = new MockLdapClient();
         context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
@@ -499,8 +528,8 @@
         context.search("test=search", "(objectClass=*)", null);
         op = (SearchOp) client.getRequest();
         assertEquals(0, op.getControls().getCountLimit());
-        assertEquals(false, op.getControls().getDerefLinkFlag());
-        assertEquals(false, op.getControls().getReturningObjFlag());
+        assertFalse(op.getControls().getDerefLinkFlag());
+        assertFalse(op.getControls().getReturningObjFlag());
         assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
                 .getSearchScope());
         assertEquals(0, op.getControls().getTimeLimit());
@@ -578,6 +607,14 @@
         Hashtable<Object, Object> env = new Hashtable<Object, Object>();
 
         context = new LdapContextImpl(client, env, "cn=test");
+
+        try {
+            context.bind("cn=bind", new Object());
+            fail("Should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // exptected
+        }
+
         context.bind("cn=bind", "it's bind");
 
         AddOp op = (AddOp) client.getRequest();
@@ -694,9 +731,9 @@
         SearchControls controls = op.getControls();
         assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
         assertEquals(0, controls.getCountLimit());
-        assertEquals(false, controls.getDerefLinkFlag());
-        assertEquals(false, controls.getReturningObjFlag());
-        assertEquals(null, controls.getReturningAttributes());
+        assertFalse(controls.getDerefLinkFlag());
+        assertFalse(controls.getReturningObjFlag());
+        assertNull(controls.getReturningAttributes());
 
         Filter filter = op.getFilter();
         assertEquals(Filter.PRESENT_FILTER, filter.getType());
@@ -766,8 +803,8 @@
 
         op = (SearchOp) client.getRequest();
         assertEquals(0, op.getControls().getCountLimit());
-        assertEquals(false, op.getControls().getDerefLinkFlag());
-        assertEquals(false, op.getControls().getReturningObjFlag());
+        assertFalse(op.getControls().getDerefLinkFlag());
+        assertFalse(op.getControls().getReturningObjFlag());
         assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
                 .getSearchScope());
         assertEquals(0, op.getControls().getTimeLimit());



Mime
View raw message