directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r569879 - in /directory/apacheds/trunk: core-unit/src/main/java/org/apache/directory/server/core/unit/ core-unit/src/test/java/org/apache/directory/server/core/exception/ core-unit/src/test/java/org/apache/directory/server/core/jndi/ core/s...
Date Sun, 26 Aug 2007 20:08:18 GMT
Author: akarasulu
Date: Sun Aug 26 13:08:17 2007
New Revision: 569879

URL: http://svn.apache.org/viewvc?rev=569879&view=rev
Log:
fix for DIRSERVER-925

Modified:
    directory/apacheds/trunk/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractPerformanceTest.java
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceITest.java
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/AddITest.java

Modified: directory/apacheds/trunk/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractPerformanceTest.java?rev=569879&r1=569878&r2=569879&view=diff
==============================================================================
--- directory/apacheds/trunk/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractPerformanceTest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/main/java/org/apache/directory/server/core/unit/AbstractPerformanceTest.java
Sun Aug 26 13:08:17 2007
@@ -134,8 +134,6 @@
     
     protected void setUp() throws Exception
     {
-        super.setUp();
-        
         if ( ! isExternal )
         {
             // Add indices for ou, uid, and objectClass
@@ -158,9 +156,8 @@
             
             configuration.setShutdownHookEnabled( false );
             configuration.setPartitionConfigurations( Collections.singleton( ( PartitionConfiguration
) partConfig ) );
-            
-            doDelete( configuration.getWorkingDirectory() );
-            setContextRoots( username, password, configuration );
+
+            super.setUp();
             
             Hashtable<String, Object> env = new Hashtable<String, Object>( configuration.toJndiEnvironment()
);
             env.put( Context.SECURITY_PRINCIPAL, username );

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceITest.java?rev=569879&r1=569878&r2=569879&view=diff
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/exception/ExceptionServiceITest.java
Sun Aug 26 13:08:17 2007
@@ -30,6 +30,7 @@
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.server.core.unit.AbstractAdminTestCase;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapContextNotEmptyException;
 import org.apache.directory.shared.ldap.exception.LdapNameAlreadyBoundException;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
@@ -434,9 +435,8 @@
         Attribute attr = new AttributeImpl( "objectClass" );
         attr.add( "top" );
         attr.add( "alias" );
-        attr.add( "person" );
+        attr.add( SchemaConstants.EXTENSIBLE_OBJECT_OC );
         attrs.put( attr );
-        attrs.put( "sn", "test" );
         attrs.put( "aliasedObjectName", "ou=users,ou=system" );
 
         sysRoot.createSubcontext( "cn=toanother", attrs );

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java?rev=569879&r1=569878&r2=569879&view=diff
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
Sun Aug 26 13:08:17 2007
@@ -40,9 +40,12 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.server.constants.CoreSchemaConstants;
+import org.apache.directory.server.constants.SystemSchemaConstants;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.core.unit.AbstractAdminTestCase;
 import org.apache.directory.shared.ldap.constants.JndiPropertyConstants;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
@@ -832,7 +835,7 @@
         LdapContext userCtx = null;
         Attributes referral = new AttributesImpl( "objectClass", "top", true );
         referral.get( "objectClass" ).add( "person" );
-        referral.get( "objectClass" ).add( "organizationalUnit" );
+        referral.get( "objectClass" ).add( SchemaConstants.EXTENSIBLE_OBJECT_OC );
         referral.put( "cn", "akarasulu" );
         referral.put( "sn", "karasulu" );
         referral.put( "ou", "deep" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?rev=569879&r1=569878&r2=569879&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Sun Aug 26 13:08:17 2007
@@ -1717,7 +1717,7 @@
 
         // As we now have all the ObjectClasses updated, we have
         // to check that we don't have conflicting ObjectClasses
-        assertObjectClasses( ocs );
+        assertObjectClasses( dn, ocs );
 
         assertRequiredAttributesPresent( dn, entry, must );
         assertNumberOfAttributeValuesValid( entry );
@@ -1869,35 +1869,70 @@
      * inheritance tree
      * - we must have at least one STRUCTURAL OC
      */
-    private void assertObjectClasses( List<ObjectClass> ocs )  throws LdapSchemaViolationException
+    private void assertObjectClasses( LdapDN dn, List<ObjectClass> ocs )  throws NamingException
     {
-    	boolean hasStructural = false;
+    	Set<ObjectClass> structuralObjectClasses = new HashSet<ObjectClass>();
     	
-    	// Loop on all the entry objectClasses 
+    	/*
+    	 * Since the number of ocs present in an entry is small it's not 
+    	 * so expensive to take two passes while determining correctness
+    	 * since it will result in clear simple code instead of a deep nasty
+    	 * for loop with nested loops.  Plus after the first pass we can
+    	 * quickly know if there are no structural object classes at all.
+    	 */
+    	
+    	// --------------------------------------------------------------------
+    	// Extract all structural objectClasses within the entry
+        // --------------------------------------------------------------------
+
     	for ( ObjectClass oc:ocs )
     	{
-    		if ( oc.isStructural() )
-    		{
-    			// We have a STRUCTURAL OC. Do we already found one ?
-    			if ( hasStructural )
-    			{
-    				// Yes, then there must be an inheritence relationship
-    				// between those two OC, otherwise this is an error.
-    				// TODO check that the inheritence tree is correct
-    			}
-    			else
-    			{
-    				hasStructural = true;
-    			}
-    		}
+    	    if ( oc.isStructural() )
+    	    {
+    	        structuralObjectClasses.add( oc );
+    	    }
     	}
     	
-    	// Throw an error if no STRUCTURAL objectClass is found.
-    	if ( !hasStructural )
+        // --------------------------------------------------------------------
+    	// Throw an error if no STRUCTURAL objectClass are found.
+        // --------------------------------------------------------------------
+
+    	if ( structuralObjectClasses.isEmpty() )
     	{
-    		String message = "An entry must have at least one STRUCTURAL ObjectClass";
+    		String message = "Entry " + dn + " does not contain a STRUCTURAL ObjectClass";
     		log.error( message );
     		throw new LdapSchemaViolationException( message, ResultCodeEnum.OBJECT_CLASS_VIOLATION
);
+    	}
+    	
+        // --------------------------------------------------------------------
+        // Put all structural object classes into new remaining container and
+    	// start removing any which are superiors of others in the set.  What
+    	// is left in the remaining set will be unrelated structural 
+    	/// objectClasses.  If there is more than one then we have a problem.
+        // --------------------------------------------------------------------
+    	
+    	Set<ObjectClass> remaining = new HashSet<ObjectClass>( structuralObjectClasses.size()
);
+    	remaining.addAll( structuralObjectClasses );
+    	for ( ObjectClass oc: structuralObjectClasses )
+    	{
+    	    if ( oc.getSuperClasses() != null )
+    	    {
+    	        for ( ObjectClass superClass: oc.getSuperClasses() )
+    	        {
+    	            if ( superClass.isStructural() )
+    	            {
+    	                remaining.remove( superClass );
+    	            }
+    	        }
+    	    }
+    	}
+    	
+    	// Like the highlander there can only be one :).
+    	if ( remaining.size() > 1 )
+    	{
+            String message = "Entry " + dn + " contains more than one STRUCTURAL ObjectClass:
" + remaining;
+            log.error( message );
+            throw new LdapSchemaViolationException( message, ResultCodeEnum.OBJECT_CLASS_VIOLATION
);
     	}
     }
 

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/AddITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/AddITest.java?rev=569879&r1=569878&r2=569879&view=diff
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/AddITest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/AddITest.java
Sun Aug 26 13:08:17 2007
@@ -38,6 +38,7 @@
 import netscape.ldap.LDAPException;
 
 import org.apache.directory.server.unit.AbstractServerTest;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 
@@ -388,24 +389,24 @@
 
         // Create entry
         Attributes entry = new AttributesImpl();
-        Attribute entryOcls = new AttributeImpl( "objectclass" );
-        entryOcls.add( "top" );
-        entryOcls.add( "organizationalUnit" );
+        Attribute entryOcls = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        entryOcls.add( SchemaConstants.TOP_OC );
+        entryOcls.add( SchemaConstants.ORGANIZATIONAL_UNIT_OC );
         entry.put( entryOcls );
-        entry.put( "ou", "favorite" );
+        entry.put( SchemaConstants.OU_AT, "favorite" );
         String entryRdn = "ou=favorite";
         ctx.createSubcontext( entryRdn, entry );
 
         // Create Alias
         String aliasedObjectName = entryRdn + "," + ctx.getNameInNamespace();
         Attributes alias = new AttributesImpl();
-        Attribute aliasOcls = new AttributeImpl( "objectclass" );
-        aliasOcls.add( "top" );
-        aliasOcls.add( "organizationalUnit" );
-        aliasOcls.add( "alias" );
+        Attribute aliasOcls = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        aliasOcls.add( SchemaConstants.TOP_OC );
+        aliasOcls.add( SchemaConstants.EXTENSIBLE_OBJECT_OC );
+        aliasOcls.add( SchemaConstants.ALIAS_OC );
         alias.put( aliasOcls );
-        alias.put( "ou", "bestFruit" );
-        alias.put( "aliasedObjectName", aliasedObjectName );
+        alias.put( SchemaConstants.OU_AT, "bestFruit" );
+        alias.put( SchemaConstants.ALIASED_OBJECT_NAME_AT, aliasedObjectName );
         String rdnAlias = "ou=bestFruit";
         ctx.createSubcontext( rdnAlias, alias );
 
@@ -425,34 +426,34 @@
     {
         // Create container
         Attributes container = new AttributesImpl();
-        Attribute containerOcls = new AttributeImpl( "objectclass" );
-        containerOcls.add( "top" );
-        containerOcls.add( "organizationalUnit" );
+        Attribute containerOcls = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        containerOcls.add( SchemaConstants.TOP_OC );
+        containerOcls.add( SchemaConstants.ORGANIZATIONAL_UNIT_OC );
         container.put( containerOcls );
-        container.put( "ou", "Fruits" );
+        container.put( SchemaConstants.OU_AT, "Fruits" );
         String containerRdn = "ou=Fruits";
         DirContext containerCtx = ctx.createSubcontext( containerRdn, container );
 
         // Create entry
         Attributes entry = new AttributesImpl();
-        Attribute entryOcls = new AttributeImpl( "objectclass" );
-        entryOcls.add( "top" );
-        entryOcls.add( "organizationalUnit" );
+        Attribute entryOcls = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        entryOcls.add( SchemaConstants.TOP_OC );
+        entryOcls.add( SchemaConstants.ORGANIZATIONAL_UNIT_OC );
         entry.put( entryOcls );
-        entry.put( "ou", "favorite" );
+        entry.put( SchemaConstants.OU_AT, "favorite" );
         String entryRdn = "ou=favorite";
         containerCtx.createSubcontext( entryRdn, entry );
 
         // Create alias ou=bestFruit,ou=Fruits to entry ou=favorite,ou=Fruits
         String aliasedObjectName = entryRdn + "," + containerCtx.getNameInNamespace();
         Attributes alias = new AttributesImpl();
-        Attribute aliasOcls = new AttributeImpl( "objectclass" );
-        aliasOcls.add( "top" );
-        aliasOcls.add( "organizationalUnit" );
-        aliasOcls.add( "alias" );
+        Attribute aliasOcls = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
+        aliasOcls.add( SchemaConstants.TOP_OC );
+        aliasOcls.add( SchemaConstants.EXTENSIBLE_OBJECT_OC );
+        aliasOcls.add( SchemaConstants.ALIAS_OC );
         alias.put( aliasOcls );
-        alias.put( "ou", "bestFruit" );
-        alias.put( "aliasedObjectName", aliasedObjectName );
+        alias.put( SchemaConstants.OU_AT, "bestFruit" );
+        alias.put( SchemaConstants.ALIASED_OBJECT_NAME_AT, aliasedObjectName );
         String rdnAlias = "ou=bestFruit";
         containerCtx.createSubcontext( rdnAlias, alias );
 
@@ -461,12 +462,12 @@
         controls.setDerefLinkFlag( true );
         controls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         containerCtx.addToEnvironment( "java.naming.ldap.derefAliases", "never" );
-        NamingEnumeration ne = containerCtx.search( "", "(objectClass=*)", controls );
+        NamingEnumeration<SearchResult> ne = containerCtx.search( "", "(objectClass=*)",
controls );
         assertTrue( ne.hasMore() );
-        SearchResult sr = ( SearchResult ) ne.next();
+        SearchResult sr = ne.next();
         assertEquals( "ou=favorite", sr.getName() );
         assertTrue( ne.hasMore() );
-        sr = ( SearchResult ) ne.next();
+        sr = ne.next();
         assertEquals( "ou=bestFruit", sr.getName() );
         
         // search one level with dereferencing turned on
@@ -476,7 +477,7 @@
         containerCtx.addToEnvironment( "java.naming.ldap.derefAliases", "always" );
         ne = containerCtx.search( "", "(objectClass=*)", controls );
         assertTrue( ne.hasMore() );
-        sr = ( SearchResult ) ne.next();
+        sr = ne.next();
         assertEquals( "ou=favorite", sr.getName() );
         assertFalse( ne.hasMore() );
         
@@ -487,7 +488,7 @@
         containerCtx.addToEnvironment( "java.naming.ldap.derefAliases", "always" );
         ne = containerCtx.search( "ou=bestFruit", "(objectClass=*)", controls );
         assertTrue( ne.hasMore() );
-        sr = ( SearchResult ) ne.next();
+        sr = ne.next();
         assertEquals( "ldap://localhost:"+super.port+"/ou=favorite,ou=Fruits,ou=system",
sr.getName() );
         assertFalse( ne.hasMore() );
         



Mime
View raw message