directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r569772 - in /directory/apacheds/trunk: core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
Date Sun, 26 Aug 2007 06:43:14 GMT
Author: akarasulu
Date: Sat Aug 25 23:43:13 2007
New Revision: 569772

URL: http://svn.apache.org/viewvc?rev=569772&view=rev
Log:
Fix for DIRSERVER-904: Adding two schema elements of different type with the same OID is allowed,
but it should not

Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java?rev=569772&r1=569771&r2=569772&view=diff
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
Sat Aug 25 23:43:13 2007
@@ -20,6 +20,7 @@
 package org.apache.directory.server.core.schema;
 
 
+import java.io.StringReader;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -31,6 +32,8 @@
 import javax.naming.directory.SearchResult;
 
 import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.shared.ldap.ldif.Entry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 
 
 /**
@@ -49,6 +52,61 @@
     }
 
 
+    
+    /**
+     * For <a href="https://issues.apache.org/jira/browse/DIRSERVER-904">DIRSERVER-904</a>.
+     */
+    public void testAddingTwoDifferentEntitiesWithSameOid() throws NamingException
+    {
+        String numberOfGunsAttrLdif = "dn: m-oid=1.3.6.1.4.1.18060.0.4.1.2.999,ou=attributeTypes,cn=other,ou=schema\n"
+
+            "m-usage: USER_APPLICATIONS\n" +
+            "m-equality: integerOrderingMatch\n" +
+            "objectClass: metaAttributeType\n" +
+            "objectClass: metaTop\n" +
+            "objectClass: top\n" +
+            "m-name: numberOfGuns\n" +
+            "m-oid: 1.3.6.1.4.1.18060.0.4.1.2.999\n" +
+            "m-singleValue: TRUE\n" +
+            "m-description: Number of guns of a ship\n" +
+            "m-collective: FALSE\n" +
+            "m-obsolete: FALSE\n" +
+            "m-noUserModification: FALSE\n" +
+            "m-syntax: 1.3.6.1.4.1.1466.115.121.1.27\n";
+        String shipOCLdif = "dn: m-oid=1.3.6.1.4.1.18060.0.4.1.2.999,ou=objectClasses,cn=other,ou=schema\n"
+
+            "objectClass: top\n" +
+            "objectClass: metaTop\n" +
+            "objectClass: metaObjectclass\n" +
+            "m-supObjectClass: top\n" +
+            "m-oid: 1.3.6.1.4.1.18060.0.4.1.2.999\n" +
+            "m-name: ship\n" +
+            "m-must: cn\n" +
+            "m-may: numberOfGuns\n" +
+            "m-may: description\n" +
+            "m-typeObjectClass: STRUCTURAL\n" +
+            "m-obsolete: FALSE\n" +
+            "m-description: A ship\n";
+
+        StringReader in = new StringReader( numberOfGunsAttrLdif + "\n\n" + shipOCLdif );
+        LdifReader ldifReader = new LdifReader( in );
+        Entry numberOfGunsAttrEntry = ldifReader.next();
+        Entry shipOCEntry = ldifReader.next();
+        assertFalse( ldifReader.hasNext() );
+        
+        // should be fine with unique OID
+        rootDSE.createSubcontext( numberOfGunsAttrEntry.getDn(), numberOfGunsAttrEntry.getAttributes()
);
+         
+        // should blow chuncks using same OID
+        try
+        {
+            rootDSE.createSubcontext( shipOCEntry.getDn(), shipOCEntry.getAttributes() );
+            fail( "Should not be possible to create two schema entities with the same OID."
);
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+    
+    
     public void testFillInObjectClasses() throws NamingException
     {
         Attribute ocs = sysRoot.getAttributes( "cn=person0" ).get( "objectClass" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java?rev=569772&r1=569771&r2=569772&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/MetaObjectClassHandler.java
Sat Aug 25 23:43:13 2007
@@ -29,15 +29,21 @@
 import org.apache.directory.server.constants.MetaSchemaConstants;
 import org.apache.directory.server.schema.bootstrap.Schema;
 import org.apache.directory.server.schema.registries.ObjectClassRegistry;
+import org.apache.directory.server.schema.registries.OidRegistry;
 import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeUsageSyntaxChecker;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.NamespaceTools;
 
 
@@ -52,6 +58,8 @@
 {
     private final SchemaPartitionDao dao;
     private final ObjectClassRegistry objectClassRegistry;
+    private final OidRegistry oidRegistry;
+    private final AttributeType m_oidAT;
 
 
     public MetaObjectClassHandler( Registries targetRegistries, PartitionSchemaLoader loader,
SchemaPartitionDao dao ) 
@@ -61,6 +69,8 @@
         
         this.dao = dao;
         this.objectClassRegistry = targetRegistries.getObjectClassRegistry();
+        this.m_oidAT = targetRegistries.getAttributeTypeRegistry().lookup( SchemaConstants.M_OID_AT_OID
);
+        this.oidRegistry = targetRegistries.getOidRegistry();
     }
 
 
@@ -84,6 +94,13 @@
         LdapDN parentDn = ( LdapDN ) name.clone();
         parentDn.remove( parentDn.size() - 1 );
         checkNewParent( parentDn );
+        String oid = ( String ) AttributeUtils.getAttribute( entry, m_oidAT ).get();
+        
+        if ( oidRegistry.hasOid( oid ) )
+        {
+            throw new LdapNamingException( "Oid " + oid + " for new objectClass is not unique.",

+                ResultCodeEnum.OTHER );
+        }
         
         String schemaName = getSchemaName( name );
         ObjectClass oc = factory.getObjectClass( entry, targetRegistries, schemaName );



Mime
View raw message