directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1032953 - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/operational/ core/src/main/java/org/apache/directory/server/core/partition/ core/src/main/java/org/apache/directory/server/core/schema/ ldap-client...
Date Tue, 09 Nov 2010 12:15:09 GMT
Author: kayyagari
Date: Tue Nov  9 12:15:09 2010
New Revision: 1032953

URL: http://svn.apache.org/viewvc?rev=1032953&view=rev
Log:
o update entryCSN attribute during modify operation (earlier this was handled in DefaultPartitionNexus)
o updated the test case

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=1032953&r1=1032952&r2=1032953&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
Tue Nov  9 12:15:09 2010
@@ -120,7 +120,7 @@ public class OperationalAttributeInterce
 
     private static AttributeType MODIFIERS_NAME_ATTRIBUTE_TYPE;
     private static AttributeType MODIFY_TIMESTAMP_ATTRIBUTE_TYPE;
-
+    private static AttributeType ENTRY_CSN_ATTRIBUTE_TYPE;
 
     /**
      * Creates the operational attribute management service interceptor.
@@ -145,6 +145,7 @@ public class OperationalAttributeInterce
 
         MODIFIERS_NAME_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.MODIFIERS_NAME_AT
);
         MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.MODIFY_TIMESTAMP_AT
);
+        ENTRY_CSN_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT
);
     }
 
 
@@ -253,7 +254,8 @@ public class OperationalAttributeInterce
 
         boolean modifierAtPresent = false;
         boolean modifiedTimeAtPresent = false;
-
+        boolean entryCsnAtPresent = false;
+        
         for ( Modification modification : mods )
         {
             AttributeType attributeType = modification.getAttribute().getAttributeType();
@@ -286,6 +288,20 @@ public class OperationalAttributeInterce
                 }
             }
 
+            if ( attributeType.equals( ENTRY_CSN_ATTRIBUTE_TYPE ) )
+            {
+                if ( !isAdmin )
+                {
+                    String message = I18n.err( I18n.ERR_32 );
+                    LOG.error( message );
+                    throw new LdapSchemaViolationException( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS,
message );
+                }
+                else
+                {
+                    entryCsnAtPresent = true;
+                }
+            }
+
             if ( PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType ) && !isAdmin
)
             {
                 String message = I18n.err( I18n.ERR_32 );
@@ -316,6 +332,14 @@ public class OperationalAttributeInterce
             mods.add( timestamp );
         }
 
+        if ( !entryCsnAtPresent )
+        {
+            String csn = service.getCSN().toString();
+            EntryAttribute attribute = new DefaultEntryAttribute( ENTRY_CSN_ATTRIBUTE_TYPE,
csn );
+            Modification updatedCsn = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
attribute );
+            mods.add( updatedCsn );
+        }
+        
         // Go down in the chain
         nextInterceptor.modify( modifyContext );
     }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=1032953&r1=1032952&r2=1032953&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
Tue Nov  9 12:15:09 2010
@@ -650,13 +650,14 @@ public class DefaultPartitionNexus exten
 
         Partition backend = getPartition( modifyContext.getDn() );
 
-        String csn = directoryService.getCSN().toString();
-        EntryAttribute attribute = new DefaultEntryAttribute( ENTRY_CSN_AT, csn );
-        Modification updatedCsn = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
attribute );
-        modifyContext.getModItems().add( updatedCsn );
-
         backend.modify( modifyContext );
-        directoryService.setContextCsn( csn );
+        
+        Entry alteredEntry = modifyContext.getAlteredEntry();
+        
+        if ( alteredEntry != null )
+        {
+            directoryService.setContextCsn( alteredEntry.get( ENTRY_CSN_AT ).getString()
);
+        }
     }
 
 

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=1032953&r1=1032952&r2=1032953&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
Tue Nov  9 12:15:09 2010
@@ -169,6 +169,7 @@ public class SchemaInterceptor extends B
 
     private static AttributeType MODIFIERS_NAME_ATTRIBUTE_TYPE;
     private static AttributeType MODIFY_TIMESTAMP_ATTRIBUTE_TYPE;
+    private static AttributeType ENTRY_CSN_ATTRIBUTE_TYPE;
 
 
     /**
@@ -212,7 +213,8 @@ public class SchemaInterceptor extends B
 
         MODIFIERS_NAME_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.MODIFIERS_NAME_AT
);
         MODIFY_TIMESTAMP_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.MODIFY_TIMESTAMP_AT
);
-
+        ENTRY_CSN_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT
);
+        
         if ( IS_DEBUG )
         {
             LOG.debug( "SchemaInterceptor Initialized !" );
@@ -1046,6 +1048,7 @@ public class SchemaInterceptor extends B
             if ( !attributeType.isUserModifiable()
                 && ( !attributeType.equals( MODIFIERS_NAME_ATTRIBUTE_TYPE )
                 && ( !attributeType.equals( MODIFY_TIMESTAMP_ATTRIBUTE_TYPE ) )
+                && ( !attributeType.equals( ENTRY_CSN_ATTRIBUTE_TYPE ) )
                 && ( !PWD_POLICY_STATE_ATTRIBUTE_TYPES.contains( attributeType )
) ) )
             {
                 String msg = I18n.err( I18n.ERR_52, attributeType );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java?rev=1032953&r1=1032952&r2=1032953&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryManager.java
Tue Nov  9 12:15:09 2010
@@ -22,6 +22,8 @@ package org.apache.directory.server.core
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -94,6 +96,8 @@ public class SchemaSubentryManager
     private static final String CASCADING_ERROR =
             "Cascading has not yet been implemented: standard operation is in effect.";
 
+    private static AttributeType ENTRY_CSN_ATTRIBUTE_TYPE;
+    
     static 
     {
         VALID_OU_VALUES.add( SchemaConstants.NORMALIZERS_AT.toLowerCase() );
@@ -149,6 +153,8 @@ public class SchemaSubentryManager
 
         String nameFormsOid = schemaManager.getAttributeTypeRegistry().getOidByName( SchemaConstants.NAME_FORMS_AT
);
         opAttr2handlerIndex.put( nameFormsOid, NAME_FORM_INDEX );
+        
+        ENTRY_CSN_ATTRIBUTE_TYPE = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT
);
     }
 
     
@@ -174,6 +180,12 @@ public class SchemaSubentryManager
                     break; 
                     
                 case REPLACE_ATTRIBUTE :
+                    // a hack to allow entryCSN modification
+                    if ( ENTRY_CSN_ATTRIBUTE_TYPE.equals( serverAttribute.getAttributeType()
) )
+                    {
+                        break;
+                    }
+
                     throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM,

                         I18n.err( I18n.ERR_283 ) );
                 

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java?rev=1032953&r1=1032952&r2=1032953&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java
Tue Nov  9 12:15:09 2010
@@ -36,6 +36,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -48,7 +49,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.message.ModifyRequestImpl;
 import org.apache.directory.shared.ldap.message.ModifyResponse;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.message.SearchResultEntry;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.DateUtils;
 import org.junit.After;
@@ -65,6 +65,16 @@ import org.junit.runner.RunWith;
 @RunWith(FrameworkRunner.class)
 @CreateLdapServer(transports =
     { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
+@ApplyLdifs({
+    "dn: uid=billyd,ou=users,ou=system",
+    "objectClass: person",
+    "objectClass: organizationalPerson",
+    "objectClass: inetOrgPerson",
+    "uid: billyd",
+    "userPassword: secret",
+    "sn: billyd",
+    "cn: billyd"
+})
 public class ClientModifyRequestTest extends AbstractLdapTestUnit
 {
     private LdapAsyncConnection connection;
@@ -233,6 +243,18 @@ public class ClientModifyRequestTest ext
         modifyRequest.setName( dn );
         modifyRequest.replace( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString()
);
 
+        // admin can modify the entryCsn
+        modResp = connection.modify( modifyRequest );
+        assertEquals( ResultCodeEnum.SUCCESS, modResp.getLdapResult().getResultCode() );
+
+        connection.close();
+        
+        connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+
+        DN bindDn = new DN( "uid=billyd,ou=users,ou=system" );
+        connection.bind( bindDn.getName(), "secret" );
+        
+        // non-admin user cannot modify entryCSN
         modResp = connection.modify( modifyRequest );
         assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, modResp.getLdapResult().getResultCode()
);
     }



Mime
View raw message