directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r506239 - in /directory/apacheds/trunk: core-unit/src/test/java/org/apache/directory/server/core/schema/ core/src/main/java/org/apache/directory/server/core/schema/
Date Mon, 12 Feb 2007 02:59:58 GMT
Author: akarasulu
Date: Sun Feb 11 18:59:57 2007
New Revision: 506239

URL: http://svn.apache.org/viewvc?view=rev&rev=506239
Log:
changes ...

 o added the dao to the DescriptionParsers class to enable lookups so we can 
   validate certain values: seems odd but this is the best place for it
 o fixed some bugs in syntax handler moving the checks to the DescriptionParsers
 o added more unit tests to the SubschemaSubentryITest


Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java?view=diff&rev=506239&r1=506238&r2=506239
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
Sun Feb 11 18:59:57 2007
@@ -90,46 +90,6 @@
 
     
     /**
-     * Get's the subschemaSubentry attribute value from the rootDSE.
-     * 
-     * @return the subschemaSubentry distinguished name
-     * @throws NamingException if there are problems accessing the RootDSE
-     */
-    private String getSubschemaSubentryDN() throws NamingException
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        controls.setReturningAttributes( new String[]{ SUBSCHEMA_SUBENTRY } );
-        
-        NamingEnumeration<SearchResult> results = rootDSE.search( "", "(objectClass=*)",
controls );
-        SearchResult result = results.next();
-        results.close();
-        Attribute subschemaSubentry = result.getAttributes().get( SUBSCHEMA_SUBENTRY );
-        return ( String ) subschemaSubentry.get();
-    }
-
-    
-    /**
-     * Gets the subschemaSubentry attributes for the global schema.
-     * 
-     * @return all operational attributes of the subschemaSubentry 
-     * @throws NamingException if there are problems accessing this entry
-     */
-    private Attributes getSubschemaSubentryAttributes() throws NamingException
-    {
-        SearchControls controls = new SearchControls();
-        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
-        controls.setReturningAttributes( new String[]{ "+", "*" } );
-        
-        NamingEnumeration<SearchResult> results = rootDSE.search( getSubschemaSubentryDN(),

-            "(objectClass=*)", controls );
-        SearchResult result = results.next();
-        results.close();
-        return result.getAttributes();
-    }
-    
-    
-    /**
      * Make sure the global subschemaSubentry is where it is expected to be. 
      */
     public void testRootDSEsSubschemaSubentry() throws NamingException
@@ -1040,7 +1000,209 @@
     // -----------------------------------------------------------------------
     // AttributeType Tests
     // -----------------------------------------------------------------------
+
     
+    private void checkAttributeTypePresent( String oid, String schemaName, boolean isPresent
) throws Exception
+    {
+        // -------------------------------------------------------------------
+        // check first to see if it is present in the subschemaSubentry
+        // -------------------------------------------------------------------
+        
+        Attributes attrs = getSubschemaSubentryAttributes();
+        Attribute attrTypes = attrs.get( "attributeTypes" );
+        AttributeTypeDescription attributeTypeDescription = null; 
+        for ( int ii = 0; ii < attrTypes.size(); ii++ )
+        {
+            String desc = ( String ) attrTypes.get( ii );
+            if ( desc.indexOf( oid ) != -1 )
+            {
+                attributeTypeDescription = attributeTypeDescriptionSchemaParser.parseAttributeTypeDescription(
desc );
+                break;
+            }
+        }
+     
+        if ( isPresent )
+        {
+            assertNotNull( attributeTypeDescription );
+            assertEquals( oid, attributeTypeDescription.getNumericOid() );
+        }
+        else
+        {
+            assertNull( attributeTypeDescription );
+        }
+
+        // -------------------------------------------------------------------
+        // check next to see if it is present in the schema partition
+        // -------------------------------------------------------------------
+        
+        attrs = null;
+        
+        if ( isPresent )
+        {
+            attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn=" +
schemaName );
+            assertNotNull( attrs );
+        }
+        else
+        {
+            try
+            {
+                attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=attributeTypes,cn="
+ schemaName );
+                fail( "should never get here" );
+            }
+            catch( NamingException e )
+            {
+            }
+            assertNull( attrs );
+        }
+        
+        // -------------------------------------------------------------------
+        // check to see if it is present in the attributeTypeRegistry
+        // -------------------------------------------------------------------
+        
+        if ( isPresent ) 
+        { 
+            assertTrue( registries.getAttributeTypeRegistry().hasAttributeType( oid ) );
+        }
+        else
+        {
+            assertFalse( registries.getAttributeTypeRegistry().hasAttributeType( oid ) );
+        }
+    }
+    
+    
+    /**
+     * Tests a number of modify add, remove and replace operation combinations for
+     * attributeTypes on the schema subentry.
+     */
+    public void testAddRemoveReplaceAttributeTypes() throws Exception
+    {
+        enableSchema( "nis" );
+        List<String> descriptions = new ArrayList<String>();
+
+        // -------------------------------------------------------------------
+        // test rejection with non-existant syntax
+        // -------------------------------------------------------------------
+        
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 DESC 'bogus desc' " +
+                "SYNTAX 1.2.3.4 X-SCHEMA 'nis' )" );
+        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 DESC 'bogus desc' " +
+                "SYNTAX 1.2.3.4 X-SCHEMA 'nis' )" );
+
+        try
+        {
+            modify( DirContext.ADD_ATTRIBUTE, descriptions, "attributeTypes" );
+            fail( "Cannot add attributeType with bogus non-existant syntax" );
+        }
+        catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
+        
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+        checkAttributeTypePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+
+//        // -------------------------------------------------------------------
+//        // test add with existant syntax but no name and no desc
+//        // -------------------------------------------------------------------
+//
+//        descriptions.clear();
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 " +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 " +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        
+//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
+//        
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+//
+//        // -------------------------------------------------------------------
+//        // test add with existant syntax but no name 
+//        // -------------------------------------------------------------------
+//        
+//        // clear the matchingRules out now
+//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+//
+//        descriptions.clear();
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 DESC 'bogus desc' " +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 DESC 'bogus desc' " +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        
+//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
+//        
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+//
+//        // -------------------------------------------------------------------
+//        // test add success with name
+//        // -------------------------------------------------------------------
+//        
+//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+//        
+//        descriptions.clear();
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'blah0' DESC 'bogus desc'
" +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'blah1' 'othername1'
) DESC 'bogus desc' " +
+//                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        
+//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
+//        
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+//
+//        // -------------------------------------------------------------------
+//        // test add success full (with obsolete)
+//        // -------------------------------------------------------------------
+//        
+//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+//        
+//        descriptions.clear();
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10000 NAME 'blah0' DESC 'bogus desc'
" +
+//                "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10001 NAME ( 'blah1' 'othername1'
) DESC 'bogus desc' " +
+//                "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" );
+//        
+//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
+//        
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", true );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", true );
+//
+//        // -------------------------------------------------------------------
+//        // test failure to replace
+//        // -------------------------------------------------------------------
+//        
+//        modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10000", "nis", false );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10001", "nis", false );
+//        
+//        try
+//        {
+//            modify( DirContext.REPLACE_ATTRIBUTE, descriptions, "matchingRules" );
+//            fail( "modify REPLACE operations should not be allowed" );
+//        }
+//        catch ( LdapOperationNotSupportedException e )
+//        {
+//            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+//        }
+//
+//        // -------------------------------------------------------------------
+//        // check add no schema info
+//        // -------------------------------------------------------------------
+//        
+//        descriptions.clear();
+//        descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.2.10002 DESC 'bogus desc' " +
+//            "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" );
+//        modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" );
+//        checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.2.10002", "other", true );
+    }
+
     
     /**
      * Tests the addition of a new attributeType via a modify ADD on the SSSE to disabled
schema.
@@ -1195,5 +1357,45 @@
         }
         
         return new String( Base64.encode( out.toByteArray() ) );
+    }
+
+
+    /**
+     * Get's the subschemaSubentry attribute value from the rootDSE.
+     * 
+     * @return the subschemaSubentry distinguished name
+     * @throws NamingException if there are problems accessing the RootDSE
+     */
+    private String getSubschemaSubentryDN() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        controls.setReturningAttributes( new String[]{ SUBSCHEMA_SUBENTRY } );
+        
+        NamingEnumeration<SearchResult> results = rootDSE.search( "", "(objectClass=*)",
controls );
+        SearchResult result = results.next();
+        results.close();
+        Attribute subschemaSubentry = result.getAttributes().get( SUBSCHEMA_SUBENTRY );
+        return ( String ) subschemaSubentry.get();
+    }
+
+    
+    /**
+     * Gets the subschemaSubentry attributes for the global schema.
+     * 
+     * @return all operational attributes of the subschemaSubentry 
+     * @throws NamingException if there are problems accessing this entry
+     */
+    private Attributes getSubschemaSubentryAttributes() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        controls.setReturningAttributes( new String[]{ "+", "*" } );
+        
+        NamingEnumeration<SearchResult> results = rootDSE.search( getSubschemaSubentryDN(),

+            "(objectClass=*)", controls );
+        SearchResult result = results.next();
+        results.close();
+        return result.getAttributes();
     }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java?view=diff&rev=506239&r1=506238&r2=506239
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DescriptionParsers.java
Sun Feb 11 18:59:57 2007
@@ -67,6 +67,8 @@
 
 /**
  * Parses descriptions using a number of different parsers for schema descriptions.
+ * Also checks to make sure some things are valid as it's parsing paramters of
+ * certain entity types.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -114,15 +116,18 @@
     private final NameFormDescriptionSchemaParser nameFormParser =
         new NameFormDescriptionSchemaParser();
     
+    private final SchemaPartitionDao dao;
+    
     
     /**
      * Creates a description parser.
      * 
      * @param globalRegistries the registries to use while creating new schema entities
      */
-    public DescriptionParsers( Registries globalRegistries )
+    public DescriptionParsers( Registries globalRegistries, SchemaPartitionDao dao )
     {
         this.globalRegistries = globalRegistries;
+        this.dao = dao;
     }
 
     
@@ -247,7 +252,14 @@
                 iave.setRootCause( e );
                 throw iave;
             }
-            
+
+            if ( desc.getSyntax() != null && ! dao.hasSyntax( desc.getSyntax() )
)
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of an attributeType with an invalid syntax:
" + desc.getSyntax(), 
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
             AttributeTypeImpl at = new AttributeTypeImpl( desc.getNumericOid(), globalRegistries
);
             at.setCanUserModify( desc.isUserModifiable() );
             at.setCollective( desc.isCollective() );
@@ -395,6 +407,14 @@
                 throw iave;
             }
             
+            if ( ! dao.hasSyntaxChecker( desc.getNumericOid() ) )
+            {
+                throw new LdapOperationNotSupportedException(
+                    "Cannot permit the addition of a syntax without the prior creation of
a " +
+                    "\nsyntaxChecker with the same object identifier of the syntax!",
+                    ResultCodeEnum.UNWILLING_TO_PERFORM );
+            }
+
             SyntaxImpl syntax = new SyntaxImpl( desc.getNumericOid(), globalRegistries.getSyntaxCheckerRegistry()
);
             setSchemaObjectProperties( desc, syntax );
             syntax.setHumanReadible( isHumanReadable( desc ) );
@@ -439,7 +459,7 @@
                 throw iave;
             }
             
-            if ( ! globalRegistries.getSyntaxRegistry().hasSyntax( desc.getSyntax() ) )
+            if ( ! dao.hasSyntax( desc.getSyntax() )  )
             {
                 throw new LdapOperationNotSupportedException(
                     "Cannot create a matchingRule that depends on non-existant syntax: "
+ desc.getSyntax(),

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java?view=diff&rev=506239&r1=506238&r2=506239
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaSyntaxHandler.java
Sun Feb 11 18:59:57 2007
@@ -271,14 +271,6 @@
     {
         Schema schema = loader.getSchema( syntax.getSchema() );
         
-        if ( ! dao.hasSyntaxChecker( syntax.getOid() ) )
-        {
-            throw new LdapOperationNotSupportedException(
-                "Cannot permit the addition of a syntax without the prior creation of a "
+
-                "\nsyntaxChecker with the same object identifier of the syntax!",
-                ResultCodeEnum.UNWILLING_TO_PERFORM );
-        }
-
         if ( ! schema.isDisabled() )
         {
             syntaxRegistry.register( syntax );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java?view=diff&rev=506239&r1=506238&r2=506239
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
Sun Feb 11 18:59:57 2007
@@ -187,7 +187,7 @@
         this.schemaObjectHandlers[NAME_FORM_INDEX] = new MetaNameFormHandler( globalRegistries,
loader ); 
 
         this.subentryModifier = new SchemaSubentryModifier( dao );
-        this.parsers = new DescriptionParsers( globalRegistries );
+        this.parsers = new DescriptionParsers( globalRegistries, dao );
         
         OidRegistry oidRegistry = globalRegistries.getOidRegistry();
         



Mime
View raw message