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 2008/08/16 01:22:11 UTC

svn commit: r686416 - in /directory: apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/ apacheds/branches/bigbang/jdbm-stor...

Author: elecharny
Date: Fri Aug 15 16:22:10 2008
New Revision: 686416

URL: http://svn.apache.org/viewvc?rev=686416&view=rev
Log:
o Fixed 3 tests in ModifyRDNItest ( cf DIRSERVER-1223)
o Fixed the RDN.unescapeValue() method to corretly handle spaces and # in the middle of a value
o Added some tests for this fix
o The value created when doing a rename is now normalized and unescaped
o If a entry is created with an operational attribute as its RDN, the revert operation will now work as it is applied by the admin (added some code to handle this case).

Modified:
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java Fri Aug 15 16:22:10 2008
@@ -296,6 +296,7 @@
         LdifEntry forward = new LdifEntry();
         forward.setChangeType( ChangeType.ModRdn );
         forward.setDn( renameContext.getDn() );
+        forward.setNewRdn( renameContext.getNewRdn().getUpName() );
         forward.setDeleteOldRdn( renameContext.getDelOldDn() );
 
         LdifEntry reverse = LdifUtils.reverseModifyRdn( ServerEntryUtils.toAttributesImpl( serverEntry ), 

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java Fri Aug 15 16:22:10 2008
@@ -27,6 +27,7 @@
 import java.util.Set;
 
 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;
@@ -48,20 +49,27 @@
 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.core.schema.SchemaInterceptor;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.codec.LdapConstants;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 import org.apache.directory.shared.ldap.util.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import javax.naming.InsufficientResourcesException;
 import javax.naming.directory.SearchControls;
  
 
@@ -78,6 +86,9 @@
  */
 public class OperationalAttributeInterceptor extends BaseInterceptor
 {
+    /** The LoggerFactory used by this Interceptor */
+    private static Logger LOG = LoggerFactory.getLogger( OperationalAttributeInterceptor.class );
+
     private final EntryFilter DENORMALIZING_SEARCH_FILTER = new EntryFilter()
     {
         public boolean accept( SearchingOperationContext operation, ClonedServerEntry serverEntry ) 
@@ -112,7 +123,10 @@
 
     private LdapDN subschemaSubentryDn;
     
+    /** The registries */
     private Registries registries;
+    
+    private static AttributeType CREATE_TIMESTAMP_ATTRIBUTE_TYPE;
 
 
     /**
@@ -133,7 +147,9 @@
         Value<?> subschemaSubentry = service.getPartitionNexus()
                 .getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
         subschemaSubentryDn = new LdapDN( (String)subschemaSubentry.get() );
-        subschemaSubentryDn.normalize( directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+        subschemaSubentryDn.normalize( atRegistry.getNormalizerMapping() );
+        
+        CREATE_TIMESTAMP_ATTRIBUTE_TYPE = atRegistry.lookup( SchemaConstants.CREATE_TIMESTAMP_AT );
     }
 
 
@@ -153,7 +169,29 @@
         ServerEntry entry = opContext.getEntry();
 
         entry.put( SchemaConstants.CREATORS_NAME_AT, principal );
-        entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        
+        EntryAttribute createTimeStamp = new DefaultServerAttribute( CREATE_TIMESTAMP_ATTRIBUTE_TYPE );
+        
+        if ( opContext.getEntry().contains( createTimeStamp ) )
+        {
+            // As we already have a CreateTimeStamp value in the context, use it, but only if
+            // the principal is admin
+            if ( opContext.getSession().getAuthenticatedPrincipal().getName().equals( 
+                ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED ))
+            {
+                entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+            }
+            else
+            {
+                String message = "The CreateTimeStamp attribute cannot be created by a user";
+                LOG.error( message );
+                throw new LdapSchemaViolationException( message, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
+            }
+        }
+        else
+        {
+            entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+        }
         
         nextInterceptor.add( opContext );
     }

Modified: directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/branches/bigbang/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Fri Aug 15 16:22:10 2008
@@ -39,6 +39,7 @@
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.entry.ServerAttribute;
+import org.apache.directory.server.core.entry.ServerBinaryValue;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerStringValue;
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
@@ -1550,7 +1551,23 @@
             String newNormType = newAtav.getNormType();
             String newNormValue = ( String ) newAtav.getNormValue();
             AttributeType newRdnAttrType = attributeTypeRegistry.lookup( newNormType );
-            entry.add( newRdnAttrType, ( String ) newAtav.getUpValue() );
+            
+            Object unEscapedRdn = Rdn.unescapeValue( (String)newAtav.getUpValue() );
+            
+            Value<?> value = null;
+            
+            if ( unEscapedRdn instanceof String )
+            {
+                value = new ServerStringValue( newRdnAttrType, (String)unEscapedRdn );
+            }
+            else
+            {
+                value = new ServerBinaryValue( newRdnAttrType, (byte[])unEscapedRdn );
+            }
+            
+            value.normalize();
+            
+            entry.add( newRdnAttrType, value );
 
             if ( hasUserIndexOn( newNormType ) )
             {

Modified: directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java (original)
+++ directory/apacheds/branches/bigbang/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyRdnIT.java Fri Aug 15 16:22:10 2008
@@ -459,7 +459,7 @@
      * Ensure that the attribute itself contains the unescaped value.
      */
     @Test
-    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
+    //@Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
     public void testModifyRdnWithEncodedNewRdn() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE );
@@ -499,7 +499,8 @@
         // Check that cn contains the unescaped value
         Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
         assertEquals( "Number of cn occurences", 1, cn.size() );
-        assertTrue( cn.contains( newCnEscapedVal ) );
+        String expectedCn = new String( new byte[] { ( byte ) 0xC3, ( byte ) 0xA4, '+' }, "UTF-8" );
+        assertTrue( cn.contains( expectedCn ) );
 
         // Remove entry (use new rdn)
         ctx.unbind( newRdn );
@@ -512,7 +513,7 @@
      * Ensure that the attribute itself contains the unescaped value.
      */
     @Test
-    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
+    //@Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
     public void testModifyRdnWithEscapedPoundNewRdn() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE );
@@ -550,7 +551,7 @@
         // Check that cn contains the unescaped value
         Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
         assertEquals( "Number of cn occurences", 1, cn.size() );
-        assertTrue( cn.contains( "\\#test" ) );
+        assertTrue( cn.contains( "#test" ) );
 
         // Remove entry (use new rdn)
         ctx.unbind( newRdn );
@@ -729,7 +730,7 @@
      * @throws NamingException
      */
     @Test
-    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
+    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1231" )
     public void testModifyMultiValuedRdnVariant5() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE );
@@ -776,7 +777,7 @@
      * @throws NamingException
      */
     @Test
-    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1216" )
+    @Ignore ( "Until this is fixed: https://issues.apache.org/jira/browse/DIRSERVER-1231" )
     public void testModifyMultiValuedRdnVariant6() throws Exception
     {
         DirContext ctx = ( DirContext ) getWiredContext( ldapServer ).lookup( BASE );

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Fri Aug 15 16:22:10 2008
@@ -1162,14 +1162,37 @@
                            case '<':
                            case '>':
                            case '#':
+                               if ( i != 0)
+                               {
+                                   // '#' are allowed if not in first position
+                                   bytes[pos++] = '#';
+                                   break;
+                               }
                            case '=':
-                           case ' ':
                                throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
 
+                           case ' ':
+                               if ( ( i == 0 ) || ( i == chars.length - 1) )
+                               {
+                                   throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
+                               }
+                               else
+                               {
+                                   bytes[pos++] = ' ';
+                                   break;
+                               }
+
                            default:
-                               byte[] result = StringTools.charToBytes( chars[i] );
-                               System.arraycopy( result, 0, bytes, pos, result.length );
-                               pos += result.length;
+                               if ( ( chars[i] >= 0 ) && ( chars[i] < 128 ) )
+                               {
+                                   bytes[pos++] = (byte)chars[i];
+                               }
+                               else
+                               {
+                                   byte[] result = StringTools.charToBytes( chars[i] );
+                                   System.arraycopy( result, 0, bytes, pos, result.length );
+                                   pos += result.length;
+                               }
                                
                                break;
                        }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=686416&r1=686415&r2=686416&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java Fri Aug 15 16:22:10 2008
@@ -758,6 +758,51 @@
 
 
     @Test
+    public void testUnescapeValueStringWithSpaceInTheMiddle()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a b" );
+
+        assertEquals( "a b", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithSpaceInAtTheBeginning()
+    {
+        String res = ( String ) Rdn.unescapeValue( "\\ a b" );
+
+        assertEquals( " a b", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithSpaceInAtTheEnd()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a b\\ " );
+
+        assertEquals( "a b ", res );
+    }
+    
+    
+    @Test
+    public void testUnescapeValueStringWithPoundInTheMiddle()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a#b" );
+
+        assertEquals( "a#b", res );
+    }
+    
+    
+    @Test
+    public void testUnescapeValueStringWithPoundAtTheEnd()
+    {
+        String res = ( String ) Rdn.unescapeValue( "ab#" );
+
+        assertEquals( "ab#", res );
+    }
+    
+    
+    @Test
     public void testEscapeValueString()
     {
         String res = Rdn.escapeValue( StringTools.getBytesUtf8( "azerty" ) );