You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/03/19 18:51:07 UTC

svn commit: r1083238 [2/2] - in /directory: apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/ shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/ shared/trunk/i18n/src/main/resources/org/apache/directory/sh...

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java (original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java Sat Mar 19 17:51:06 2011
@@ -31,18 +31,25 @@ import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.ObjectClass;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
-import org.apache.directory.shared.ldap.model.subtree.*;
+import org.apache.directory.shared.ldap.model.subtree.AndRefinement;
+import org.apache.directory.shared.ldap.model.subtree.ItemRefinement;
+import org.apache.directory.shared.ldap.model.subtree.NotRefinement;
+import org.apache.directory.shared.ldap.model.subtree.OrRefinement;
+import org.apache.directory.shared.ldap.model.subtree.Refinement;
+import org.apache.directory.shared.ldap.model.subtree.SubtreeSpecification;
+import org.apache.directory.shared.ldap.model.subtree.SubtreeSpecificationParser;
 import org.apache.directory.shared.ldap.schemaloader.JarLdifSchemaLoader;
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 /**
  * Unit tests class for Subtree Specification parser (wrapper).
  *
@@ -65,7 +72,7 @@ public class SubtreeSpecificationParserT
     private static final String INVALID_SPEC_WITH_BASE_AND_MISSING_WS = "{ base\"ou=system\"}";
 
     /** A valid specification with some specific exclusions set */
-    private static final String SPEC_WITH_SPECIFICEXCLUSIONS = "{ specificExclusions { chopAfter:\"ef=gh\", chopBefore:\"ab=cd\" } }";
+    private static final String SPEC_WITH_SPECIFICEXCLUSIONS = "{ specificExclusions { chopAfter:\"cn=gh\", chopBefore:\"cn=cd\" } }";
 
     /** A valid specification with empty specific exclusions set */
     private static final String SPEC_WITH_EMPTY_SPECIFICEXCLUSIONS = "{ specificExclusions { } }";
@@ -80,8 +87,8 @@ public class SubtreeSpecificationParserT
      * A valid specification with base and specific exclusions and minimum and
      * maximum set
      */
-    private static final String SPEC_WITH_BASE_AND_SPECIFICEXCLUSIONS_AND_MINIMUM_AND_MAXIMUM = "{ base \"ou=people\", specificExclusions { chopBefore:\"x=y\""
-        + ", chopAfter:\"k=l\", chopBefore:\"y=z\", chopAfter:\"l=m\" }, minimum   7, maximum 77 }";
+    private static final String SPEC_WITH_BASE_AND_SPECIFICEXCLUSIONS_AND_MINIMUM_AND_MAXIMUM = "{ base \"ou=people\", specificExclusions { chopBefore:\"cn=y\""
+        + ", chopAfter:\"sn=l\", chopBefore:\"c=z\", chopAfter:\"l=m\" }, minimum   7, maximum 77 }";
 
     /** A valid specification with refinement set */
     private static final String SPEC_WITH_REFINEMENT = "{ base \"ou=system\", specificationFilter and:{ and:{ item:2.5.6.0"
@@ -92,12 +99,12 @@ public class SubtreeSpecificationParserT
 
     /** A valid specification with ALL IN ONE */
     private static final String SPEC_WITH_ALL_IN_ONE = "{ base    \"ou=departments\""
-        + ", specificExclusions { chopBefore:\"x=y\", chopAfter:\"k=l\", chopBefore:\"y=z\", chopAfter:\"l=m\" }"
+        + ", specificExclusions { chopBefore:\"cn=y\", chopAfter:\"sn=l\", chopBefore:\"c=z\", chopAfter:\"l=m\" }"
         + ", minimum 7, maximum   77"
         + ", specificationFilter     and:{ and:{ item:2.5.6.0, or:{ item:2.5.6.1, item:2.5.6.2 } }, not: item:2.5.6.3 } }";
 
     /** An valid specification with unordinary component order */
-    private static final String SPEC_ORDER_OF_COMPONENTS_DOES_NOT_MATTER = "{ base \"ou=system\", minimum 3, specificExclusions { chopBefore:\"x=y\" } }";
+    private static final String SPEC_ORDER_OF_COMPONENTS_DOES_NOT_MATTER = "{ base \"ou=system\", minimum 3, specificExclusions { chopBefore:\"cn=y\" } }";
 
     /** An invalid specification with completely unrelated content */
     private static final String INVALID_SILLY_THING = "How much wood would a wood chuck chuck if a wood chuck would chuck wood?";
@@ -195,22 +202,22 @@ public class SubtreeSpecificationParserT
         SubtreeSpecification ss = parser.parse( SPEC_WITH_SPECIFICEXCLUSIONS );
         assertFalse( ss.getChopBeforeExclusions().isEmpty() );
         assertFalse( ss.getChopAfterExclusions().isEmpty() );
-        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "ab=cd" ) ) );
-        assertTrue( ss.getChopAfterExclusions().contains( new Dn( "ef=gh" ) ) );
+        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( schemaManager, "cn=cd" ) ) );
+        assertTrue( ss.getChopAfterExclusions().contains( new Dn( schemaManager, "cn=gh" ) ) );
 
         // try a second time
         ss = parser.parse( SPEC_WITH_SPECIFICEXCLUSIONS );
         assertFalse( ss.getChopBeforeExclusions().isEmpty() );
         assertFalse( ss.getChopAfterExclusions().isEmpty() );
-        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "ab=cd" ) ) );
-        assertTrue( ss.getChopAfterExclusions().contains( new Dn( "ef=gh" ) ) );
+        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( schemaManager, "cn=cd" ) ) );
+        assertTrue( ss.getChopAfterExclusions().contains( new Dn( schemaManager, "cn=gh" ) ) );
 
         // try a third time
         ss = parser.parse( SPEC_WITH_SPECIFICEXCLUSIONS );
         assertFalse( ss.getChopBeforeExclusions().isEmpty() );
         assertFalse( ss.getChopAfterExclusions().isEmpty() );
-        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "ab=cd" ) ) );
-        assertTrue( ss.getChopAfterExclusions().contains( new Dn( "ef=gh" ) ) );
+        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( schemaManager, "cn=cd" ) ) );
+        assertTrue( ss.getChopAfterExclusions().contains( new Dn( schemaManager, "cn=gh" ) ) );
     }
 
 
@@ -276,9 +283,9 @@ public class SubtreeSpecificationParserT
         assertNotNull( ss );
 
         assertEquals( "ou=people", ss.getBase().toString() );
-        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "x=y" ).normalize( schemaManager ) ) );
-        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "y=z" ).normalize( schemaManager ) ) );
-        assertTrue( ss.getChopAfterExclusions().contains( new Dn( "k=l" ).normalize( schemaManager ) ) );
+        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "cn=y" ).normalize( schemaManager ) ) );
+        assertTrue( ss.getChopBeforeExclusions().contains( new Dn( "c=z" ).normalize( schemaManager ) ) );
+        assertTrue( ss.getChopAfterExclusions().contains( new Dn( "sn=l" ).normalize( schemaManager ) ) );
         assertTrue( ss.getChopAfterExclusions().contains( new Dn( "l=m" ).normalize( schemaManager ) ) );
         assertEquals( 7, ss.getMinBaseDistance() );
         assertEquals( 77, ss.getMaxBaseDistance() );
@@ -389,14 +396,14 @@ public class SubtreeSpecificationParserT
     @Test
     public void testReusabiltiy() throws Exception
     {
-        Dn firstDn = new Dn("k=l");
-        String firstExclusion = "{ specificExclusions { chopAfter:\"k=l\" } }";
+        Dn firstDn = new Dn( schemaManager, "cn=l" );
+        String firstExclusion = "{ specificExclusions { chopAfter:\"cn=l\" } }";
         SubtreeSpecification firstSpec = parser.parse( firstExclusion );
         assertEquals( 1, firstSpec.getChopAfterExclusions().size() );
         assertEquals(firstDn, firstSpec.getChopAfterExclusions().iterator().next() );
 
-        Dn secondDn = new Dn("x=y");
-        String secondExclusion = "{ specificExclusions { chopAfter:\"x=y\" } }";
+        Dn secondDn = new Dn( schemaManager, "l=y" );
+        String secondExclusion = "{ specificExclusions { chopAfter:\"l=y\" } }";
         SubtreeSpecification secondSpec = parser.parse( secondExclusion );
         assertEquals( 1, secondSpec.getChopAfterExclusions().size() );
         assertEquals(secondDn, secondSpec.getChopAfterExclusions().iterator().next() );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java Sat Mar 19 17:51:06 2011
@@ -212,7 +212,7 @@ public class DefaultEntryAttribute imple
     {
         if ( attributeType == null ) 
         {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -283,7 +283,7 @@ public class DefaultEntryAttribute imple
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -311,7 +311,7 @@ public class DefaultEntryAttribute imple
     {
         if ( attributeType == null )
         {
-            String message = I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED );
+            String message = I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED );
             LOG.error( message );
             throw new IllegalArgumentException( message );
         }
@@ -381,7 +381,7 @@ public class DefaultEntryAttribute imple
     {
         if ( attributeType == null )
         {
-            throw new IllegalArgumentException( I18n.err( I18n.ERR_04442_NULL_AT_NOT_ALLOWED ) );
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_04460_ATTRIBUTE_TYPE_NULL_NOT_ALLOWED ) );
         }
 
         setAttributeType( attributeType );

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ComplexDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ComplexDnParser.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ComplexDnParser.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/ComplexDnParser.java Sat Mar 19 17:51:06 2011
@@ -71,6 +71,7 @@ public class ComplexDnParser
     public void parseRdn( String name, Rdn rdn ) throws LdapInvalidDnException
     {
         AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) );
+        
         try
         {
             dnParser.relativeDistinguishedName( rdn );
@@ -82,5 +83,4 @@ public class ComplexDnParser
             throw ine;
         }
     }
-
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java Sat Mar 19 17:51:06 2011
@@ -474,7 +474,7 @@ public final class Dn implements Iterabl
         for ( Rdn rdn : newDn.rdns )
         {
             String upName = rdn.getName();
-            rdnOidToName( rdn, schemaManager.getNormalizerMapping() );
+            rdnOidToName( rdn, schemaManager );
             rdn.normalize();
             rdn.setUpName( upName );
         }
@@ -1497,50 +1497,59 @@ public final class Dn implements Iterabl
     private static Ava atavOidToName( Ava atav, Map<String, OidNormalizer> oidsMap )
         throws LdapInvalidDnException
     {
-        String type = Strings.trim(atav.getNormType());
+        String type = Strings.trim( atav.getNormType() );
 
         if ( ( type.startsWith( "oid." ) ) || ( type.startsWith( "OID." ) ) )
         {
             type = type.substring( 4 );
         }
 
-        if ( Strings.isNotEmpty(type) )
+        if ( Strings.isNotEmpty( type ) )
         {
             if ( oidsMap == null )
             {
                 return atav;
             }
-            else
+            
+            type = Strings.toLowerCase( type );
+            
+            // Check that we have an existing AttributeType for this type
+            if ( !oidsMap.containsKey( type ) )
             {
-                OidNormalizer oidNormalizer = oidsMap.get( type.toLowerCase() );
+                // No AttributeType : this is an error
+                String msg = I18n.err( I18n.ERR_04268_OID_NOT_FOUND, atav.getUpType() );
+                LOG.error( msg );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, msg );
+            }
+
+            OidNormalizer oidNormalizer = oidsMap.get( type );
 
-                if ( oidNormalizer != null )
+            if ( oidNormalizer != null )
+            {
+                try
                 {
-                    try
-                    {
-                        return new Ava(
-                            atav.getUpType(),
-                            oidNormalizer.getAttributeTypeOid(),
-                            atav.getUpValue(),
-                            oidNormalizer.getNormalizer().normalize( atav.getNormValue() ),
-                            atav.getUpName() );
-                    }
-                    catch ( LdapException le )
-                    {
-                        throw new LdapInvalidDnException( le.getMessage() );
-                    }
+                    return new Ava(
+                        atav.getUpType(),
+                        oidNormalizer.getAttributeTypeOid(),
+                        atav.getUpValue(),
+                        oidNormalizer.getNormalizer().normalize( atav.getNormValue() ),
+                        atav.getUpName() );
                 }
-                else
+                catch ( LdapException le )
                 {
-                    // We don't have a normalizer for this OID : just do nothing.
-                    return atav;
+                    throw new LdapInvalidDnException( le.getMessage() );
                 }
             }
+            else
+            {
+                // We don't have a normalizer for this OID : just do nothing.
+                return atav;
+            }
         }
         else
         {
             // The type is empty : this is not possible...
-            String msg = I18n.err( I18n.ERR_04209 );
+            String msg = I18n.err( I18n.ERR_04209_EMPTY_TYPE_NOT_ALLOWED );
             LOG.error( msg );
             throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, msg );
         }
@@ -1556,7 +1565,7 @@ public final class Dn implements Iterabl
      * @throws LdapInvalidDnException If the Rdn is invalid.
      */
     /** No qualifier */
-    static void rdnOidToName( Rdn rdn, Map<String, OidNormalizer> oidsMap ) throws LdapInvalidDnException
+    static void rdnOidToName( Rdn rdn, SchemaManager schemaManager ) throws LdapInvalidDnException
     {
         // We have more than one ATAV for this Rdn. We will loop on all
         // ATAVs
@@ -1565,8 +1574,8 @@ public final class Dn implements Iterabl
 
         for ( Ava val : rdnCopy )
         {
-            Ava newAtav = atavOidToName( val, oidsMap );
-            rdn.addAVA( null, newAtav );
+            Ava newAtav = atavOidToName( val, schemaManager.getNormalizerMapping() );
+            rdn.addAVA( schemaManager, newAtav );
         }
     }
 

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java Sat Mar 19 17:51:06 2011
@@ -483,10 +483,11 @@ public final class Rdn implements Clonea
         synchronized ( this )
         {
             String savedUpName = getName();
-            Dn.rdnOidToName( this, schemaManager.getNormalizerMapping() );
+            Dn.rdnOidToName( this, schemaManager );
             normalize();
             this.upName = savedUpName;
             normalized = true;
+            this.schemaManager = schemaManager;
     
             return this;
         }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/DefaultSchemaObjectRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/DefaultSchemaObjectRegistry.java?rev=1083238&r1=1083237&r2=1083238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/DefaultSchemaObjectRegistry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/registries/DefaultSchemaObjectRegistry.java Sat Mar 19 17:51:06 2011
@@ -105,7 +105,7 @@ public abstract class DefaultSchemaObjec
             return schemaObject.getSchemaName();
         }
 
-        String msg = I18n.err( I18n.ERR_04268, oid );
+        String msg = I18n.err( I18n.ERR_04268_OID_NOT_FOUND, oid );
         LOG.warn( msg );
         throw new LdapException( msg );
     }