directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r500076 - in /directory/apacheds/branches/1.0: core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Date Fri, 26 Jan 2007 00:56:40 GMT
Author: elecharny
Date: Thu Jan 25 16:56:39 2007
New Revision: 500076

URL: http://svn.apache.org/viewvc?view=rev&rev=500076
Log:
Throwing an exception if trying to modify an operational attributes not user modifiable. Added
the corresponding tests proposed by DIRSERVER-835. *WARNING*I think this is not enough. Some
special cases are to be handled... More to come

Modified:
    directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
    directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java?view=diff&rev=500076&r1=500075&r2=500076
==============================================================================
--- directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
(original)
+++ directory/apacheds/branches/1.0/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
Thu Jan 25 16:56:39 2007
@@ -22,9 +22,14 @@
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.NoPermissionException;
 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.InvalidAttributeValueException;
+import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
@@ -32,6 +37,7 @@
 import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
 import org.apache.directory.shared.ldap.message.LockableAttributesImpl;
 import org.apache.directory.shared.ldap.message.DerefAliasesEnum;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 
 
 /**
@@ -45,7 +51,38 @@
 {
     private static final String CREATORS_NAME = "creatorsName";
     private static final String CREATE_TIMESTAMP = "createTimestamp";
+    private static final String RDN_KATE_BUSH = "cn=Kate Bush";
 
+    protected Attributes getPersonAttributes( String sn, String cn )
+    {
+        Attributes attrs = new BasicAttributes( true );
+        Attribute ocls = new BasicAttribute( "objectClass" );
+        ocls.add( "top" );
+        ocls.add( "person" );
+        attrs.put( ocls );
+        attrs.put( "cn", cn );
+        attrs.put( "sn", sn );
+
+        return attrs;
+    }
+
+    protected void setUp() throws NamingException, Exception
+    {
+        super.setUp();
+        
+        // Create an entry for Kate Bush
+        Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        DirContext ctx = sysRoot.createSubcontext( RDN_KATE_BUSH, attrs );
+        assertNotNull( ctx );
+    }
+    
+    protected void tearDown() throws NamingException, Exception
+    {
+        sysRoot.destroySubcontext( RDN_KATE_BUSH );
+        
+        super.tearDown();
+    }
+    
 
     public void testModifyOperationalOpAttrs() throws NamingException
     {
@@ -143,5 +180,79 @@
             { "creatorsName" } );
 
         assertFalse( "uid=akarasulu,ou=users,ou=system".equals( attributes.get( "creatorsName"
).get() ) );
+    }
+    
+    /**
+     * Try to add modifiersName attribute to an entry
+     */
+    public void testModifyOperationalAttributeAdd() throws NamingException
+    {
+        ModificationItem modifyOp = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute(
+            "modifiersName", "cn=Tori Amos,dc=example,dc=com" ) );
+
+        try
+        {
+            sysRoot.modifyAttributes( RDN_KATE_BUSH, new ModificationItem[]
+                { modifyOp } );
+            fail( "modification of entry should fail" );
+        }
+        catch ( InvalidAttributeValueException e )
+        {
+            // expected
+        }
+        catch ( NoPermissionException e )
+        {
+            // expected
+        }
+    }
+
+
+    /**
+     * Try to remove creatorsName attribute from an entry.
+     */
+    public void testModifyOperationalAttributeRemove() throws NamingException
+    {
+        ModificationItem modifyOp = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new
BasicAttribute(
+            "creatorsName" ) );
+
+        try
+        {
+            sysRoot.modifyAttributes( RDN_KATE_BUSH, new ModificationItem[]
+                { modifyOp } );
+            fail( "modification of entry should fail" );
+        }
+        catch ( InvalidAttributeValueException e )
+        {
+            // expected
+        }
+        catch ( NoPermissionException e )
+        {
+            // expected
+        }
+    }
+
+
+    /**
+     * Try to replace creatorsName attribute on an entry.
+     */
+    public void testModifyOperationalAttributeReplace() throws NamingException
+    {
+        ModificationItem modifyOp = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
new LockableAttributeImpl(
+            "creatorsName", "cn=Tori Amos,dc=example,dc=com" ) );
+
+        try
+        {
+            sysRoot.modifyAttributes( RDN_KATE_BUSH, new ModificationItem[]
+                { modifyOp } );
+            fail( "modification of entry should fail" );
+        }
+        catch ( InvalidAttributeValueException e )
+        {
+            // expected
+        }
+        catch ( NoPermissionException e )
+        {
+            // expected
+        }
     }
 }

Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=500076&r1=500075&r2=500076
==============================================================================
--- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Thu Jan 25 16:56:39 2007
@@ -30,6 +30,7 @@
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.NoPermissionException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
@@ -1270,6 +1271,16 @@
             if ( !atRegistry.hasAttributeType( change.getID() ) && !AttributeUtils.containsValueCaseIgnore(
objectClass, "extensibleObject" ) )
             {
                 throw new LdapInvalidAttributeIdentifierException();
+            }
+            
+            // We will forbid modification of operationnal attributes which are not
+            // user modifiable.
+            AttributeType attributeType = atRegistry.lookup( change.getID() );
+            
+            if ( ( attributeType.getUsage() == UsageEnum.DIRECTORYOPERATION ) &&
+                 ( !attributeType.isCanUserModify() ) )
+            {
+                throw new NoPermissionException( "Cannot modify the operational attribute
'" + change.getID() + "'" );
             }
 
             switch ( modOp )



Mime
View raw message