directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r894859 - in /directory/apacheds/branches/apacheds-schema: core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Date Thu, 31 Dec 2009 15:07:38 GMT
Author: elecharny
Date: Thu Dec 31 15:07:37 2009
New Revision: 894859

URL: http://svn.apache.org/viewvc?rev=894859&view=rev
Log:
Fixed a failing tests in which we were trying to update an OpAttr NO_USER_MODIFIABLE

Modified:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/branches/apacheds-schema/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=894859&r1=894858&r2=894859&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
Thu Dec 31 15:07:37 2009
@@ -27,6 +27,7 @@
 import java.util.UUID;
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
+import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.entry.DefaultServerAttribute;
@@ -197,11 +198,45 @@
         // Add the UUID and the entryCSN. The UUID is stored as a byte[] representation of

         // its String value
         // @TODO : If we are using replication, those four OAs may be already present.
-        // We have to deal with this as soon as we have the replication working again.
+        // We have to deal with this as soon as we have the replication working again
+        
+        // Check that we don't have an entryUUID AT in the incoming entry, as it's a NO-USER-MODIFICATION
AT
+        // Of course, we will allow if for replication (see above @TODO)
+        boolean isAdmin = opContext.getSession().getAuthenticatedPrincipal().getName().equals(

+            ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+        
+        if ( entry.containsAttribute( SchemaConstants.ENTRY_UUID_AT ) )
+        {
+            if ( !isAdmin )
+            {
+                // Wrong !
+                String message = "The " + SchemaConstants.ENTRY_UUID_AT + " operational attribute
cannot be modified by a user";
+                LOG.error( message );
+                throw new LdapSchemaViolationException( message, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS
);
+            }
+        }
+        else
+        {
+            entry.put( SchemaConstants.ENTRY_UUID_AT, SchemaUtils.uuidToBytes( UUID.randomUUID()
) );
+        }
+            
+        if ( entry.containsAttribute( SchemaConstants.ENTRY_CSN_AT ) )
+        {
+            if ( !isAdmin )
+            {
+                // Wrong !
+                String message = "The " + SchemaConstants.ENTRY_CSN_AT + " operational attribute
cannot be modified by a user";
+                LOG.error( message );
+                throw new LdapSchemaViolationException( message, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS
);
+            }
+        }
+        else
+        {
+            entry.put( SchemaConstants.ENTRY_CSN_AT, service.getCSN().toString() );
+        }
+        
         entry.put( SchemaConstants.CREATORS_NAME_AT, principal );
         entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
-        entry.put( SchemaConstants.ENTRY_UUID_AT, SchemaUtils.uuidToBytes( UUID.randomUUID()
) );
-        entry.put( SchemaConstants.ENTRY_CSN_AT, service.getCSN().toString() );
         
         nextInterceptor.add( opContext );
     }

Modified: directory/apacheds/branches/apacheds-schema/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=894859&r1=894858&r2=894859&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Thu Dec 31 15:07:37 2009
@@ -1208,6 +1208,24 @@
     }
     
     
+    private UUID getUUIDFromBytes( byte[] data ) 
+    {
+        long msb = 0;
+        long lsb = 0;
+        for (int i=0; i<8; i++)
+        {
+            msb = (msb << 8) | (data[i] & 0xff);
+        }
+        
+        for (int i=8; i<16; i++)
+        {
+            lsb = (lsb << 8) | (data[i] & 0xff);
+        }
+        
+        return new UUID( msb, lsb );
+    }
+
+    
     @Test
     public void testAddEntryUUIDAndCSNAttributes() throws Exception
     {
@@ -1235,13 +1253,13 @@
         con.add( kate );
 
         // Analyze entry and description attribute
-        LDAPEntry addedEntry = con.read( dn );
+        LDAPEntry addedEntry = con.read( dn, new String[]{ "*", "+"} );
         assertNotNull( addedEntry );
-        //FIXME the LDAPConnection is not able to read the ENTRY_UUID_AT
+
         LDAPAttribute attr = addedEntry.getAttribute( SchemaConstants.ENTRY_UUID_AT );
         assertNotNull( attr );
-        System.out.println( attr.getByteValueArray()[0] );
-        assertEquals( uuid, UUID.nameUUIDFromBytes( attr.getByteValueArray()[0] ) );
+        
+        assertEquals( uuid, getUUIDFromBytes( attr.getByteValueArray()[0] ) );
 
         attr = addedEntry.getAttribute( SchemaConstants.ENTRY_CSN_AT );
         assertNotNull( attr );



Mime
View raw message