directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r581891 - in /directory: apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/ apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/ apacheds/trunk/core/src/main/java/org/apache/direc...
Date Thu, 04 Oct 2007 13:15:51 GMT
Author: elecharny
Date: Thu Oct  4 06:15:48 2007
New Revision: 581891

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

Modified:
    directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java

Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java?rev=581891&r1=581890&r2=581891&view=diff
==============================================================================
--- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
(original)
+++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/operational/OperationalAttributeServiceITest.java
Thu Oct  4 06:15:48 2007
@@ -39,6 +39,7 @@
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.DerefAliasesEnum;
 import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.junit.Test;
 
 
 /**
@@ -186,6 +187,7 @@
      * @see <a href="http://nagoya.apache.org/jira/browse/DIREVE-67">JIRA Issue
      *      DIREVE-67</a>
      */
+    @Test
     public void testConfirmNonAdminUserDnIsCreatorsName() throws NamingException
     {
 
@@ -199,7 +201,8 @@
     /**
      * Modify an entry and check whether attributes modifiersName and modifyTimestamp are
present.
      */
-    public void _testModifyShouldLeadToModifiersAttributes() throws NamingException
+    @Test
+    public void testModifyShouldLeadToModifiersAttributes() throws NamingException
     {
         ModificationItem modifyOp = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute(
"description",
             "Singer Songwriter" ) );
@@ -224,7 +227,8 @@
     /**
      * Modify an entry and check whether attribute modifyTimestamp changes.
      */
-    public void _testModifyShouldChangeModifyTimestamp() throws NamingException, InterruptedException
+    @Test
+    public void testModifyShouldChangeModifyTimestamp() throws NamingException, InterruptedException
     {
         // Add attribute description to entry
         ModificationItem modifyAddOp = new ModificationItem( DirContext.ADD_ATTRIBUTE, new
BasicAttribute(
@@ -262,9 +266,6 @@
         assertNotNull( modifyTimestamp );
         String newTimestamp = modifyTimestamp.get().toString();
         
-        System.out.println(oldTimestamp);
-        System.out.println(newTimestamp);
-
         // assert the value has changed
         assertFalse( oldTimestamp.equals( newTimestamp ) );
     }
@@ -273,6 +274,7 @@
     /**
      * Try to add modifiersName attribute to an entry
      */
+    @Test
     public void testModifyOperationalAttributeAdd() throws NamingException
     {
         ModificationItem modifyOp = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute(
@@ -298,6 +300,7 @@
     /**
      * Try to remove creatorsName attribute from an entry.
      */
+    @Test
     public void testModifyOperationalAttributeRemove() throws NamingException
     {
         ModificationItem modifyOp = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new
BasicAttribute(
@@ -323,6 +326,7 @@
     /**
      * Try to replace creatorsName attribute on an entry.
      */
+    @Test(expected=NoPermissionException.class)
     public void testModifyOperationalAttributeReplace() throws NamingException
     {
         ModificationItem modifyOp = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
new AttributeImpl(

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java?rev=581891&r1=581890&r2=581891&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeService.java
Thu Oct  4 06:15:48 2007
@@ -37,6 +37,7 @@
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.server.core.configuration.InterceptorConfiguration;
 import org.apache.directory.server.core.enumeration.SearchResultFilter;
 import org.apache.directory.server.core.enumeration.SearchResultFilteringEnumeration;
@@ -66,6 +67,8 @@
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -79,6 +82,28 @@
  */
 public class OperationalAttributeService extends BaseInterceptor
 {
+    /** The LoggerFactory used by this Interceptor */
+    private static Logger log = LoggerFactory.getLogger( OperationalAttributeService.class
);
+    
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+    /**
+     * the root nexus of the system
+     */
+    private PartitionNexus nexus;
+
+    /** The attribute registry */
+    private AttributeTypeRegistry registry;
+
+    /** A flag set in configuration if the user want OpAtt to be denormalized */
+    private boolean isDenormalizeOpAttrsEnabled;
+
+    /**
+     * subschemaSubentry attribute's value from Root DSE
+     */
+    private LdapDN subschemaSubentryDn;
+
     private final SearchResultFilter DENORMALIZING_SEARCH_FILTER = new SearchResultFilter()
     {
         public boolean accept( Invocation invocation, SearchResult result, SearchControls
controls ) 
@@ -109,20 +134,32 @@
             return true;
         }
     };
-
+    
+    
     /**
-     * the root nexus of the system
+     * An helper method to add the modifiersname and modifyTimestamp
+     * operational attributes
      */
-    private PartitionNexus nexus;
-
-    private AttributeTypeRegistry registry;
-
-    private boolean isDenormalizeOpAttrsEnabled;
+    private ModificationItemImpl[] addModifyOperationalAttribute( ModificationItemImpl[]
mods, LdapPrincipal principal )
+    {
+        // Copy the current mods into a new array, and adding two elements at the end
+        ModificationItemImpl[] newMods = new ModificationItemImpl[ mods.length + 2 ];
+        System.arraycopy( mods, 0, newMods, 0, mods.length );
+        
+        // Add the modifiersName
+        ModificationItemImpl mod = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,

+            new AttributeImpl( SchemaConstants.MODIFIERS_NAME_AT, principal.getName() ) );
+        mod.modifiedByServer();
+        newMods[mods.length] = mod;
+        
+        // Add the modifyTimestamp
+        mod = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, 
+            new AttributeImpl( SchemaConstants.MODIFY_TIMESTAMP_AT, DateUtils.getGeneralizedTime()
) );
+        mod.modifiedByServer();
+        newMods[mods.length + 1] = mod;
 
-    /**
-     * subschemaSubentry attribute's value from Root DSE
-     */
-    private LdapDN subschemaSubentryDn;
+        return newMods;
+    }
 
     /**
      * Creates the operational attribute management service interceptor.
@@ -132,8 +169,18 @@
     }
 
 
+    /**
+     * Interceptor initialization
+     * 
+     * @see BaseInterceptor#init(DirectoryServiceConfiguration, InterceptorConfiguration)
+     */
     public void init( DirectoryServiceConfiguration factoryCfg, InterceptorConfiguration
cfg ) throws NamingException
     {
+        if ( IS_DEBUG )
+        {
+            log.debug( "Initializing OperationalAttributeService..." );
+        }
+
         nexus = factoryCfg.getPartitionNexus();
         registry = factoryCfg.getRegistries().getAttributeTypeRegistry();
         isDenormalizeOpAttrsEnabled = factoryCfg.getStartupConfiguration().isDenormalizeOpAttrsEnabled();
@@ -142,9 +189,19 @@
         String subschemaSubentry = ( String ) nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT
).get();
         subschemaSubentryDn = new LdapDN( subschemaSubentry );
         subschemaSubentryDn.normalize( factoryCfg.getRegistries().getAttributeTypeRegistry().getNormalizerMapping()
);
+
+        if ( IS_DEBUG )
+        {
+            log.debug( "SchemaService Initialized !" );
+        }
     }
 
 
+    /**
+     * Interceptor teardown
+     * 
+     * @see BaseInterceptor#destroy()
+     */
     public void destroy()
     {
     }
@@ -152,6 +209,12 @@
 
     /**
      * Adds extra operational attributes to the entry before it is added.
+     * 
+     * This method adds those two attroibutes :
+     *  - creatorNames
+     *  - createTimestamp
+     *  
+     *  The creatorNames is the principal
      */
     public void add(NextInterceptor nextInterceptor, AddOperationContext opContext )
         throws NamingException
@@ -159,41 +222,47 @@
         String principal = getPrincipal().getName();
         Attributes entry = opContext.getEntry();
 
-        Attribute attribute = new AttributeImpl( SchemaConstants.CREATORS_NAME_AT );
-        attribute.add( principal );
-        entry.put( attribute );
-
-        attribute = new AttributeImpl( SchemaConstants.CREATE_TIMESTAMP_AT );
-        attribute.add( DateUtils.getGeneralizedTime() );
-        entry.put( attribute );
+        // Add the operational attributes to the entry
+        entry.put( new AttributeImpl( SchemaConstants.CREATORS_NAME_AT, principal ) );
+        entry.put( new AttributeImpl( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime()
) );
 
         nextInterceptor.add( opContext );
     }
     
+    
+    /**
+     * Adds extra operational attributes when an entry is modified.
+     * 
+     * This method adds or modify those two attributes :
+     *  - modifierNames
+     *  - modifyTimestamp
+     *  
+     *  The modifierNames is the principal
+     */
     public void modify( NextInterceptor nextInterceptor, ModifyOperationContext opContext
)
         throws NamingException
     {
-        // -------------------------------------------------------------------
-        // Add the operational attributes for the modifier first
-        // -------------------------------------------------------------------
-
-        List<ModificationItemImpl> modItemList = 
-            new ArrayList<ModificationItemImpl>( opContext.getModItems().length + 2
);
-        Collections.addAll( modItemList, opContext.getModItems() );
+        nextInterceptor.modify( opContext );
+
+        if ( opContext.getDn().getNormName().equals( subschemaSubentryDn.getNormName() )
) 
+        {
+            return;
+        }
         
+        // add operational attributes after call in case the operation fails
+        Attributes attributes = new AttributesImpl( true );
         Attribute attribute = new AttributeImpl( SchemaConstants.MODIFIERS_NAME_AT );
         attribute.add( getPrincipal().getName() );
-        modItemList.add( new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attribute
) );
-        
+        attributes.put( attribute );
+
         attribute = new AttributeImpl( SchemaConstants.MODIFY_TIMESTAMP_AT );
         attribute.add( DateUtils.getGeneralizedTime() );
-        modItemList.add( new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attribute
) );
-
-        // -------------------------------------------------------------------
-        // Make the modify() call happen
-        // -------------------------------------------------------------------
+        attributes.put( attribute );
+        
+        ModificationItemImpl[] items = ModifyOperationContext.createModItems( attributes,
DirContext.REPLACE_ATTRIBUTE );
 
-        nextInterceptor.modify( opContext );
+        ModifyOperationContext newModify = new ModifyOperationContext( opContext.getDn(),
items );
+        nexus.modify( newModify );
     }
 
 
@@ -398,7 +467,7 @@
     }
 
     
-    public void denormalizeEntryOpAttrs( Attributes entry ) throws NamingException
+    private void denormalizeEntryOpAttrs( Attributes entry ) throws NamingException
     {
         if ( isDenormalizeOpAttrsEnabled )
         {
@@ -446,7 +515,7 @@
      * Does not create a new DN but alters existing DN by using the first
      * short name for an attributeType definition.
      */
-    public LdapDN denormalizeTypes( LdapDN dn ) throws NamingException
+    private LdapDN denormalizeTypes( LdapDN dn ) throws NamingException
     {
         LdapDN newDn = new LdapDN();
         

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java?rev=581891&r1=581890&r2=581891&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
Thu Oct  4 06:15:48 2007
@@ -529,14 +529,17 @@
         for ( ModificationItemImpl mod : mods )
         {
             String opAttrOid = globalRegistries.getOidRegistry().getOid( mod.getAttribute().getID()
);
+            
             switch ( mod.getModificationOp() )
             {
                 case( DirContext.ADD_ATTRIBUTE ):
                     modifyAddOperation( opAttrOid, mod.getAttribute(), doCascadeModify );
                     break;
+                    
                 case( DirContext.REMOVE_ATTRIBUTE ):
                     modifyRemoveOperation( opAttrOid, mod.getAttribute(), doCascadeModify
);
                     break; 
+                    
                 case( DirContext.REPLACE_ATTRIBUTE ):
                     throw new LdapOperationNotSupportedException( 
                         "Modify REPLACE operations on schema subentries are not allowed:
" +
@@ -544,6 +547,7 @@
                         "that reside in schema operational attributes.  Instead use \na "
+
                         "targeted combination of modify ADD and REMOVE operations.", 
                         ResultCodeEnum.UNWILLING_TO_PERFORM );
+                
                 default:
                     throw new IllegalStateException( "Undefined modify operation: " + mod.getModificationOp()
);
             }

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=581891&r1=581890&r2=581891&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
Thu Oct  4 06:15:48 2007
@@ -117,12 +117,12 @@
     /** The LoggerFactory used by this Interceptor */
     private static Logger log = LoggerFactory.getLogger( SchemaService.class );
 
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = log.isDebugEnabled();
+
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
     private static final String BINARY_KEY = JndiPropertyConstants.JNDI_LDAP_ATTRIBUTES_BINARY;
 
-
-    /** Speedup for logs */
-    private static final boolean IS_DEBUG = log.isDebugEnabled();
 
     /**
      * the root nexus to all database partitions

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java?rev=581891&r1=581890&r2=581891&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/ModificationItemImpl.java
Thu Oct  4 06:15:48 2007
@@ -40,6 +40,13 @@
 public class ModificationItemImpl extends ModificationItem
 {
     private static final long serialVersionUID = 1L;
+    
+    /** 
+     * A special flag set to false by default, used to indicate
+     * that some modification has been done by the server. Usefull
+     * for Operationnal Attributes.
+     */
+    private boolean modifiedByServer;
 
     /**
      * Create a modificationItemImpl
@@ -52,6 +59,7 @@
     public ModificationItemImpl( int modificationOp, Attribute attribute ) 
     {
         super( modificationOp, AttributeUtils.toAttributeImpl( attribute ) );
+        modifiedByServer = false;
     }
     
     /**
@@ -66,6 +74,7 @@
     {
         super( modification.getModificationOp(), 
             AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+        modifiedByServer = false;
     }
     
     /**
@@ -76,6 +85,7 @@
     {
         super( modification.getModificationOp(), 
             AttributeUtils.toAttributeImpl( modification.getAttribute() ) );
+        modifiedByServer = false;
     }
     
     /**
@@ -104,6 +114,32 @@
         return new ModificationItemImpl( getModificationOp(), (Attribute)getAttribute().clone()
); 
     }
     
+
+    /**
+     * 
+     * tells if the modification has been done by the server
+     *
+     * @return <code>true</code> if the server has modified this attribute
+     */
+    public boolean isModifiedByServer()
+    {
+        return modifiedByServer;
+    }
+
+    
+    /**
+     * 
+     * Method called when the server modifies an operationnal
+     * attribute, as we must protect the attribute from being
+     * checked by the SchemaService interceptor
+     *
+     */
+    public void modifiedByServer()
+    {
+        modifiedByServer = true;
+    }
+
+    
     /**
      * @see Object#toString()
      */
@@ -111,7 +147,14 @@
     {
         StringBuffer sb = new StringBuffer();
         
-        sb.append( "ModificationItem : \n" );
+        sb.append( "ModificationItem" );
+        
+        if ( modifiedByServer )
+        {
+            sb.append( "[Op]" );
+        }
+        
+        sb.append( " : \n" );
         
         switch ( getModificationOp() )
         {



Mime
View raw message