directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r771954 - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/normalization/ core/src/main/java/org/apache/directory/server/core/schema/ server-integ/src/test/java/org/apache/directory/server/operations/add/
Date Tue, 05 May 2009 18:26:37 GMT
Author: seelmann
Date: Tue May  5 18:26:37 2009
New Revision: 771954

URL: http://svn.apache.org/viewvc?rev=771954&view=rev
Log:
Fix for DIRSERVER-1311: add unescaped RDN value to the entry; moved code from SchemaIntercepter#check()
to NormalizationInterceptor

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=771954&r1=771953&r2=771954&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
Tue May  5 18:26:37 2009
@@ -49,8 +49,11 @@
 import org.apache.directory.server.schema.registries.OidRegistry;
 import org.apache.directory.shared.ldap.cursor.EmptyCursor;
 import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -110,6 +113,7 @@
     {
         opContext.getDn().normalize( attrNormalizers );
         opContext.getEntry().getDn().normalize( attrNormalizers );
+        addRdnAttributesToEntry( opContext.getDn(), opContext.getEntry() );
         nextInterceptor.add( opContext );
     }
 
@@ -277,4 +281,85 @@
         opContext.getDn().normalize( attrNormalizers );
         next.removeContextPartition( opContext );
     }
+
+
+    /**
+     * Adds missing RDN's attributes and values to the entry.
+     *
+     * @param dn the DN
+     * @param entry the entry
+     */
+    private void addRdnAttributesToEntry( LdapDN dn, ServerEntry entry ) throws Exception
+    {
+        if ( dn == null || entry == null )
+        {
+            return;
+        }
+
+        Rdn rdn = dn.getRdn();
+
+        // Loop on all the AVAs
+        for ( AttributeTypeAndValue ava : rdn )
+        {
+            String value = ( String ) ava.getNormValue();
+            String upValue = ( String ) ava.getUpValue();
+            String upId = ava.getUpType();
+
+            // Check that the entry contains this AVA
+            if ( !entry.contains( upId, value ) )
+            {
+                String message = "The RDN '" + upId + "=" + upValue + "' is not present in
the entry";
+                LOG.warn( message );
+
+                // We don't have this attribute : add it.
+                // Two cases : 
+                // 1) The attribute does not exist
+                if ( !entry.containsAttribute( upId ) )
+                {
+                    addUnescapedUpValue( entry, upId, upValue );
+                }
+                // 2) The attribute exists
+                else
+                {
+                    AttributeType at = attributeRegistry.lookup( upId );
+
+                    // 2.1 if the attribute is single valued, replace the value
+                    if ( at.isSingleValue() )
+                    {
+                        entry.removeAttributes( upId );
+                        addUnescapedUpValue( entry, upId, upValue );
+                    }
+                    // 2.2 the attribute is multi-valued : add the missing value
+                    else
+                    {
+                        addUnescapedUpValue( entry, upId, upValue );
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Adds the user provided value to the given entry.
+     * If the user provided value is string value it is unescaped first. 
+     * If the user provided value is a hex string the value is added as byte[].
+     *
+     * @param entry the entry
+     * @param upId the user provided attribute type to add
+     * @param upValue the user provided value to add
+     */
+    private void addUnescapedUpValue( ServerEntry entry, String upId, String upValue ) throws
Exception
+    {
+        Object unescapedUpValue = Rdn.unescapeValue( upValue );
+        if ( unescapedUpValue instanceof String )
+        {
+            entry.add( upId, ( String ) unescapedUpValue );
+        }
+        else
+        {
+            entry.add( upId, ( byte[] ) unescapedUpValue );
+        }
+    }
+
 }

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=771954&r1=771953&r2=771954&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 May  5 18:26:37 2009
@@ -1137,6 +1137,12 @@
         boolean deleteOldRn = opContext.getDelOldDn();
         ServerEntry entry = opContext.lookup( name, ByPassConstants.LOOKUP_BYPASS );
 
+        /*
+         *  Note: This is only a consistency checks, to the ensure that all
+         *  mandatory attributes are available after deleting the old RDN.
+         *  The real modification is done in the JdbmStore class.
+         *  - TODO: this check is missing in the moveAndRename() method
+         */
         if ( deleteOldRn )
         {
             ServerEntry tmpEntry = ( ServerEntry ) entry.clone();
@@ -1665,7 +1671,6 @@
         // 3-1) Except if the extensibleObject ObjectClass is used
         // 3-2) or if the AttributeType is COLLECTIVE
         // 4) We also check that for H-R attributes, we have a valid String in the values
-        // 5) We last check that the entry has it's RDN values as attributes  
         EntryAttribute objectClassAttr = entry.get( SchemaConstants.OBJECT_CLASS_AT );
 
         // Protect the server against a null objectClassAttr
@@ -1703,52 +1708,9 @@
 
         // Now check the syntaxes
         assertSyntaxes( entry );
+    }
 
-        // Last, check that the RDN's values are attributes in the entry
-        Rdn rdn = entry.getDn().getRdn();
 
-        // Loop on all the AVAs
-        for ( AttributeTypeAndValue ava : rdn )
-        {
-            String value = ( String ) ava.getNormValue();
-            String upValue = ( String ) ava.getUpValue();
-            String upId = ava.getUpType();
-
-            // Check that the entry contains this AVA
-            if ( !entry.contains( upId, value ) )
-            {
-                String message = "The RDN '" + upId + "=" + upValue + "' is not present in
the entry";
-                LOG.warn( message );
-                
-                // We don't have this attribute : add it.
-                // Two cases : 
-                // 1) The attribute does not exist
-                if ( !entry.containsAttribute( upId ) )
-                {
-                    entry.add( upId, upValue );
-                }
-                // 2) The attribute exists
-                else
-                {
-                    AttributeType at = atRegistry.lookup( upId );
-                    
-                    // 2.1 if the attribute is single valued, replace the value
-                    if ( at.isSingleValue() )
-                    {
-                        entry.removeAttributes( upId );
-                        entry.put( upId, upValue );
-                    }
-                    // 2.2 the attribute is multi-valued : add the missing value
-                    else
-                    {
-                        entry.add( upId, upValue );
-                    }
-                }
-            }
-        }
-    }
-    
-    
     private void checkOcSuperior( ServerEntry entry ) throws Exception
     {
         ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java?rev=771954&r1=771953&r2=771954&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
Tue May  5 18:26:37 2009
@@ -20,6 +20,15 @@
 package org.apache.directory.server.operations.add;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.util.HashSet;
 import java.util.Set;
 
@@ -66,11 +75,6 @@
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.integ.LdapServerFactory;
 import org.apache.directory.server.integ.SiRunner;
-
-import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredConnection;
-import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
-import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContextThrowOnRefferal;
-
 import org.apache.directory.server.ldap.LdapService;
 import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
@@ -79,18 +83,13 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.mina.util.AvailablePortFinder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
 
 /**
  * Various add scenario tests.
@@ -1179,4 +1178,71 @@
 
         assertNotNull( newOcls );
     }
+
+
+    /**
+     * Test for DIRSERVER-1311: If the RDN attribute+value is not present
+     * in the entry the server should implicit add this attribute+value to
+     * the entry. Additionally, if the RDN value is escaped or a hexstring
+     * the server must add the unescaped string or binary value to the entry.
+     */
+    @Test
+    public void testAddUnescapedRdnValue_DIRSERVER_1311() throws Exception
+    {
+        LdapContext ctx = ( LdapContext ) getWiredContext( ldapService ).lookup( BASE );
+
+        Attributes tori = new BasicAttributes( true );
+        Attribute toriOC = new BasicAttribute( "objectClass" );
+        toriOC.add( "top" );
+        toriOC.add( "person" );
+        tori.put( toriOC );
+        tori.put( "cn", "Tori Amos" );
+        tori.put( "sn", "Amos" );
+        /*
+         * Note that the RDN attribute is different to the cn specified in the entry.
+         * This creates a second cn attribute "cn:Amos,Tori". This is a JNDI hack:
+         * If no other cn is available in the entry, JNDI adds the RDN 
+         * attribute to the entry before sending the request to the server.
+         */
+        ctx.createSubcontext( " cn = Amos\\,Tori ", tori );
+
+        Attributes binary = new BasicAttributes( true );
+        Attribute binaryOC = new BasicAttribute( "objectClass" );
+        binaryOC.add( "top" );
+        binaryOC.add( "person" );
+        binary.put( binaryOC );
+        binary.put( "cn", "Binary" );
+        binary.put( "sn", "Binary" );
+        binary.put( "userPassword", "test" );
+        /*
+         * Note that the RDN attribute is different to the userPassword specified 
+         * in the entry. This creates a second cn attribute "userPassword:#414243". 
+         * This is a JNDI hack:
+         * If no other userPassword is available in the entry, JNDI adds the RDN 
+         * attribute to the entry before sending the request to the server.
+         */
+        ctx.createSubcontext( " userPassword = #414243 ", binary );
+
+        SearchControls controls = new SearchControls();
+        NamingEnumeration<SearchResult> res;
+
+        // search for the implicit added cn
+        res = ctx.search( "", "(cn=Amos,Tori)", controls );
+        assertTrue( res.hasMore() );
+        Attribute cnAttribute = res.next().getAttributes().get( "cn" );
+        assertEquals( 2, cnAttribute.size() );
+        assertTrue( cnAttribute.contains( "Tori Amos" ) );
+        assertTrue( cnAttribute.contains( "Amos,Tori" ) );
+        assertFalse( res.hasMore() );
+
+        // search for the implicit added userPassword
+        res = ctx.search( "", "(userPassword=\\41\\42\\43)", controls );
+        assertTrue( res.hasMore() );
+        Attribute userPasswordAttribute = res.next().getAttributes().get( "userPassword"
);
+        assertEquals( 2, userPasswordAttribute.size() );
+        assertTrue( userPasswordAttribute.contains( StringTools.getBytesUtf8( "test" ) )
);
+        assertTrue( userPasswordAttribute.contains( StringTools.getBytesUtf8( "ABC" ) ) );
+        assertFalse( res.hasMore() );
+    }
+
 }



Mime
View raw message