You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/01/14 06:24:23 UTC

svn commit: r368980 - in /directory/trunks/apacheds: core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java core/src/main/java/org/apache/ldap/server/referral/ReferralService.java

Author: akarasulu
Date: Fri Jan 13 21:24:18 2006
New Revision: 368980

URL: http://svn.apache.org/viewcvs?rev=368980&view=rev
Log:
added compare request handling for referrals property is set to throw

Modified:
    directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java

Modified: directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java?rev=368980&r1=368979&r2=368980&view=diff
==============================================================================
--- directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java (original)
+++ directory/trunks/apacheds/core-unit/src/test/java/org/apache/ldap/server/jndi/ReferralTest.java Fri Jan 13 21:24:18 2006
@@ -31,6 +31,7 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.server.unit.AbstractAdminTestCase;
 
 
@@ -280,6 +281,89 @@
         try 
         {
             td.refCtx.destroySubcontext( "cn=alex karasulu,ou=apache" );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/cn=alex karasulu,ou=apache,ou=users,dc=example,dc=com", 
+                e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
+            assertFalse( e.skipReferral() );
+        }
+    }
+    
+    
+    /**
+     * Checks for correct core behavoir when Context.REFERRAL is set to <b>throw</b>
+     * for an delete operation with the parent context being a referral.
+     * 
+     * @throws Exception if something goes wrong.
+     */
+    public void testCompareWithReferralParent() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // Attempt to compare attributes in an entry below the referral parent. 
+        // We should encounter referral errors with referral setting set to 
+        // throw.
+        // -------------------------------------------------------------------
+
+        td.refCtx.addToEnvironment( Context.REFERRAL, "throw" );
+        try 
+        {
+            if ( td.refCtx instanceof ServerLdapContext )
+            {
+                LdapName dn = new LdapName( "cn=alex karasulu,ou=users,ou=system" );
+                ( ( ServerLdapContext ) td.refCtx ).compare( dn, "sn", "karasulu" );
+            }
+            else
+            {
+                // abort the test because we're using the sun jdni provider
+                return;
+            }
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch( ReferralException e )
+        {
+            assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://hertz:10389/cn=alex karasulu,ou=users,dc=example,dc=com", e.getReferralInfo() );
+            assertTrue( e.skipReferral() );
+            assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
+            assertFalse( e.skipReferral() );
+        }
+    }
+    
+    
+    /**
+     * Checks for correct core behavoir when Context.REFERRAL is set to <b>throw</b>
+     * for a compare operation with an ancestor context being a referral.
+     * 
+     * @throws Exception if something goes wrong.
+     */
+    public void testCompareWithReferralAncestor() throws Exception
+    {
+        // -------------------------------------------------------------------
+        // Attempt to compare attributes in an entry below the referral ancestor. 
+        // We should encounter referral errors when referral setting is set to 
+        // throw.
+        // -------------------------------------------------------------------
+
+        td.refCtx.addToEnvironment( Context.REFERRAL, "throw" );
+        try 
+        {
+            if ( td.refCtx instanceof ServerLdapContext )
+            {
+                LdapName dn = new LdapName( "cn=alex karasulu,ou=apache,ou=users,ou=system" );
+                ( ( ServerLdapContext ) td.refCtx ).compare( dn, "sn", "karasulu" );
+            }
+            else
+            {
+                // abort the test because we're using the sun jdni provider
+                return;
+            }
             fail( "Should fail here throwing a ReferralException" );
         }
         catch( ReferralException e )

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java?rev=368980&r1=368979&r2=368980&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java Fri Jan 13 21:24:18 2006
@@ -280,6 +280,45 @@
                 + refval, ResultCodeEnum.OTHER );
         }
     }
+
+    
+    public boolean compare( NextInterceptor next, Name normName, String oid, Object value ) throws NamingException
+    {
+        Invocation invocation = InvocationStack.getInstance().peek();
+        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
+        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
+        
+        // handle a normal add without following referrals
+        if ( refval == null || refval.equals( IGNORE ) )
+        {
+            return next.compare( normName, oid, value );
+        }
+
+        if ( refval.equals( THROW ) )
+        {
+            Name farthest = lut.getFarthestReferralAncestor( normName );
+            if ( farthest == null ) 
+            {
+                return next.compare( normName, oid, value );
+            }
+            
+            Attributes referral = invocation.getProxy().lookup( farthest, DirectoryPartitionNexusProxy.LOOKUP_BYPASS );
+            Attribute refs = referral.get( REF_ATTR );
+            doReferralException( farthest, normName, refs );
+            
+            // we really can't get here since doReferralException will throw an exception
+            return false;
+        }
+        else if ( refval.equals( FOLLOW ) )
+        {
+            throw new NotImplementedException( FOLLOW + " referral handling mode not implemented" );
+        }
+        else
+        {
+            throw new LdapNamingException( "Undefined value for " + Context.REFERRAL  + " key: " 
+                + refval, ResultCodeEnum.OTHER );
+        }
+    }
     
     
     public void delete( NextInterceptor next, Name normName ) throws NamingException