directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r948572 - in /directory/apacheds/trunk: core/src/main/java/org/apache/directory/server/core/operational/ ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/
Date Wed, 26 May 2010 20:30:29 GMT
Author: kayyagari
Date: Wed May 26 20:30:29 2010
New Revision: 948572

URL: http://svn.apache.org/viewvc?rev=948572&view=rev
Log:
o changed the exception thrown when a non admin user tries to add entryUUID and entryCSN attributes
to LdapNoPermissionException
  which will send the result code INSUFFICIENT_ACCESS_RIGHTS (this change was done to keep
it uniform with the behavior of SchemaInterceptor's checkModifyEntry() method)
o added test cases to test this behavior

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.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=948572&r1=948571&r2=948572&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
Wed May 26 20:30:29 2010
@@ -47,13 +47,14 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
-import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
+import org.apache.directory.shared.ldap.entry.Entry;
 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.Entry;
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapNoPermissionException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.AVA;
@@ -209,7 +210,7 @@ public class OperationalAttributeInterce
                 // Wrong !
                 String message = I18n.err( I18n.ERR_30, SchemaConstants.ENTRY_UUID_AT );
                 LOG.error( message );
-                throw new LdapSchemaViolationException( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS,
message );
+                throw new LdapNoPermissionException( message );
             }
         }
         else
@@ -224,7 +225,7 @@ public class OperationalAttributeInterce
                 // Wrong !
                 String message =  I18n.err( I18n.ERR_30, SchemaConstants.ENTRY_CSN_AT );
                 LOG.error( message );
-                throw new LdapSchemaViolationException( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS,
message );
+                throw new LdapNoPermissionException( message );
             }
         }
         else

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java?rev=948572&r1=948571&r2=948572&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
Wed May 26 20:30:29 2010
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
@@ -34,12 +35,16 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.future.AddFuture;
 import org.apache.directory.ldap.client.api.message.AddRequest;
 import org.apache.directory.ldap.client.api.message.AddResponse;
+import org.apache.directory.ldap.client.api.message.BindResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
 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;
+import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
@@ -71,6 +76,7 @@ public class ClientAddRequestTest extend
     public void setup() throws Exception
     {
         connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+        connection.setTimeOut( 0 );
         DN bindDn = new DN( "uid=admin,ou=system" );
         connection.bind( bindDn.getName(), "secret" );
         
@@ -144,4 +150,50 @@ public class ClientAddRequestTest extend
             fail();
         }
     }
+    
+    
+    @ApplyLdifs(
+        {
+            "dn: cn=kayyagari,ou=system",
+            "objectClass: person",
+            "objectClass: top",
+            "cn: kayyagari",
+            "description: dbugger",
+            "sn: dbugger",
+            "userPassword: secret"
+        })
+    @Test
+    public void testAddEntryUUIDAndEntryCsn() throws Exception
+    {
+        //test as admin first
+        DN dn = new DN( "cn=x,ou=system" );
+        String uuid = UUID.randomUUID().toString();
+        String csn = new CsnFactory( 0 ).newInstance().toString();
+        
+        Entry entry = new DefaultEntry( dn );
+        entry.add( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.PERSON_OC );
+        entry.add( SchemaConstants.CN_AT, "x" );
+        entry.add( SchemaConstants.SN_AT, "x" );
+        entry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
+        entry.add( SchemaConstants.ENTRY_CSN_AT, csn );
+        
+        connection.add( entry );
+        
+        Entry loadedEntry = ( ( SearchResultEntry ) connection.lookup( dn.getName(), "+"
) ).getEntry();
+        
+        // successful for admin
+        assertEquals( uuid, loadedEntry.get( SchemaConstants.ENTRY_UUID_AT ).getString()
);
+        assertEquals( csn, loadedEntry.get( SchemaConstants.ENTRY_CSN_AT ).getString() );
+        
+        connection.delete( dn );
+        connection.unBind();
+        
+        // connect as non admin user and try to add entry with uuid and csn
+        BindResponse bindResp = connection.bind( "cn=kayyagari,ou=system", "secret" );
+        assertEquals( ResultCodeEnum.SUCCESS, bindResp.getLdapResult().getResultCode() );
+        
+        AddResponse resp = connection.add( entry );
+        assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, resp.getLdapResult().getResultCode()
);
+    }
+    
 }

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=948572&r1=948571&r2=948572&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
Wed May 26 20:30:29 2010
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
@@ -33,15 +34,19 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.future.ModifyFuture;
 import org.apache.directory.ldap.client.api.message.ModifyRequest;
 import org.apache.directory.ldap.client.api.message.ModifyResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
 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;
+import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.After;
 import org.junit.Before;
@@ -72,6 +77,7 @@ public class ClientModifyRequestTest ext
     public void setup() throws Exception
     {
         connection = new LdapNetworkConnection( "localhost", ldapServer.getPort() );
+        connection.setTimeOut( 0 );
 
         DN bindDn = new DN( "uid=admin,ou=system" );
         connection.bind( bindDn.getName(), "secret" );
@@ -178,4 +184,23 @@ public class ClientModifyRequestTest ext
             fail();
         }
     }
+    
+    
+    @Test
+    public void testModifyEntryUUIDAndEntryCSN() throws Exception
+    {
+        DN dn = new DN( "uid=admin,ou=system" );
+        
+        ModifyRequest modReq = new ModifyRequest( dn );
+        modReq.replace( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
+        
+        ModifyResponse modResp = connection.modify( modReq );
+        assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, modResp.getLdapResult().getResultCode()
);
+        
+        modReq = new ModifyRequest( dn );
+        modReq.replace( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString()
);
+        
+        modResp = connection.modify( modReq );
+        assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, modResp.getLdapResult().getResultCode()
);
+    }
 }



Mime
View raw message