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 2009/05/26 01:18:34 UTC
svn commit: r778530 - in /directory/apacheds/trunk:
core-integ/src/main/java/org/apache/directory/server/core/integ/
core-integ/src/test/java/org/apache/directory/server/core/schema/
core/src/main/java/org/apache/directory/server/core/schema/
Author: elecharny
Date: Mon May 25 23:18:33 2009
New Revision: 778530
URL: http://svn.apache.org/viewvc?rev=778530&view=rev
Log:
o Added a fix for DIRSERVER-1368
o Added helper methods (isSchemaEnabled, etc) in the Schema Interceptor
o Added tests to check that inheritence is correctly handled when adding OC or AT in the schema
Modified:
directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=778530&r1=778529&r2=778530&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Mon May 25 23:18:33 2009
@@ -22,8 +22,14 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
+
import javax.naming.InvalidNameException;
import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapContext;
import org.apache.commons.io.FileUtils;
@@ -44,6 +50,7 @@
import org.apache.directory.server.core.CoreSession;
import org.apache.directory.server.core.jndi.ServerLdapContext;
+import org.apache.directory.server.schema.bootstrap.Schema;
/**
@@ -280,4 +287,58 @@
ldif.putAttribute( "givenName", givenName );
return ldif;
}
+
+ // -----------------------------------------------------------------------
+ // Enable/Disable Schema Tests
+ // -----------------------------------------------------------------------
+ public static Map<String, Schema> getLoadedSchemas( DirectoryService service )
+ {
+ return service.getRegistries().getLoadedSchemas();
+ }
+
+
+ public static void enableSchema( DirectoryService service, String schemaName ) throws Exception
+ {
+ LdapContext schemaRoot = getSchemaContext( service );
+
+ // now enable the test schema
+ ModificationItem[] mods = new ModificationItem[1];
+ Attribute attr = new BasicAttribute( "m-disabled", "FALSE" );
+ mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+ schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
+ }
+
+
+ public static void disableSchema( DirectoryService service, String schemaName ) throws Exception
+ {
+ LdapContext schemaRoot = getSchemaContext( service );
+
+ // now enable the test schema
+ ModificationItem[] mods = new ModificationItem[1];
+ Attribute attr = new BasicAttribute( "m-disabled", "TRUE" );
+ mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+ schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
+ }
+
+
+ /**
+ * A helper method which tells if a schema is disabled
+ */
+ public static boolean isDisabled( DirectoryService service, String schemaName )
+ {
+ Schema schema = getLoadedSchemas(service ).get( schemaName );
+
+ return ( schema == null ) || ( schema.isDisabled() );
+ }
+
+
+ /**
+ * A helper method which tells if a schema is enabled
+ */
+ public static boolean isEnabled( DirectoryService service, String schemaName )
+ {
+ Schema schema = getLoadedSchemas( service ).get( schemaName );
+
+ return ( schema != null ) && ( !schema.isDisabled() );
+ }
}
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java?rev=778530&r1=778529&r2=778530&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java Mon May 25 23:18:33 2009
@@ -23,8 +23,9 @@
import org.apache.directory.server.constants.MetaSchemaConstants;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+
import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
-import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
@@ -48,7 +49,6 @@
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapContext;
-import java.util.Map;
/**
@@ -61,16 +61,9 @@
@RunWith ( CiRunner.class )
public class MetaSchemaHandlerIT
{
- /** the schema to use for this test: one that is not loaded by default */
- private static final String NIS_SCHEMA = "nis";
-
/** a test attribute in the test schema: uidNumber in nis schema */
private static final String TEST_ATTR_OID = "1.3.6.1.1.1.1.0";
- /** the name of the dummy schema to test metaSchema adds/deletes with */
- private static final String DUMMY_SCHEMA = "dummy";
-
-
public static DirectoryService service;
@@ -80,12 +73,6 @@
}
- private static Map<String, Schema> getLoadedSchemas()
- {
- return service.getRegistries().getLoadedSchemas();
- }
-
-
@Before
public void checkSambaSchema() throws Exception
{
@@ -100,7 +87,7 @@
assertTrue( attributes.get( SchemaConstants.OU_AT ).contains( "attributetypes" ) );
// Disable the NIS schema
- disableSchema( "nis" );
+ IntegrationUtils.disableSchema( service, "nis" );
}
@@ -121,12 +108,12 @@
LdapContext schemaRoot = getSchemaContext( service );
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( "cn", "dummy" );
dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
- assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
+ assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
}
@@ -142,14 +129,14 @@
LdapContext schemaRoot = getSchemaContext( service );
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( "cn", "dummy" );
dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
- dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, NIS_SCHEMA );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "nis" );
dummySchema.get( MetaSchemaConstants.M_DEPENDENCIES_AT ).add( "core" );
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
- assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
+ assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
}
@@ -165,26 +152,26 @@
LdapContext schemaRoot = getSchemaContext( service );
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( "cn", "dummy" );
dummySchema.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "missing" );
dummySchema.get( MetaSchemaConstants.M_DEPENDENCIES_AT ).add( "core" );
try
{
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
}
catch( LdapOperationNotSupportedException e )
{
assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
}
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
//noinspection EmptyCatchBlock
try
{
- schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ schemaRoot.lookup( "cn=dummy" );
fail( "schema should not be added to schema partition" );
}
catch( NamingException e )
@@ -205,11 +192,11 @@
LdapContext schemaRoot = getSchemaContext( service );
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ dummySchema.put( "cn", "dummy" );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
- assertNotNull( schemaRoot.lookup( "cn=" + DUMMY_SCHEMA ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
+ assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
}
@@ -225,12 +212,12 @@
LdapContext schemaRoot = getSchemaContext( service );
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
- dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, NIS_SCHEMA );
+ dummySchema.put( "cn", "dummy" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "nis" );
try
{
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
fail( "should not be able to add enabled schema with deps on disabled schemas" );
}
catch( LdapOperationNotSupportedException e )
@@ -238,12 +225,12 @@
assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
}
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
//noinspection EmptyCatchBlock
try
{
- schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ schemaRoot.lookup( "cn=dummy" );
fail( "schema should not be added to schema partition" );
}
catch( NamingException e )
@@ -269,11 +256,11 @@
// add the dummy schema enabled
testAddEnabledSchemaNoDeps();
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
// delete it now
- schemaRoot.destroySubcontext( "cn=" + DUMMY_SCHEMA );
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ schemaRoot.destroySubcontext( "cn=dummy" );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
}
@@ -289,18 +276,18 @@
// add the dummy schema enabled
testAddEnabledSchemaNoDeps();
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
// make the nis schema depend on the dummy schema
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE,
- new BasicAttribute( MetaSchemaConstants.M_DEPENDENCIES_AT, DUMMY_SCHEMA ) );
- schemaRoot.modifyAttributes( "cn=" + NIS_SCHEMA, mods );
+ new BasicAttribute( MetaSchemaConstants.M_DEPENDENCIES_AT, "dummy" ) );
+ schemaRoot.modifyAttributes( "cn=nis", mods );
// attempt to delete it now & it should fail
try
{
- schemaRoot.destroySubcontext( "cn=" + DUMMY_SCHEMA );
+ schemaRoot.destroySubcontext( "cn=dummy" );
fail( "should not be able to delete a schema with dependents" );
}
catch ( LdapOperationNotSupportedException e )
@@ -308,7 +295,7 @@
assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
}
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
}
@@ -325,12 +312,12 @@
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
+ dummySchema.put( "cn", "dummy" );
dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "missing" );
try
{
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
fail( "should not be able to add enabled schema with deps on missing schemas" );
}
catch( LdapOperationNotSupportedException e )
@@ -338,12 +325,12 @@
assertTrue( e.getResultCode().equals( ResultCodeEnum.UNWILLING_TO_PERFORM ) );
}
- assertNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
//noinspection EmptyCatchBlock
try
{
- schemaRoot.lookup( "cn=" + DUMMY_SCHEMA );
+ schemaRoot.lookup( "cn=dummy" );
fail( "schema should not be added to schema partition" );
}
catch( NamingException e )
@@ -352,57 +339,6 @@
}
- // -----------------------------------------------------------------------
- // Enable/Disable Schema Tests
- // -----------------------------------------------------------------------
-
-
- private void enableSchema( String schemaName ) throws Exception
- {
- LdapContext schemaRoot = getSchemaContext( service );
-
- // now enable the test schema
- ModificationItem[] mods = new ModificationItem[1];
- Attribute attr = new BasicAttribute( "m-disabled", "FALSE" );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
- }
-
-
- private void disableSchema( String schemaName ) throws Exception
- {
- LdapContext schemaRoot = getSchemaContext( service );
-
- // now enable the test schema
- ModificationItem[] mods = new ModificationItem[1];
- Attribute attr = new BasicAttribute( "m-disabled", "TRUE" );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
- }
-
-
- /**
- * A helper method which tells if a schema is disabled
- */
- private boolean isDisabled( String schemaName )
- {
- Schema schema = getLoadedSchemas().get( schemaName );
-
- return ( schema == null ) || ( schema.isDisabled() );
- }
-
-
- /**
- * A helper method which tells if a schema is enabled
- */
- private boolean isEnabled( String schemaName )
- {
- Schema schema = getLoadedSchemas().get( schemaName );
-
- return ( schema != null ) && ( !schema.isDisabled() );
- }
-
-
/**
* Checks to make sure updates enabling a metaSchema object in
* the schema partition triggers the loading of that schema into
@@ -416,17 +352,17 @@
AttributeTypeRegistry atr = getAttributeTypeRegistry();
// check that the nis schema is not loaded
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// double check and make sure an attribute from that schema is
// not in the AttributeTypeRegistry
assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
// now enable the test schema
- enableSchema( "nis" );
+ IntegrationUtils.enableSchema( service, "nis" );
// now test that the schema is loaded
- assertTrue( isEnabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
// double check and make sure the test attribute from the
// test schema is now loaded and present within the attr registry
@@ -446,20 +382,20 @@
AttributeTypeRegistry atr = getAttributeTypeRegistry();
// check that the nis schema is not loaded
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// double check and make sure an attribute from that schema is
// not in the AttributeTypeRegistry
assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
// now enable the test schema
- enableSchema( "nis" );
+ IntegrationUtils.enableSchema( service, "nis" );
// and enable it again (it should not do anything)
- enableSchema( "nis" );
+ IntegrationUtils.enableSchema( service, "nis" );
// now test that the schema is loaded
- assertTrue( isEnabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
// double check and make sure the test attribute from the
// test schema is now loaded and present within the attr registry
@@ -479,23 +415,23 @@
AttributeTypeRegistry atr = getAttributeTypeRegistry();
// check that the nis schema is not loaded
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// double check and make sure an attribute from that schema is
// not in the AttributeTypeRegistry
assertFalse( atr.hasAttributeType( TEST_ATTR_OID ) );
// now disable the test schema
- disableSchema( "nis" );
+ IntegrationUtils.disableSchema( service, "nis" );
// now test that the schema is loaded
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// and disable it again (it should not do anything)
- disableSchema( "nis" );
+ IntegrationUtils.disableSchema( service, "nis" );
// and test again that the schema is still disabled
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// double check and make sure the test attribute from the
// test schema is now loaded and present within the attr registry
@@ -518,18 +454,18 @@
AttributeTypeRegistry atr = getAttributeTypeRegistry();
// check that the nis schema is enabled
- assertTrue( isEnabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
// double check and make sure an attribute from that schema is
// in the AttributeTypeRegistry
assertTrue( atr.hasAttributeType( TEST_ATTR_OID ) );
// now disable the test schema
- disableSchema( "samba" );
- disableSchema( "nis" );
+ IntegrationUtils.disableSchema( service, "samba" );
+ IntegrationUtils.disableSchema( service, "nis" );
// now test that the schema is NOT loaded
- assertTrue( isDisabled( NIS_SCHEMA ) );
+ assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
// double check and make sure the test attribute from the test
// schema is now NOT loaded and present within the attr registry
@@ -558,13 +494,13 @@
// adds enabled dummy schema that depends on the test schema
Attributes dummySchema = new BasicAttributes( "objectClass", "top", true );
dummySchema.get( "objectClass" ).add( MetaSchemaConstants.META_SCHEMA_OC );
- dummySchema.put( "cn", DUMMY_SCHEMA );
- dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, NIS_SCHEMA );
- schemaRoot.createSubcontext( "cn=" + DUMMY_SCHEMA, dummySchema );
+ dummySchema.put( "cn", "dummy" );
+ dummySchema.put( MetaSchemaConstants.M_DEPENDENCIES_AT, "nis" );
+ schemaRoot.createSubcontext( "cn=dummy", dummySchema );
// check that the nis schema is loaded and the dummy schema is loaded
- assertTrue( isEnabled( NIS_SCHEMA ) );
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
AttributeTypeRegistry atr = getAttributeTypeRegistry();
@@ -589,8 +525,8 @@
}
// now test that both schema are still loaded
- assertTrue( isEnabled( NIS_SCHEMA ) );
- assertNotNull( getLoadedSchemas().get( DUMMY_SCHEMA ) );
+ assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
+ assertNotNull( IntegrationUtils.getLoadedSchemas( service ).get( "dummy" ) );
// double check and make sure the test attribute from the test
// schema is still loaded and present within the attr registry
@@ -684,7 +620,7 @@
{
LdapContext schemaRoot = getSchemaContext( service );
- enableSchema( "samba" );
+ IntegrationUtils.enableSchema( service, "samba" );
assertTrue( getAttributeTypeRegistry().hasAttributeType( "sambaNTPassword" ) );
assertEquals( "samba", getAttributeTypeRegistry().getSchemaName( "sambaNTPassword" ) );
@@ -727,7 +663,7 @@
try
{
- schemaRoot.modifyAttributes( "cn=" + NIS_SCHEMA, mods );
+ schemaRoot.modifyAttributes( "cn=nis", mods );
fail( "Should not be able to add bogus dependency to schema" );
}
catch ( LdapOperationNotSupportedException e )
@@ -749,14 +685,14 @@
public void testRejectAddOfDisabledDependencyToEnabledSchema() throws Exception
{
LdapContext schemaRoot = getSchemaContext( service );
- enableSchema( NIS_SCHEMA );
+ IntegrationUtils.enableSchema( service, "nis" );
ModificationItem[] mods = new ModificationItem[1];
Attribute attr = new BasicAttribute( "m-dependencies", "mozilla" );
mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
try
{
- schemaRoot.modifyAttributes( "cn=" + NIS_SCHEMA, mods );
+ schemaRoot.modifyAttributes( "cn=nis", mods );
fail( "Should not be able to add disabled dependency to schema" );
}
catch ( LdapOperationNotSupportedException e )
@@ -779,8 +715,8 @@
ModificationItem[] mods = new ModificationItem[1];
Attribute attr = new BasicAttribute( "m-dependencies", "mozilla" );
mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + NIS_SCHEMA, mods );
- Attributes attrs = schemaRoot.getAttributes( "cn=" + NIS_SCHEMA );
+ schemaRoot.modifyAttributes( "cn=nis", mods );
+ Attributes attrs = schemaRoot.getAttributes( "cn=nis" );
Attribute dependencies = attrs.get( "m-dependencies" );
assertTrue( dependencies.contains( "mozilla" ) );
}
@@ -799,8 +735,8 @@
ModificationItem[] mods = new ModificationItem[1];
Attribute attr = new BasicAttribute( "m-dependencies", "java" );
mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + NIS_SCHEMA, mods );
- Attributes attrs = schemaRoot.getAttributes( "cn=" + NIS_SCHEMA );
+ schemaRoot.modifyAttributes( "cn=nis", mods );
+ Attributes attrs = schemaRoot.getAttributes( "cn=nis" );
Attribute dependencies = attrs.get( "m-dependencies" );
assertTrue( dependencies.contains( "java" ) );
}
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java?rev=778530&r1=778529&r2=778530&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java Mon May 25 23:18:33 2009
@@ -25,16 +25,22 @@
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.*;
import org.apache.directory.shared.ldap.name.LdapDN;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
@RunWith ( CiRunner.class )
@@ -45,6 +51,100 @@
public static DirectoryService service;
+
+ private void injectSchema() throws Exception
+ {
+ //--------------------------------------------------------------------
+ // The accountStatus AT
+ //--------------------------------------------------------------------
+ Attributes attributes = new BasicAttributes( true );
+ Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
+
+ objectClassAttribute.add( "top" );
+ objectClassAttribute.add( "metaTop" );
+ objectClassAttribute.add( "metaAttributeType" );
+
+ attributes.put( objectClassAttribute );
+
+ attributes.put( "m-oid", "2.16.840.1.113730.3.2.22.249" );
+
+ // The name
+ attributes.put( "m-name", "accountStatus" );
+
+ // The Obsolete flag
+ attributes.put( "m-obsolete", "FALSE" );
+
+ // The single value flag
+ attributes.put( "m-singleValue", "TRUE" );
+
+ // The collective flag
+ attributes.put( "m-collective", "FALSE" );
+
+ // The noUserModification flag
+ attributes.put( "m-noUserModification", "FALSE" );
+
+ // The usage
+ attributes.put( "m-usage", "USER_APPLICATIONS" );
+
+ // The equality matching rule
+ attributes.put( "m-equality", "caseIgnoreMatch" );
+
+ // The substr matching rule
+ attributes.put( "m-substr", "caseIgnoreSubstringsMatch" );
+
+ // The syntax
+ attributes.put( "m-syntax", "1.3.6.1.4.1.1466.115.121.1.15" );
+
+ // The superior
+ attributes.put( "m-supAttributeType", "name" );
+
+ // The description
+ attributes.put( "m-description", "Account Status" );
+
+ // Inject the AT
+ LdapDN dn = new LdapDN( "ou=attributeTypes,cn=apachemeta" );
+ dn.add( MetaSchemaConstants.M_OID_AT + "=2.16.840.1.113730.3.2.22.249" );
+
+ getSchemaContext( service ).createSubcontext( dn, attributes );
+
+ //--------------------------------------------------------------------
+ // The extendPerson OC
+ //--------------------------------------------------------------------
+ attributes = new BasicAttributes( true );
+ objectClassAttribute = new BasicAttribute( "objectClass" );
+
+ objectClassAttribute.add( "top" );
+ objectClassAttribute.add( "metaTop" );
+ objectClassAttribute.add( "metaObjectClass" );
+
+ attributes.put( objectClassAttribute );
+
+ attributes.put( "m-oid", "2.16.840.1.113730.3.2.22" );
+
+ // The name
+ attributes.put( "m-name", "extendPerson" );
+
+ // The Obsolete flag
+ attributes.put( "m-obsolete", "FALSE" );
+
+ // The Type list
+ attributes.put( "m-typeObjectClass", "STRUCTURAL" );
+
+ // The superiors
+ attributes.put( "m-supObjectClass", "inetOrgPerson" );
+
+ // The description
+ attributes.put( "m-description", "Extended InetOrgPerson" );
+
+ // The MAY list
+ attributes.put( "m-may", "accountStatus" );
+
+ // Inject the OC
+ dn = new LdapDN( "ou=objectClasses,cn=apachemeta" );
+ dn.add( MetaSchemaConstants.M_OID_AT + "=2.16.840.1.113730.3.2.22" );
+
+ getSchemaContext( service ).createSubcontext( dn, attributes );
+ }
/**
* Gets relative DN to ou=schema.
@@ -60,10 +160,10 @@
/*
- * Test that I can create an ObjectClass entry with an invalid
+ * Test that I cannot create an ObjectClass entry with an invalid name
*/
@Test
- public void testCreateObjectClassWithInvalidNameAttribute() throws Exception
+ public void testCannotCreateObjectClassWithInvalidNameAttribute() throws Exception
{
Attributes attributes = new BasicAttributes( true );
Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
@@ -94,10 +194,10 @@
}
/*
- * Test that I can create an ObjectClass entry with an invalid name
+ * Test that I canotn create an ObjectClass entry with an invalid name
*/
@Test
- public void testCreateObjectClassWithNoObjectClass() throws Exception
+ public void testCannotCreateObjectClassWithNoObjectClass() throws Exception
{
Attributes attributes = new BasicAttributes( true );
Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
@@ -106,7 +206,7 @@
objectClassAttribute.add( "metaTop" );
objectClassAttribute.add( "metaObjectClass" );
- // Don't put the objectclasses in the entry : this is in purpose !
+ // Don't put the objectclasses in the entry : this is on purpose !
// attributes.put( objectClassAttribute );
attributes.put( "m-oid", "testOID" );
@@ -127,4 +227,115 @@
assertTrue( true );
}
}
+
+
+ /**
+ * Test that if we create an OC with a superior OC then the AT are correctly
+ * inherited.
+ */
+ @Test
+ public void testCreateOCWithSuperior() throws Exception
+ {
+ injectSchema();
+
+ // Now, check that we can add entries with this new OC
+ Attributes entry = new BasicAttributes( true );
+ Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
+
+ // The ObjectClass
+ objectClassAttribute.add( "top" );
+ objectClassAttribute.add( "extendPerson" );
+
+ entry.put( objectClassAttribute );
+
+ // Mandatory attributes -- required in MUST list
+ entry.put( "uid", "test" );
+ entry.put( "sn", "test" );
+ entry.put( "givenName", "test" );
+ entry.put( "cn", "test" );
+ entry.put( "displayName", "test-test" );
+ entry.put( "initials", "tt" );
+ entry.put( "accountStatus", "test" );
+
+ // Create the context
+ DirContext system = getSystemContext( service );
+
+ try
+ {
+ system.createSubcontext( "cn=test", entry );
+ }
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail();
+ }
+
+ }
+
+
+ /**
+ * Test that if we create an AT with an ancestor, we can search and
+ * get back the entry using its ancestor
+ */
+ @Test
+ public void testCreateATWithSuperior() throws Exception
+ {
+ injectSchema();
+
+ // Now, check that we can add entries with this new AT
+ Attributes entry = new BasicAttributes( true );
+ Attribute objectClassAttribute = new BasicAttribute( "objectClass" );
+
+ // The ObjectClass
+ objectClassAttribute.add( "top" );
+ objectClassAttribute.add( "extendPerson" );
+
+ entry.put( objectClassAttribute );
+
+ // Mandatory attributes -- required in MUST list
+ entry.put( "uid", "test" );
+ entry.put( "sn", "test" );
+ entry.put( "givenName", "test" );
+ entry.put( "cn", "test" );
+ entry.put( "displayName", "test-test" );
+ entry.put( "initials", "tt" );
+ entry.put( "accountStatus", "accountStatusValue" );
+
+ // Create the context
+ DirContext system = getSystemContext( service );
+
+ try
+ {
+ system.createSubcontext( "cn=test", entry );
+ }
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail();
+ }
+
+ SearchControls sc = new SearchControls();
+ NamingEnumeration<SearchResult> result = system.search( "", "(name=accountStatusValue)", sc );
+
+ boolean found = false;
+
+ while ( result.hasMore() )
+ {
+ assertFalse( found );
+ SearchResult searchResult = result.next();
+ assertEquals( "accountStatusValue", searchResult.getAttributes().get( "accountStatus" ).get() );
+ found = true;
+ }
+
+ found = false;
+ result = system.search( "", "(accountStatus=accountStatusValue)", sc );
+
+ while ( result.hasMore() )
+ {
+ assertFalse( found );
+ SearchResult searchResult = result.next();
+ assertEquals( "accountStatusValue", searchResult.getAttributes().get( "accountStatus" ).get() );
+ found = true;
+ }
+ }
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=778530&r1=778529&r2=778530&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Mon May 25 23:18:33 2009
@@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
@@ -60,6 +61,7 @@
import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
import org.apache.directory.server.core.partition.ByPassConstants;
import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.ObjectClassRegistry;
import org.apache.directory.server.schema.registries.OidRegistry;
@@ -358,31 +360,41 @@
/**
+ * Compute the superiors and MUST/MAY attributes for a specific
+ * ObjectClass
+ */
+ private void computeSuperior( ObjectClass objectClass ) throws Exception
+ {
+ List<ObjectClass> ocSuperiors = new ArrayList<ObjectClass>();
+
+ superiors.put( objectClass.getOid(), ocSuperiors );
+
+ computeOCSuperiors( objectClass, ocSuperiors, new HashSet<String>() );
+
+ Set<String> atSeen = new HashSet<String>();
+ computeMustAttributes( objectClass, atSeen );
+ computeMayAttributes( objectClass, atSeen );
+
+ superiors.put( objectClass.getName(), ocSuperiors );
+ }
+
+
+ /**
* Compute all ObjectClasses superiors, MAY and MUST attributes.
* @throws Exception
*/
private void computeSuperiors() throws Exception
{
Iterator<ObjectClass> objectClasses = registries.getObjectClassRegistry().iterator();
- superiors = new HashMap<String, List<ObjectClass>>();
- allMust = new HashMap<String, List<AttributeType>>();
- allMay = new HashMap<String, List<AttributeType>>();
- allowed = new HashMap<String, List<AttributeType>>();
+ superiors = new ConcurrentHashMap<String, List<ObjectClass>>();
+ allMust = new ConcurrentHashMap<String, List<AttributeType>>();
+ allMay = new ConcurrentHashMap<String, List<AttributeType>>();
+ allowed = new ConcurrentHashMap<String, List<AttributeType>>();
while ( objectClasses.hasNext() )
{
- List<ObjectClass> ocSuperiors = new ArrayList<ObjectClass>();
-
ObjectClass objectClass = objectClasses.next();
- superiors.put( objectClass.getOid(), ocSuperiors );
-
- computeOCSuperiors( objectClass, ocSuperiors, new HashSet<String>() );
-
- Set<String> atSeen = new HashSet<String>();
- computeMustAttributes( objectClass, atSeen );
- computeMayAttributes( objectClass, atSeen );
-
- superiors.put( objectClass.getName(), ocSuperiors );
+ computeSuperior( objectClass );
}
}
@@ -853,6 +865,28 @@
/**
+ * A helper method which tells if a schema is disabled
+ */
+ private boolean isDisabled( String schemaName )
+ {
+ Schema schema = registries.getLoadedSchemas().get( schemaName );
+
+ return ( schema == null ) || ( schema.isDisabled() );
+ }
+
+
+ /**
+ * A helper method which tells if a schema is enabled
+ */
+ private boolean isEnabled( String schemaName )
+ {
+ Schema schema = registries.getLoadedSchemas().get( schemaName );
+
+ return ( schema != null ) && ( !schema.isDisabled() );
+ }
+
+
+ /**
* Checks to see if removing a set of attributes from an entry completely removes
* that attribute's values. If change has zero size then all attributes are
* presumed to be removed.
@@ -1791,10 +1825,52 @@
{
schemaManager.add( addContext );
- checkOcSuperior( addContext.getEntry() );
- }
+ if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.META_SCHEMA_OC ) )
+ {
+ // This is a schema addition
+ // We have to check if the schema is enabled or disabled
+ String schema = entry.get( SchemaConstants.CN_AT ).getString();
+
+ next.add( addContext );
- next.add( addContext );
+ if ( isEnabled( schema ) )
+ {
+ // Update the OC superiors for each added ObjectClass
+ computeSuperiors();
+ }
+ }
+ else if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.META_OBJECT_CLASS_OC ) )
+ {
+ // This is an ObjectClass addition
+ checkOcSuperior( addContext.getEntry() );
+
+ next.add( addContext );
+
+ // Update the structures now that the schema element has been added
+ String schemaName = MetaSchemaUtils.getSchemaName( name );
+
+ if ( isEnabled( schemaName ) )
+ {
+ String ocName = entry.get( MetaSchemaConstants.M_NAME_AT ).getString();
+ ObjectClass addedOC = registries.getObjectClassRegistry().lookup( ocName );
+ computeSuperior( addedOC );
+ }
+ }
+ else if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.META_ATTRIBUTE_TYPE_OC ) )
+ {
+ // This is an AttributeType addition
+ next.add( addContext );
+ }
+ else
+ {
+ next.add( addContext );
+ }
+
+ }
+ else
+ {
+ next.add( addContext );
+ }
}
@@ -1942,6 +2018,7 @@
Set<ObjectClass> remaining = new HashSet<ObjectClass>( structuralObjectClasses.size() );
remaining.addAll( structuralObjectClasses );
+
for ( ObjectClass oc : structuralObjectClasses )
{
if ( oc.getSuperClasses() != null )