You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/10/25 13:43:24 UTC

svn commit: r328338 - in /directory/shared/ldap/trunk/common/src: antlr/ACIItem.g test/org/apache/ldap/common/aci/ACIItemParserTest.java

Author: ersiner
Date: Tue Oct 25 04:43:14 2005
New Revision: 328338

URL: http://svn.apache.org/viewcvs?rev=328338&view=rev
Log:
Updated ACIItem grammar to allow any order for all components.
Added test cases to test new functionality.

Modified:
    directory/shared/ldap/trunk/common/src/antlr/ACIItem.g
    directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/aci/ACIItemParserTest.java

Modified: directory/shared/ldap/trunk/common/src/antlr/ACIItem.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/antlr/ACIItem.g?rev=328338&r1=328337&r2=328338&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/ACIItem.g (original)
+++ directory/shared/ldap/trunk/common/src/antlr/ACIItem.g Tue Oct 25 04:43:14 2005
@@ -48,6 +48,7 @@
 import org.apache.ldap.common.util.MandatoryComponentsMonitor;
 import org.apache.ldap.common.util.NamespaceTools;
 import org.apache.ldap.common.util.NoDuplicateKeysMap;
+import org.apache.ldap.common.util.OptionalComponentsMonitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -128,6 +129,7 @@
     private ComponentsMonitor mainACIItemComponentsMonitor;
     private ComponentsMonitor itemPermissionComponentsMonitor;
     private ComponentsMonitor userPermissionComponentsMonitor;
+    private ComponentsMonitor subtreeSpecificationComponentsMonitor;
     
     
     /**
@@ -361,8 +363,13 @@
     :
     ID_itemFirst ( SP )* COLON ( SP )*
         OPEN_CURLY ( SP )*
-            protectedItems ( SP )*
-            SEP ( SP )* itemPermissions
+            ( 
+              protectedItems ( SP )*
+                SEP ( SP )* itemPermissions
+            | // relaxing
+              itemPermissions ( SP )*
+                SEP ( SP )* protectedItems
+            )
         ( SP )* CLOSE_CURLY
     {
         isItemFirstACIItem = true;
@@ -376,8 +383,13 @@
     :
     ID_userFirst ( SP )* COLON ( SP )*
         OPEN_CURLY ( SP )*
-            userClasses ( SP )*
-            SEP ( SP )* userPermissions
+            (
+              userClasses ( SP )*
+                SEP ( SP )* userPermissions
+            | // relaxing
+              userPermissions ( SP )*
+                SEP ( SP )* userClasses
+            )
         ( SP )* CLOSE_CURLY
     {
         isItemFirstACIItem = false;
@@ -575,11 +587,19 @@
     log.debug( "entered aMaxValueCount()" );
     l_maxValueCount = null;
     String l_oid = null;
+    Token token = null;
 }
     :
     OPEN_CURLY ( SP )*
-        ID_type ( SP )+ l_oid=oid ( SP )* SEP ( SP )*
-        ID_maxCount ( SP )+ token:INTEGER
+        (
+          ID_type ( SP )+ l_oid=oid ( SP )* SEP ( SP )*
+          ID_maxCount ( SP )+ token1:INTEGER
+          { token = token1; }
+        | // relaxing
+          ID_maxCount ( SP )+ token2:INTEGER ( SP )* SEP ( SP )*
+          ID_type ( SP )+ l_oid=oid
+          { token = token2; }
+        )
     ( SP )* CLOSE_CURLY
     {
         l_maxValueCount = new ProtectedItem.MaxValueCountItem( l_oid, token2Integer( token ) );
@@ -597,7 +617,6 @@
         m_protectedItemsMap.put( "maxImmSub",
                 new ProtectedItem.MaxImmSub(
                         token2Integer( token ) ) );
-        
     }
     ;
 
@@ -634,8 +653,13 @@
 }
     :
     OPEN_CURLY ( SP )*
-        ID_type ( SP )+ typeOid=oid ( SP )* SEP ( SP )*
-        ID_valuesIn ( SP )+ valuesInOid=oid
+        (
+          ID_type ( SP )+ typeOid=oid ( SP )* SEP ( SP )*
+          ID_valuesIn ( SP )+ valuesInOid=oid
+        | // relaxing
+          ID_valuesIn ( SP )+ valuesInOid=oid ( SP )* SEP ( SP )*
+          ID_type ( SP )+ typeOid=oid
+        )
     ( SP )* CLOSE_CURLY
     {
         l_restrictedValue = new ProtectedItem.RestrictedByItem( typeOid, valuesInOid );
@@ -751,11 +775,17 @@
     OPEN_CURLY ( SP )*
         ( l_grantAndDenial = grantAndDenial ( SP )*
           {
-              m_grantsAndDenials.add( l_grantAndDenial );
+              if ( !m_grantsAndDenials.add( l_grantAndDenial ))
+              {
+                  throw new RecognitionException( "Duplicated GrantAndDenial bit: " + l_grantAndDenial );
+              }
           }
             ( SEP ( SP )* l_grantAndDenial = grantAndDenial ( SP )*
               {
-                  m_grantsAndDenials.add( l_grantAndDenial );
+                  if ( !m_grantsAndDenials.add( l_grantAndDenial ))
+                  {
+                      throw new RecognitionException( "Duplicated GrantAndDenial bit: " + l_grantAndDenial );
+                  }
               }
             )*
         )?
@@ -1001,71 +1031,50 @@
     ssModifier = new SubtreeSpecificationModifier();
     chopBeforeExclusions = new HashSet();
     chopAfterExclusions = new HashSet();
+    subtreeSpecificationComponentsMonitor = new OptionalComponentsMonitor( 
+            new String [] { "base", "specificExclusions", "minimum", "maximum", "specificationFilter" } );
 }
     :
     OPEN_CURLY ( SP )*
-        (
-            ( ( ss_base ( SP )* ss_base_follower )
-            | ( ss_specificExclusions ( SP )* ss_specificExclusions_follower )
-            | ( ss_minimum ( SP )* ss_minimum_follower )
-            | ( ss_maximum ( SP )* ss_maximum_follower )
-            | ( ss_specificationFilter ( SP )* )
-            )
-        )?
+        ( subtreeSpecificationComponent ( SP )*
+            ( SEP ( SP )* subtreeSpecificationComponent ( SP )* )* )?
     CLOSE_CURLY
     {
         ss = ssModifier.getSubtreeSpecification();
     }
     ;
 
-ss_base_follower
-{
-    log.debug( "entered ss_base_follower()" );
-}
-    :
-    ( SEP ( SP )*
-        ( ( ss_specificExclusions ( SP )* ss_specificExclusions_follower )
-        | ( ss_minimum ( SP )* ss_minimum_follower )
-        | ( ss_maximum ( SP )* ss_maximum_follower )
-        | ( ss_specificationFilter ( SP )* )
-        )
-    )?
-    ;
-
-ss_specificExclusions_follower
+subtreeSpecificationComponent
 {
-    log.debug( "entered ss_specificExclusions_follower()" );
-}
-    :
-    ( SEP ( SP )*
-        ( ( ss_minimum ( SP )* ss_minimum_follower )
-        | ( ss_maximum ( SP )* ss_maximum_follower )
-        | ( ss_specificationFilter ( SP )* )
-        )
-    )?
-    ;
-
-ss_minimum_follower
-{
-    log.debug( "entered ss_minimum_follower()" );
-}
-    :
-    ( SEP ( SP )*
-        ( ( ss_maximum ( SP )* ss_maximum_follower )
-        | ( ss_specificationFilter ( SP )* )
-        )
-    )?
-    ;
-
-ss_maximum_follower
-{
-    log.debug( "entered ss_maximum_follower()" );
+    log.debug( "entered subtreeSpecification()" );
 }
     :
-    ( SEP ( SP )*
-        ss_specificationFilter ( SP )*
-    )?
+    ss_base
+    {
+        subtreeSpecificationComponentsMonitor.useComponent( "base" );
+    }
+    | ss_specificExclusions
+    {
+        subtreeSpecificationComponentsMonitor.useComponent( "specificExclusions" );
+    }
+    | ss_minimum
+    {
+        subtreeSpecificationComponentsMonitor.useComponent( "minimum" );
+    }
+    | ss_maximum
+    {
+        subtreeSpecificationComponentsMonitor.useComponent( "maximum" );
+    }
+    | ss_specificationFilter
+    {
+        subtreeSpecificationComponentsMonitor.useComponent( "specificationFilter" );
+    }
     ;
+    exception
+    catch [IllegalArgumentException e]
+    {
+        throw new RecognitionException( e.getMessage() );
+    }
 
 ss_base
 {

Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/aci/ACIItemParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/aci/ACIItemParserTest.java?rev=328338&r1=328337&r2=328338&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/aci/ACIItemParserTest.java (original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/aci/ACIItemParserTest.java Tue Oct 25 04:43:14 2005
@@ -291,4 +291,102 @@
         }
     }
     
+    public void testOrderOfMainACIComponentsDoesNotMatterButMissingsMatter() throws Exception
+    {
+        String spec = "{   itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, " +
+                "subtree {{ base \"ou=system\", specificationFilter and:{ } }, { base \"ou=ORGANIZATIONUNIT\"," +
+                "minimum  1, maximum   2 } } }  , " +
+                "userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {x=y,m=n,k=l} , " +
+                "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } } }, " +
+                " identificationTag \"id2\"   , precedence 14 }   ";
+
+        try
+        {
+            parser.parse(spec);
+            fail( "testOrderOfMainACIComponentsDoesNotMatterButMissingsMatter() should not have run this line." );
+        }
+        catch ( ParseException e )
+        {
+            assertNotNull( e );
+        }
+    }
+     
+    public void testUserFirstComponentsOrderDoesNotMatter() throws Exception
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , " +
+                "itemOrUserFirst userFirst:  { userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {x=y,m=n,k=l} , " +
+                "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } }, userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, " +
+                "subtree {{ base \"ou=system\", specificationFilter and:{ } }, { base \"ou=ORGANIZATIONUNIT\"," +
+                "minimum  1, maximum   2 } } } }  }   ";
+        
+        parser.parse( spec );
+    }
+    
+    public void testItemFirstComponentsOrderDoesNotMatter() throws Exception
+    {
+        String spec = " {  identificationTag  \"id1\" , precedence 114  , authenticationLevel simple  , " +
+                "itemOrUserFirst itemFirst  :{ itemPermissions { { userClasses {allUsers  , userGroup { \"1.2=y,z=t\"  , \"a=b,c=d\" } " +
+                " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } }," +
+                "{ precedence 10, userClasses {allUsers  , userGroup { \"1.2=y,z=t\"  , \"a=b,c=d\" } " +
+                " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } } },protectedItems  { entry  , attributeType { 1.2.3    , ou }  , " +
+                " attributeValue { ou=people  , cn=Ersin  }  , rangeOfValues (cn=ErsinEr) , " +
+                "classes and : { item: xyz , or:{item:X,item:Y}   }}  " +
+                " }}";
+        
+        parser.parse( spec );
+    }
+    
+    public void testGrantAndDenialBitsOrderDoesNotMatterButDuplicatesMatter() throws Exception
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , " +
+                "itemOrUserFirst userFirst:  { userClasses {  allUsers }  , " +
+                "userPermissions { { protectedItems{ entry  }  , grantsAndDenials { grantBrowse, grantInvoke, denyAdd, grantBrowse } } } }  }";
+        
+        try
+        {
+            parser.parse(spec);
+            fail( "testGrantAndDenialBitsOrderDoesNotMatterButDuplicatesMatter() should not have run this line." );
+        }
+        catch ( ParseException e )
+        {
+            assertNotNull( e );
+        }
+    }
+    
+    public void testRestrictedValueComponentsOrderDoesNotMatter() throws Exception
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , " +
+                "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, " +
+                "subtree {{ base \"ou=system\", specificationFilter and:{ } }, { base \"ou=ORGANIZATIONUNIT\"," +
+                "minimum  1, maximum   2 } } }  , " +
+                "userPermissions { { protectedItems{ entry  , " + 
+                "maxValueCount { { type 10.11.12, maxCount 10 }, { maxCount 20, type 11.12.13  } } " +
+                " }  , grantsAndDenials { grantBrowse } } } }  }   ";
+        
+        parser.parse( spec );
+    }
+    
+    public void testMaxValueCountComponentsOrderDoesNotMatter() throws Exception
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , " +
+                "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, " +
+                "subtree {{ base \"ou=system\", specificationFilter and:{ } }, { base \"ou=ORGANIZATIONUNIT\"," +
+                "minimum  1, maximum   2 } } }  , " +
+                "userPermissions { { protectedItems{ entry  , " + 
+                "restrictedBy { { type 10.11.12, valuesIn ou }, { valuesIn cn, type 11.12.13  } } " +
+                " }  , grantsAndDenials { grantBrowse } } } }  }   ";
+        
+        parser.parse( spec );
+    }
+    
+    public void testSubtreeSpecificationComponentsOrderDoesNotMatter() throws Exception
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , " +
+                "itemOrUserFirst userFirst:  { userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {x=y,m=n,k=l} , " +
+                "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } }, userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, " +
+                "subtree {{ specificationFilter and:{ }, base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\"," +
+                " maximum   2, minimum  1 } } }  }  }   ";
+        
+        parser.parse( spec );
+    }
 }