directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r917174 - in /directory/apacheds/trunk: server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
Date Sun, 28 Feb 2010 13:00:21 GMT
Author: kayyagari
Date: Sun Feb 28 13:00:20 2010
New Revision: 917174

URL: http://svn.apache.org/viewvc?rev=917174&view=rev
Log:
fix for DIRSERVER-1401

Modified:
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java
    directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java

Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java?rev=917174&r1=917173&r2=917174&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java
(original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/MoveIT.java
Sun Feb 28 13:00:20 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.server.operations.modifydn;
 
 
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getClientApiConnection;
 import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -30,11 +31,17 @@
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.ModifyDnRequest;
+import org.apache.directory.ldap.client.api.message.ModifyDnResponse;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 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.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.RDN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -65,7 +72,19 @@
     "dn: ou=NewSuperior,ou=system",
     "objectClass: organizationalUnit",
     "objectClass: top",
-    "ou: NewSuperior"
+    "ou: NewSuperior",
+    
+    "dn: ou=parent,ou=system",
+    "changetype: add",
+    "objectClass: organizationalUnit",
+    "objectClass: top",
+    "ou: parent",
+    
+    "dn: ou=child,ou=parent,ou=system",
+    "changetype: add",
+    "objectClass: organizationalUnit",
+    "objectClass: top",
+    "ou: child"
     }
 )
 public class MoveIT extends AbstractLdapTestUnit 
@@ -118,9 +137,27 @@
         ctx.close();
     }
     
+    
     @Test
-    public void testDummy()
+    public void testIllegalMove() throws Exception
     {
-        
+
+    	LdapConnection con = getClientApiConnection( ldapServer );
+    
+    	//now do something bad: make the parent a child of its own child 
+    	ModifyDnResponse resp = con.move( "ou=parent,ou=system", "ou=child,ou=parent,ou=system"
);
+    	assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, resp.getLdapResult().getResultCode()
);
     }
+    
+    
+    @Test
+    public void testIllegalMoveToSameDN() throws Exception
+    {
+
+    	LdapConnection con = getClientApiConnection( ldapServer );
+    
+    	//now do something bad: try to move the entry to the same DN
+    	ModifyDnResponse resp = con.move( "ou=parent,ou=system", "ou=parent,ou=system" );
+        assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, resp.getLdapResult().getResultCode()
);
+    }    
 }

Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java?rev=917174&r1=917173&r2=917174&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
(original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
Sun Feb 28 13:00:20 2010
@@ -35,6 +35,7 @@
 import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
@@ -370,6 +371,7 @@
 
     public final void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext )
throws Exception
     {
+        checkIsValidMove( moveAndRenameContext.getDn(), moveAndRenameContext.getParent()
);
         store.move( moveAndRenameContext.getDn(), moveAndRenameContext.getParent(), moveAndRenameContext.getNewRdn(),
             moveAndRenameContext.getDelOldDn() );
     }
@@ -377,10 +379,52 @@
 
     public final void move( MoveOperationContext moveContext ) throws Exception
     {
+        checkIsValidMove( moveContext.getDn(), moveContext.getParent() );
         store.move( moveContext.getDn(), moveContext.getParent() );
     }
 
+    
+    /**
+     * 
+     * checks whether the moving of given entry is valid
+     *
+     * @param oldChildDn the entry's DN to be moved
+     * @param newParentDn new parent entry's DN
+     * @throws Exception
+     */
+    private void checkIsValidMove( LdapDN oldChildDn, LdapDN newParentDn ) throws Exception
+    {
+        Long newParentId = getEntryId( newParentDn.toString() );
+        Long childId = getEntryId( oldChildDn.toString() );
+        Long oldParentId = getParentId( childId );
+        
+        if( childId.longValue() == newParentId.longValue() )
+        {
+            throw new LdapOperationNotSupportedException( "child entry DN cannot be same
as parent entry DN", ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        IndexCursor idxCursor = getSubLevelIndex().forwardCursor( childId );
+        boolean invalid = false;
+        while( idxCursor.next() )
+        {
+            ForwardIndexEntry<Long, Long> fwdIdxEntry = ( ForwardIndexEntry<Long,
Long> ) idxCursor.get();
+            
+            if( fwdIdxEntry.getId().equals( newParentId ) )
+            {
+                invalid = true;
+                break;
+            }
+        }
+
+        idxCursor.close();
+        
+        if ( invalid )
+        {
+            throw new LdapOperationNotSupportedException( "cannot place an entry below itself",
ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+    }
 
+    
     public final void bind( LdapDN bindDn, byte[] credentials, List<String> mechanisms,
String saslAuthId )
         throws Exception
     {



Mime
View raw message