directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r887711 - in /directory/shared/branches/shared-schema/ldap/src: main/antlr/distinguishedName.g main/java/org/apache/directory/shared/ldap/name/Rdn.java test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Date Sun, 06 Dec 2009 16:51:01 GMT
Author: seelmann
Date: Sun Dec  6 16:51:01 2009
New Revision: 887711

URL: http://svn.apache.org/viewvc?rev=887711&view=rev
Log:
Fix for DIRSHARED-41 and DIRSHARED-42:
o Allow numeric oid as RDN attriute value
o MultiMap.get() always returns a Collection


Modified:
    directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java

Modified: directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g?rev=887711&r1=887710&r2=887711&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/antlr/distinguishedName.g Sun Dec
 6 16:51:01 2009
@@ -101,9 +101,9 @@
  *
  * To avoid nondeterminism the following 
  * rules are excluded. These rules are 
- * explicitely added in the productions.
+ * explicitly added in the productions.
  *   EQUALS (0x3D) 
--*   HYPHEN (0x2D)  
+ *   HYPHEN (0x2D)  
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  */
@@ -556,7 +556,7 @@
  * The rule LUTF1_REST doesn't contain the following charcters,
  * so we must check them additionally
  *   EQUALS (0x3D) 
--*   HYPHEN (0x2D)  
+ *   HYPHEN (0x2D)  
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  */
@@ -574,6 +574,8 @@
     digit:DIGIT { lutf1 = digit.getText(); }
     |
     alpha:ALPHA { lutf1 = alpha.getText(); }
+    | 
+    numericoid:NUMERICOID  { lutf1 = numericoid.getText(); }    
     ;
     
 /**
@@ -584,7 +586,7 @@
  * The rule LUTF1_REST doesn't contain the following charcters,
  * so we must check them additionally
  *   EQUALS (0x3D) 
--*   HYPHEN (0x2D)  
+ *   HYPHEN (0x2D)  
  *   DIGIT (0x30-0x39)
  *   ALPHA (0x41-0x5A and 0x61-0x7A)
  *   SHARP
@@ -608,6 +610,8 @@
     sharp:SHARP { sutf1 = sharp.getText(); }
     | 
     space:SPACE  { sutf1 = space.getText(); }
+    | 
+    numericoid:NUMERICOID  { sutf1 = numericoid.getText(); }    
     ;    
 
 
@@ -727,4 +731,4 @@
 
     
     
-    
\ No newline at end of file
+    

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=887711&r1=887710&r2=887711&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
Sun Dec  6 16:51:01 2009
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -33,6 +34,7 @@
 import javax.naming.InvalidNameException;
 import javax.naming.NamingException;
 
+import org.apache.commons.collections.MultiMap;
 import org.apache.commons.collections.map.MultiValueMap;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
@@ -150,7 +152,7 @@
      */
     @SuppressWarnings(
         { "unchecked" })
-    private Map<String, AttributeTypeAndValue> atavTypes = new MultiValueMap();
+    private MultiMap atavTypes = new MultiValueMap();
 
     /**
      * We keep the type for a single valued RDN, to avoid the creation of an HashMap
@@ -547,38 +549,25 @@
             default:
                 if ( atavTypes.containsKey( normalizedType ) )
                 {
-                    Object obj = atavTypes.get( normalizedType );
+                    Collection<AttributeTypeAndValue> atavList = ( Collection<AttributeTypeAndValue>
) atavTypes.get( normalizedType );
+                    StringBuffer sb = new StringBuffer();
+                    boolean isFirst = true;
 
-                    if ( obj instanceof AttributeTypeAndValue )
+                    for ( AttributeTypeAndValue elem : atavList )
                     {
-                        return ( ( AttributeTypeAndValue ) obj ).getNormValue();
-                    }
-                    else if ( obj instanceof List )
-                    {
-                        StringBuffer sb = new StringBuffer();
-                        boolean isFirst = true;
-                        List<AttributeTypeAndValue> atavList = ( ( List<AttributeTypeAndValue>
) obj );
-
-                        for ( AttributeTypeAndValue elem : atavList )
+                        if ( isFirst )
                         {
-                            if ( isFirst )
-                            {
-                                isFirst = false;
-                            }
-                            else
-                            {
-                                sb.append( ',' );
-                            }
-
-                            sb.append( elem.getNormValue() );
+                            isFirst = false;
+                        }
+                        else
+                        {
+                            sb.append( ',' );
                         }
 
-                        return sb.toString();
-                    }
-                    else
-                    {
-                        throw new InvalidNameException( "Bad object stored in the RDN" );
+                        sb.append( elem.getNormValue() );
                     }
+
+                    return sb.toString();
                 }
 
                 return "";
@@ -638,7 +627,8 @@
             default:
                 if ( atavTypes.containsKey( normalizedType ) )
                 {
-                    return atavTypes.get( normalizedType );
+                    Collection<AttributeTypeAndValue> atavList = ( Collection<AttributeTypeAndValue>
) atavTypes.get( normalizedType );
+                    return atavList.iterator().next();
                 }
 
                 return null;

Modified: directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=887711&r1=887710&r2=887711&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Sun Dec  6 16:51:01 2009
@@ -3491,4 +3491,42 @@
         assertEquals( "ou=\\ ", dn4.getRdn().getNormName() );
     }
 
+
+    /**
+     * Test for DIRSHARED-41, DIRSTUDIO-603.
+     * (DN parser fails to parse names containing an numeric OID value)
+     */
+    @Test
+    public void testNumericOid() throws Exception
+    {
+        // numeric OID only
+        LdapDN dn1 = new LdapDN( "cn=loopback+ipHostNumber=127.0.0.1,ou=Hosts,dc=mygfs,dc=com"
);
+        assertEquals( "cn=loopback+ipHostNumber=127.0.0.1,ou=Hosts,dc=mygfs,dc=com", dn1.getUpName()
);
+        assertEquals( "cn=loopback+iphostnumber=127.0.0.1,ou=Hosts,dc=mygfs,dc=com", dn1.getNormName()
);
+        assertEquals( "cn=loopback+ipHostNumber=127.0.0.1", dn1.getRdn().getUpName() );
+        assertEquals( "cn=loopback+iphostnumber=127.0.0.1", dn1.getRdn().getNormName() );
+        assertEquals( "127.0.0.1", dn1.getRdn().getAttributeTypeAndValue( "ipHostNumber"
).getUpValue().get() );
+        
+        // numeric OID with suffix
+        LdapDN dn2 = new LdapDN( "cn=loopback+ipHostNumber=X127.0.0.1,ou=Hosts,dc=mygfs,dc=com"
);
+        assertEquals( "cn=loopback+ipHostNumber=X127.0.0.1,ou=Hosts,dc=mygfs,dc=com", dn2.getUpName()
);
+        assertEquals( "cn=loopback+iphostnumber=X127.0.0.1,ou=Hosts,dc=mygfs,dc=com", dn2.getNormName()
);
+        assertEquals( "cn=loopback+ipHostNumber=X127.0.0.1", dn2.getRdn().getUpName() );
+        assertEquals( "cn=loopback+iphostnumber=X127.0.0.1", dn2.getRdn().getNormName() );
+
+        // numeric OID with prefix
+        LdapDN dn3 = new LdapDN( "cn=loopback+ipHostNumber=127.0.0.1Y,ou=Hosts,dc=mygfs,dc=com"
);
+        assertEquals( "cn=loopback+ipHostNumber=127.0.0.1Y,ou=Hosts,dc=mygfs,dc=com", dn3.getUpName()
);
+        assertEquals( "cn=loopback+iphostnumber=127.0.0.1Y,ou=Hosts,dc=mygfs,dc=com", dn3.getNormName()
);
+        assertEquals( "cn=loopback+ipHostNumber=127.0.0.1Y", dn3.getRdn().getUpName() );
+        assertEquals( "cn=loopback+iphostnumber=127.0.0.1Y", dn3.getRdn().getNormName() );
+
+        // numeric OID with special characters
+        LdapDN dn4 = new LdapDN( "cn=loopback+ipHostNumber=\\#127.0.0.1 Z,ou=Hosts,dc=mygfs,dc=com"
);
+        assertEquals( "cn=loopback+ipHostNumber=\\#127.0.0.1 Z,ou=Hosts,dc=mygfs,dc=com",
dn4.getUpName() );
+        assertEquals( "cn=loopback+iphostnumber=\\#127.0.0.1 Z,ou=Hosts,dc=mygfs,dc=com",
dn4.getNormName() );
+        assertEquals( "cn=loopback+ipHostNumber=\\#127.0.0.1 Z", dn4.getRdn().getUpName()
);
+        assertEquals( "cn=loopback+iphostnumber=\\#127.0.0.1 Z", dn4.getRdn().getNormName()
);
+    }
+
 }



Mime
View raw message