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 2010/07/26 18:23:55 UTC

svn commit: r979345 - in /directory/shared/trunk: ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java

Author: elecharny
Date: Mon Jul 26 16:23:54 2010
New Revision: 979345

URL: http://svn.apache.org/viewvc?rev=979345&view=rev
Log:
Fixed DIRSERVER-1531, added a test

Modified:
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java

Modified: directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java?rev=979345&r1=979344&r2=979345&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java (original)
+++ directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java Mon Jul 26 16:23:54 2010
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.shared.ldap.schema.loader.ldif;
 
@@ -263,6 +263,51 @@ public class SchemaManagerAddTest
 
 
     /**
+     * Try to inject an AttributeType which is a subtype of a Collective AT
+     */
+    @Test
+    public void testAddAttributeTypeSupCollectiveUser() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int atrSize = schemaManager.getAttributeTypeRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+
+        // Create the collective attribute first
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+        attributeType.setCollective( true );
+
+        // It should not fail
+        assertTrue( schemaManager.add( attributeType ) );
+
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
+
+        // Now try to create an AT which is a subtype of teh create collective attribute
+        AttributeType subType = new AttributeType( "1.1.1" );
+        subType.setEqualityOid( "2.5.13.1" );
+        subType.setOrderingOid( null );
+        subType.setSubstringOid( null );
+        subType.setSuperiorOid( "1.1.0" );
+        subType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        subType.setUsage( UsageEnum.USER_APPLICATIONS );
+        subType.setCollective( false );
+
+        // It should fail
+        assertFalse( schemaManager.add( subType ) );
+
+        assertFalse( isATPresent( schemaManager, "1.1.1" ) );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
+    }
+
+
+    /**
      * Try to inject an AttributeType which is Collective, but an operational AT
      */
     @Test
@@ -296,6 +341,40 @@ public class SchemaManagerAddTest
 
 
     /**
+     * Try to inject a single valued AttributeType which is Collective
+     */
+    @Test
+    public void testAddAttributeTypeCollectiveOperationalSigleValue() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int atrSize = schemaManager.getAttributeTypeRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+        attributeType.setCollective( true );
+        attributeType.setSingleValued( true );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapProtocolErrorException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
+    }
+
+
+    /**
      * Try to inject an AttributeType which is a NO-USER-MODIFICATION and userApplication
      */
     @Test
@@ -974,7 +1053,7 @@ public class SchemaManagerAddTest
 
 
     /**
-     * Try to inject a new MatchingRule with an existing AT name 
+     * Try to inject a new MatchingRule with an existing AT name
      */
     @Test
     public void testAddMatchingRuleExistingATName() throws Exception
@@ -1007,7 +1086,7 @@ public class SchemaManagerAddTest
 
 
     /**
-     * Try to inject a new MatchingRule with a not existing Syntax 
+     * Try to inject a new MatchingRule with a not existing Syntax
      */
     @Test
     public void testAddMatchingRuleNotExistingSyntax() throws Exception
@@ -1036,7 +1115,7 @@ public class SchemaManagerAddTest
 
 
     /**
-     * Try to inject a new MatchingRule with an existing AT name 
+     * Try to inject a new MatchingRule with an existing AT name
      */
     @Test
     public void testAddMatchingRuleNotExistingSchema() throws Exception
@@ -1428,6 +1507,49 @@ public class SchemaManagerAddTest
     }
 
 
+    /**
+     * Addition of an OC with a collective AT present in MUST or MAY.
+     */
+    @Test
+    public void testAddObjectClassNoSuperiorCollectiveATInMustOrMay() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        schemaManager.loadWithDeps( "collective" );
+        int ocrSize = schemaManager.getObjectClassRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+
+        // Check a addition in MUST
+        ObjectClass objectClassMust = new ObjectClass( "1.1.1" );
+        objectClassMust.addMustAttributeTypeOids( "c-o", "ref" );
+
+        // collective attribute in MUST : failure expected
+        assertFalse( schemaManager.add( objectClassMust ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapProtocolErrorException );
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
+
+        // Check an addition in MAY
+        ObjectClass objectClassMay = new ObjectClass( "1.1.1" );
+        objectClassMay.addMayAttributeTypeOids( "c-o", "ref" );
+
+        // collective attribute in MAY : failure expected
+        assertFalse( schemaManager.add( objectClassMay ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapProtocolErrorException );
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
+    }
+
+
     //-------------------------------------------------------------------------
     // Then, with superiors
     //-------------------------------------------------------------------------
@@ -1732,7 +1854,7 @@ public class SchemaManagerAddTest
     // Syntax addition tests
     //-------------------------------------------------------------------------
     /**
-     * Try to inject a new valid Syntax, with no SC : the associated SC 
+     * Try to inject a new valid Syntax, with no SC : the associated SC
      * will be the default OctetString SC
      */
     @Test

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java?rev=979345&r1=979344&r2=979345&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java Mon Jul 26 16:23:54 2010
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.shared.ldap.schema;
 
@@ -36,10 +36,10 @@ import org.apache.directory.shared.ldap.
  * <p>
  * According to ldapbis [MODELS]:
  * </p>
- * 
+ *
  * <pre>
  *  Object Class definitions are written according to the ABNF:
- *  
+ *
  *    ObjectClassDescription = LPAREN WSP
  *        numericoid                ; object identifier
  *        [ SP &quot;NAME&quot; SP qdescrs ]  ; short names (descriptors)
@@ -50,9 +50,9 @@ import org.apache.directory.shared.ldap.
  *        [ SP &quot;MUST&quot; SP oids ]     ; attribute types
  *        [ SP &quot;MAY&quot; SP oids ]      ; attribute types
  *        extensions WSP RPAREN
- * 
+ *
  *     kind = &quot;ABSTRACT&quot; / &quot;STRUCTURAL&quot; / &quot;AUXILIARY&quot;
- * 
+ *
  *   where:
  *     [numericoid] is object identifier assigned to this object class;
  *     NAME [qdescrs] are short names (descriptors) identifying this object
@@ -66,7 +66,7 @@ import org.apache.directory.shared.ldap.
  *         types, respectively; and
  *    [extensions] describe extensions.
  * </pre>
- * 
+ *
  * @see <a href="http://www.faqs.org/rfcs/rfc2252.html">RFC2252 Section 4.4</a>
  * @see <a
  *      href="http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-models-11.txt">ldapbis
@@ -209,6 +209,16 @@ public class ObjectClass extends Abstrac
                 {
                     AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName );
 
+                    if ( attributeType.isCollective() )
+                    {
+                        // Collective Attributes are not allowed in MAY or MUST
+                        String msg = I18n.err( I18n.ERR_04485_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, oid );
+
+                        Throwable error = new LdapProtocolErrorException( msg );
+                        errors.add( error );
+                        break;
+                    }
+
                     if ( mayAttributeTypes.contains( attributeType ) )
                     {
                         // Already registered : this is an error
@@ -248,6 +258,16 @@ public class ObjectClass extends Abstrac
                 {
                     AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName );
 
+                    if ( attributeType.isCollective() )
+                    {
+                        // Collective Attributes are not allowed in MAY or MUST
+                        String msg = I18n.err( I18n.ERR_04484_COLLECTIVE_NOT_ALLOWED_IN_MUST, mustAttributeTypeName, oid );
+
+                        Throwable error = new LdapProtocolErrorException( msg );
+                        errors.add( error );
+                        break;
+                    }
+
                     if ( mustAttributeTypes.contains( attributeType ) )
                     {
                         // Already registered : this is an error
@@ -308,7 +328,7 @@ public class ObjectClass extends Abstrac
             buildMust( errors, registries );
 
             /**
-             * Add the OC references (using and usedBy) : 
+             * Add the OC references (using and usedBy) :
              * OC -> AT (MAY and MUST)
              * OC -> OC (SUPERIORS)
              */
@@ -333,13 +353,13 @@ public class ObjectClass extends Abstrac
     /**
      * Remove the ObjectClass from the registries, updating the references to
      * other SchemaObject.
-     * 
-     * If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST), 
+     *
+     * If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
      * an exception is thrown.
      *
      * @param errors The errors we got while removing the ObjectClass from the registries
      * @param registries The Registries
-     * @exception If the ObjectClass is not valid 
+     * @exception If the ObjectClass is not valid
      */
     public void removeFromRegistries( List<Throwable> errors, Registries registries ) throws LdapException
     {
@@ -351,7 +371,7 @@ public class ObjectClass extends Abstrac
             objectClassRegistry.unregisterDescendants( this, superiors );
 
             /**
-             * Remove the OC references (using and usedBy) : 
+             * Remove the OC references (using and usedBy) :
              * OC -> AT (for MAY and MUST)
              * OC -> OC
              */
@@ -644,7 +664,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Gets the superclasses of this ObjectClass.
-     * 
+     *
      * @return the superclasses
      */
     public List<ObjectClass> getSuperiors()
@@ -655,7 +675,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Gets the superclasses OIDsof this ObjectClass.
-     * 
+     *
      * @return the superclasses OIDs
      */
     public List<String> getSuperiorOids()
@@ -717,7 +737,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Sets the superior object classes
-     * 
+     *
      * @param superiors the object classes to set
      */
     public void setSuperiors( List<ObjectClass> superiors )
@@ -744,7 +764,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Update the associated SUPERIORS ObjectClasses, even if the SchemaObject is readOnly
-     * 
+     *
      * @param superiors the object classes to set
      */
     public void updateSuperiors( List<ObjectClass> superiors )
@@ -764,7 +784,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Sets the superior object class OIDs
-     * 
+     *
      * @param superiorOids the object class OIDs to set
      */
     public void setSuperiorOids( List<String> superiorOids )
@@ -783,7 +803,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Gets the type of this ObjectClass as a type safe enum.
-     * 
+     *
      * @return the ObjectClass type as an enum
      */
     public ObjectClassTypeEnum getType()
@@ -794,7 +814,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Set the ObjectClass type, one of ABSTRACT, AUXILIARY or STRUCTURAL.
-     * 
+     *
      * @param objectClassType The ObjectClassType value
      */
     public void setType( ObjectClassTypeEnum objectClassType )
@@ -813,7 +833,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Tells if the current ObjectClass is STRUCTURAL
-     * 
+     *
      * @return <code>true</code> if the ObjectClass is STRUCTURAL
      */
     public boolean isStructural()
@@ -824,7 +844,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Tells if the current ObjectClass is ABSTRACT
-     * 
+     *
      * @return <code>true</code> if the ObjectClass is ABSTRACT
      */
     public boolean isAbstract()
@@ -835,7 +855,7 @@ public class ObjectClass extends Abstrac
 
     /**
      * Tells if the current ObjectClass is AUXILIARY
-     * 
+     *
      * @return <code>true</code> if the ObjectClass is AUXILIARY
      */
     public boolean isAuxiliary()