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 2007/01/05 16:15:18 UTC

svn commit: r493045 - in /directory/trunks/apacheds/core/src: main/java/org/apache/directory/server/core/schema/ test/java/org/apache/directory/server/core/schema/

Author: elecharny
Date: Fri Jan  5 07:15:15 2007
New Revision: 493045

URL: http://svn.apache.org/viewvc?view=rev&rev=493045
Log:
Fixed DIRSERVER-791

Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
    directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/schema/SchemaCheckerTest.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java?view=diff&rev=493045&r1=493044&r2=493045
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaChecker.java Fri Jan  5 07:15:15 2007
@@ -364,7 +364,7 @@
         }
 
         Set rdnAttributes = getRdnAttributes( name );
-        String id = oidRegistry.getOid( ( String ) attribute.getID() );
+        String id = oidRegistry.getOid( attribute.getID() );
 
         if ( !rdnAttributes.contains( id ) )
         {
@@ -389,7 +389,7 @@
         // from here on the modify operation replaces specific values
         // of the Rdn attribute so we must check to make sure all the old
         // rdn attribute values are present in the replacement set
-        String rdnValue = getRdnValue( id, name );
+        String rdnValue = getRdnValue( id, name, oidRegistry );
         for ( int ii = 0; ii < attribute.size(); ii++ )
         {
             // if the old rdn value is not in the rdn attribute then
@@ -428,7 +428,7 @@
      * @param attributes the attributes being modified
      * @throws NamingException if the modify operation is removing an Rdn attribute
      */
-    public static void preventRdnChangeOnModifyReplace( Name name, int mod, Attributes attributes )
+    public static void preventRdnChangeOnModifyReplace( Name name, int mod, Attributes attributes, OidRegistry oidRegistry )
         throws NamingException
     {
         if ( mod != DirContext.REPLACE_ATTRIBUTE )
@@ -462,7 +462,7 @@
                 // from here on the modify operation replaces specific values
                 // of the Rdn attribute so we must check to make sure all the old
                 // rdn attribute values are present in the replacement set
-                String rdnValue = getRdnValue( id, name );
+                String rdnValue = getRdnValue( id, name, oidRegistry );
                 Attribute rdnAttr = attributes.get( id );
                 for ( int ii = 0; ii < rdnAttr.size(); ii++ )
                 {
@@ -538,7 +538,7 @@
         // from here on the modify operation only deletes specific values
         // of the Rdn attribute so we must check if one of those values
         // are used by the Rdn attribute value pair for the name of the entry
-        String rdnValue = getRdnValue( id, name );
+        String rdnValue = getRdnValue( id, name, oidRegistry );
         for ( int ii = 0; ii < attribute.size(); ii++ )
         {
             if ( rdnValue.equals( attribute.get( ii ) ) )
@@ -575,7 +575,7 @@
      * @param attributes the attributes being modified
      * @throws NamingException if the modify operation is removing an Rdn attribute
      */
-    public static void preventRdnChangeOnModifyRemove( Name name, int mod, Attributes attributes )
+    public static void preventRdnChangeOnModifyRemove( Name name, int mod, Attributes attributes, OidRegistry oidRegistry )
         throws NamingException
     {
         if ( mod != DirContext.REMOVE_ATTRIBUTE )
@@ -609,7 +609,7 @@
                 // from here on the modify operation only deletes specific values
                 // of the Rdn attribute so we must check if one of those values
                 // are used by the Rdn attribute value pair for the name of the entry
-                String rdnValue = getRdnValue( id, name );
+                String rdnValue = getRdnValue( id, name, oidRegistry );
                 Attribute rdnAttr = attributes.get( id );
                 for ( int ii = 0; ii < rdnAttr.size(); ii++ )
                 {
@@ -636,19 +636,38 @@
      *
      * @param id the attribute id of the Rdn attribute to return
      * @param name the distinguished name of the entry
+     * @param oidRegistry the OID registry
      * @return the Rdn attribute value corresponding to the id, or null if the
      * attribute is not an rdn attribute
      * @throws NamingException if the name is malformed in any way
      */
-    private static String getRdnValue( String id, Name name ) throws NamingException
+    private static String getRdnValue( String id, Name name, OidRegistry oidRegistry ) throws NamingException
     {
+        // Transform the rdnAttrId to it's OID counterPart
+        String idOid = oidRegistry.getOid( id );
+
+        if ( idOid == null )
+        {
+            log.error( "The id {} does not have any OID. It should be a wrong AttributeType.", id);
+            throw new NamingException( "Wrong AttributeType, does not have an associated OID : " + id );
+        }
+
         String[] comps = NamespaceTools.getCompositeComponents( name.get( name.size() - 1 ) );
 
         for ( int ii = 0; ii < comps.length; ii++ )
         {
             String rdnAttrId = NamespaceTools.getRdnAttribute( comps[ii] );
+            
+            // Transform the rdnAttrId to it's OID counterPart
+            String rdnAttrOid = oidRegistry.getOid( rdnAttrId );
+
+            if ( rdnAttrOid == null )
+            {
+                log.error( "The id {} does not have any OID. It should be a wrong AttributeType.", rdnAttrOid);
+                throw new NamingException( "Wrong AttributeType, does not have an associated OID : " + rdnAttrOid );
+            }
 
-            if ( rdnAttrId.equalsIgnoreCase( id ) )
+            if ( rdnAttrOid.equalsIgnoreCase( idOid ) )
             {
                 return NamespaceTools.getRdnValue( comps[ii] );
             }

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=493045&r1=493044&r2=493045
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Fri Jan  5 07:15:15 2007
@@ -727,13 +727,13 @@
         
         if ( modOp == DirContext.REMOVE_ATTRIBUTE )
         {
-            SchemaChecker.preventRdnChangeOnModifyRemove( name, modOp, mods );
+            SchemaChecker.preventRdnChangeOnModifyRemove( name, modOp, mods, registries.getOidRegistry() );
             SchemaChecker.preventStructuralClassRemovalOnModifyRemove( ocRegistry, name, modOp, mods, objectClass );
         }
 
         if ( modOp == DirContext.REPLACE_ATTRIBUTE )
         {
-            SchemaChecker.preventRdnChangeOnModifyReplace( name, modOp, mods );
+            SchemaChecker.preventRdnChangeOnModifyReplace( name, modOp, mods, registries.getOidRegistry() );
             SchemaChecker.preventStructuralClassRemovalOnModifyReplace( ocRegistry, name, modOp, mods );
             assertNumberOfAttributeValuesValid( mods );
         }

Modified: directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/schema/SchemaCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/schema/SchemaCheckerTest.java?view=diff&rev=493045&r1=493044&r2=493045
==============================================================================
--- directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/schema/SchemaCheckerTest.java (original)
+++ directory/trunks/apacheds/core/src/test/java/org/apache/directory/server/core/schema/SchemaCheckerTest.java Fri Jan  5 07:15:15 2007
@@ -215,13 +215,13 @@
         attributes.put( "cn", "does not matter" );
 
         // postive test which should pass
-        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
 
         // test should fail since we are removing the ou attribute
         attributes.put( new BasicAttribute( "ou" ) );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )
@@ -233,13 +233,13 @@
         name = new LdapDN( "ou=users+cn=system users,dc=example,dc=com" );
         attributes = new BasicAttributes( true );
         attributes.put( "sn", "does not matter" );
-        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
 
         // test for failure when modifying Rdn attribute in multi attribute Rdn
         attributes.put( new BasicAttribute( "cn" ) );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )
@@ -251,14 +251,14 @@
         // is not used when composing the Rdn
         attributes = new BasicAttributes( true );
         attributes.put( "ou", "container" );
-        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
 
         // now let's make it fail again just by providing the right value for ou (users)
         attributes = new BasicAttributes( true );
         attributes.put( "ou", "users" );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyRemove( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )
@@ -280,13 +280,13 @@
         attributes.put( "cn", "does not matter" );
 
         // postive test which should pass
-        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
 
         // test should fail since we are removing the ou attribute
         attributes.put( new BasicAttribute( "ou" ) );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )
@@ -298,13 +298,13 @@
         name = new LdapDN( "ou=users+cn=system users,dc=example,dc=com" );
         attributes = new BasicAttributes( true );
         attributes.put( "sn", "does not matter" );
-        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
 
         // test for failure when modifying Rdn attribute in multi attribute Rdn
         attributes.put( new BasicAttribute( "cn" ) );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )
@@ -317,14 +317,14 @@
         attributes = new BasicAttributes( true );
         attributes.put( "ou", "container" );
         attributes.put( "ou", "users" );
-        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+        SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
 
         // now let's make it fail by not including the old value for ou (users)
         attributes = new BasicAttributes( true );
         attributes.put( "ou", "container" );
         try
         {
-            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes );
+            SchemaChecker.preventRdnChangeOnModifyReplace( name, mod, attributes, registries.getOidRegistry() );
             fail( "should never get here due to a LdapSchemaViolationException being thrown" );
         }
         catch ( LdapSchemaViolationException e )