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 2008/06/02 16:00:26 UTC

svn commit: r662440 [5/8] - in /directory: apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/ apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/authn/ apacheds/branches/bigbang/c...

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java?rev=662440&r1=662439&r2=662440&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java Mon Jun  2 07:00:23 2008
@@ -21,8 +21,6 @@
 
 
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -35,15 +33,9 @@
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.authn.AuthenticationInterceptor;
-import org.apache.directory.server.core.authz.AciAuthorizationInterceptor;
-import org.apache.directory.server.core.authz.DefaultAuthorizationInterceptor;
-import org.apache.directory.server.core.changelog.ChangeLogInterceptor;
-import org.apache.directory.server.core.collective.CollectiveAttributeInterceptor;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.event.EventInterceptor;
-import org.apache.directory.server.core.exception.ExceptionInterceptor;
 import org.apache.directory.server.core.filtering.EntryFilter;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.InterceptorChain;
@@ -62,19 +54,13 @@
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.OperationContext;
 import org.apache.directory.server.core.interceptor.context.RemoveContextPartitionOperationContext;
 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.interceptor.context.UnbindOperationContext;
-import org.apache.directory.server.core.invocation.Invocation;
 import org.apache.directory.server.core.invocation.InvocationStack;
-import org.apache.directory.server.core.normalization.NormalizationInterceptor;
-import org.apache.directory.server.core.operational.OperationalAttributeInterceptor;
-import org.apache.directory.server.core.referral.ReferralInterceptor;
-import org.apache.directory.server.core.schema.SchemaInterceptor;
-import org.apache.directory.server.core.subtree.SubentryInterceptor;
-import org.apache.directory.server.core.trigger.TriggerInterceptor;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapSizeLimitExceededException;
@@ -94,32 +80,6 @@
  */
 public class PartitionNexusProxy extends PartitionNexus
 {
-    /**
-     * safe to use set of bypass instructions to lookup raw entries
-     */
-    public static final Collection<String> LOOKUP_BYPASS;
-
-    /**
-     * safe to use set of bypass instructions to getMatchedDn
-     */
-    public static final Collection<String> GETMATCHEDDN_BYPASS;
-
-    /**
-     * safe to use set of bypass instructions to lookup raw entries excluding operational attributes
-     */
-    public static final Collection<String> LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS;
-    
-    public static final Collection<String> GET_ROOT_DSE_BYPASS;
-
-    /**
-     * Bypass String to use when ALL interceptors should be skipped
-     */
-    public static final String BYPASS_ALL = "*";
-
-    /**
-     * Bypass String to use when ALL interceptors should be skipped
-     */
-    public static final Collection<String> BYPASS_ALL_COLLECTION = Collections.singleton( BYPASS_ALL );
 
     /**
      * A static object to store the rootDSE entry with all the attributes
@@ -141,75 +101,8 @@
      */
     private static final Object ROOT_DSE_NOOP_MUTEX = new Object();
 
-    private final Context caller;
     private final DirectoryService service;
 
-    static
-    {
-        Collection<String> c = new HashSet<String>();
-        c.add( NormalizationInterceptor.class.getName() );
-        c.add( AuthenticationInterceptor.class.getName() );
-        c.add( ReferralInterceptor.class.getName() );
-        c.add( AciAuthorizationInterceptor.class.getName() );
-        c.add( DefaultAuthorizationInterceptor.class.getName() );
-//        c.add( ExceptionInterceptor.class.getName() );
-        c.add( OperationalAttributeInterceptor.class.getName() );
-        c.add( SchemaInterceptor.class.getName() );
-        c.add( SubentryInterceptor.class.getName() );
-//        c.add( CollectiveAttributeInterceptor.class.getName() );
-        c.add( EventInterceptor.class.getName() );
-//        c.add( TriggerInterceptor.class.getName() );
-        LOOKUP_BYPASS = Collections.unmodifiableCollection( c );
-
-        c = new HashSet<String>();
-//        c.add( NormalizationInterceptor.class.getName() );
-        c.add( AuthenticationInterceptor.class.getName() );
-        c.add( ReferralInterceptor.class.getName() );
-        c.add( AciAuthorizationInterceptor.class.getName() );
-        c.add( DefaultAuthorizationInterceptor.class.getName() );
-//        c.add( ExceptionInterceptor.class.getName() );
-        c.add( SchemaInterceptor.class.getName() );
-        c.add( OperationalAttributeInterceptor.class.getName() );
-        c.add( SubentryInterceptor.class.getName() );
-//        c.add( CollectiveAttributeInterceptor.class.getName() );
-        c.add( EventInterceptor.class.getName() );
-//        c.add( TriggerInterceptor.class.getName() );
-        GETMATCHEDDN_BYPASS = Collections.unmodifiableCollection( c );
-
-        c = new HashSet<String>();
-        c.add( NormalizationInterceptor.class.getName() );
-        c.add( AuthenticationInterceptor.class.getName() );
-        c.add( ReferralInterceptor.class.getName() );
-        c.add( AciAuthorizationInterceptor.class.getName() );
-        c.add( DefaultAuthorizationInterceptor.class.getName() );
-//        c.add( ExceptionInterceptor.class.getName() );
-//        c.add( OperationalAttributeInterceptor.class.getName() );
-        c.add( SchemaInterceptor.class.getName() );
-        c.add( SubentryInterceptor.class.getName() );
-//        c.add( CollectiveAttributeInterceptor.class.getName() );
-        c.add( EventInterceptor.class.getName() );
-        c.add( TriggerInterceptor.class.getName() );
-        LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS = Collections.unmodifiableCollection( c );
-        
-        
-        c = new HashSet<String>();
-        c.add( NormalizationInterceptor.class.getName() );
-        //c.add( AuthenticationInterceptor.class.getName() );
-        c.add( ChangeLogInterceptor.class.getName() );
-        c.add( ReferralInterceptor.class.getName() );
-        c.add( AciAuthorizationInterceptor.class.getName() );
-        c.add( DefaultAuthorizationInterceptor.class.getName() );
-        c.add( ExceptionInterceptor.class.getName() );
-        c.add( OperationalAttributeInterceptor.class.getName() );
-        c.add( SchemaInterceptor.class.getName() );
-        c.add( SubentryInterceptor.class.getName() );
-        c.add( CollectiveAttributeInterceptor.class.getName() );
-        c.add( EventInterceptor.class.getName() );
-        c.add( TriggerInterceptor.class.getName() );
-        GET_ROOT_DSE_BYPASS = Collections.unmodifiableCollection( c );
-
-    }
-
 
     /**
      * Creates a new instance.
@@ -217,9 +110,8 @@
      * @param caller  a JNDI {@link Context} object that will call this proxy
      * @param service a JNDI service
      */
-    public PartitionNexusProxy( Context caller, DirectoryService service ) throws Exception
+    public PartitionNexusProxy( DirectoryService service ) throws Exception
     {
-        this.caller = caller;
         this.service = service;
     }
 
@@ -333,12 +225,25 @@
     {
         return getMatchedName( opContext, null );
     }
+    
+    
+    private void push( OperationContext opContext )
+    {
+        InvocationStack.getInstance().push( opContext );
+    }
+    
+    
+    private OperationContext pop()
+    {
+        return InvocationStack.getInstance().pop();
+    }
 
 
-    public LdapDN getMatchedName( GetMatchedNameOperationContext opContext, Collection<String> bypass ) throws Exception
+    public LdapDN getMatchedName( GetMatchedNameOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "getMatchedName", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -346,7 +251,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -357,10 +262,11 @@
     }
 
 
-    public LdapDN getSuffix( GetSuffixOperationContext opContext, Collection<String> bypass ) throws Exception
+    public LdapDN getSuffix( GetSuffixOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "getSuffixDn", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -368,7 +274,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -379,10 +285,11 @@
     }
 
 
-    public Iterator<String> listSuffixes( ListSuffixOperationContext opContext, Collection<String> bypass ) throws Exception
+    public Iterator<String> listSuffixes( ListSuffixOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "listSuffices", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -390,7 +297,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -401,10 +308,11 @@
     }
 
 
-    public boolean compare( CompareOperationContext opContext, Collection<String> bypass ) throws Exception
+    public boolean compare( CompareOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "compare", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -412,7 +320,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -423,10 +331,11 @@
     }
 
 
-    public void delete( DeleteOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void delete( DeleteOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "delete", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -434,7 +343,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -445,10 +354,11 @@
     }
 
 
-    public void add( AddOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void add( AddOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "add", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -456,7 +366,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -467,10 +377,11 @@
     }
 
 
-    public void modify( ModifyOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void modify( ModifyOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "modify", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -478,7 +389,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -489,10 +400,11 @@
     }
 
 
-    public EntryFilteringCursor list( ListOperationContext opContext, Collection<String> bypass ) throws Exception
+    public EntryFilteringCursor list( ListOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "list", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -500,7 +412,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -550,11 +462,12 @@
     }
 
 
-    public EntryFilteringCursor search( SearchOperationContext opContext, Collection<String> bypass )
+    public EntryFilteringCursor search( SearchOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "search", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -562,7 +475,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -604,10 +517,11 @@
     }
 
 
-    public ClonedServerEntry lookup( LookupOperationContext opContext, Collection<String> bypass ) throws Exception
+    public ClonedServerEntry lookup( LookupOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "lookup", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -615,7 +529,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -625,10 +539,11 @@
     }
 
 
-    public boolean hasEntry( EntryOperationContext opContext, Collection<String> bypass ) throws Exception
+    public boolean hasEntry( EntryOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "hasEntry", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -636,7 +551,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -647,10 +562,11 @@
     }
 
 
-    public void rename( RenameOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void rename( RenameOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "rename", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -658,7 +574,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -669,10 +585,11 @@
     }
 
 
-    public void move( MoveOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void move( MoveOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "move", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -680,7 +597,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -691,11 +608,12 @@
     }
 
 
-    public void moveAndRename( MoveAndRenameOperationContext opContext, Collection<String> bypass )
+    public void moveAndRename( MoveAndRenameOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "moveAndRename", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -703,7 +621,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -711,14 +629,15 @@
      * TODO : check if we can find another way to protect ourselves from recursion.
      *
      * @param opContext The operation context
-     * @param bypass bypass instructions to skip interceptors
+     * @param byPassed bypass instructions to skip interceptors
      * @throws Exception if bind fails
      */
-    public void bind( BindOperationContext opContext, Collection<String> bypass )
+    public void bind( BindOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "bind", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -726,15 +645,16 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
 
-    public void unbind( UnbindOperationContext opContext, Collection<String> bypass ) throws Exception
+    public void unbind( UnbindOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "unbind", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -742,7 +662,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -778,11 +698,12 @@
     }
 
 
-    public ClonedServerEntry getRootDSE( GetRootDSEOperationContext opContext, Collection<String> bypass )
+    public ClonedServerEntry getRootDSE( GetRootDSEOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "getRootDSE", GET_ROOT_DSE_BYPASS ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -790,7 +711,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -801,11 +722,12 @@
     }
 
 
-    public void addContextPartition( AddContextPartitionOperationContext opContext, Collection<String> bypass )
+    public void addContextPartition( AddContextPartitionOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "addContextPartition", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -813,7 +735,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 
@@ -824,11 +746,12 @@
     }
 
 
-    public void removeContextPartition( RemoveContextPartitionOperationContext opContext, Collection<String> bypass )
+    public void removeContextPartition( RemoveContextPartitionOperationContext opContext, Collection<String> byPassed )
             throws Exception
     {
         ensureStarted();
-        opContext.push( new Invocation( this, caller, "removeContextPartition", bypass ) );
+        opContext.setByPassed( byPassed );
+        push( opContext );
         
         try
         {
@@ -836,7 +759,7 @@
         }
         finally
         {
-            opContext.pop();
+            pop();
         }
     }
 

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralHandlingCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralHandlingCursor.java?rev=662440&r1=662439&r2=662440&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralHandlingCursor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralHandlingCursor.java Mon Jun  2 07:00:23 2008
@@ -31,8 +31,8 @@
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.filtering.EntryFilter;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.interceptor.context.OperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
-import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.shared.ldap.codec.util.LdapURL;
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -272,7 +272,7 @@
             
             if ( doThrow )
             {
-                doReferralExceptionOnSearchBase( wrapped.getOperationContext().getRegistries() );
+                doReferralExceptionOnSearchBase( wrapped.getOperationContext() );
             }
                 
             return true;
@@ -420,7 +420,7 @@
     }
     
 
-    private void doReferralExceptionOnSearchBase( Registries registries ) throws NamingException
+    private void doReferralExceptionOnSearchBase( OperationContext opContext ) throws NamingException
     {
         // the refs attribute may be filtered out so we might need to lookup the entry
         EntryAttribute refs = entry.getOriginalEntry().get( SchemaConstants.REF_AT );

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java?rev=662440&r1=662439&r2=662440&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java Mon Jun  2 07:00:23 2008
@@ -27,8 +27,13 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DefaultCoreSession;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.ReferralHandlingMode;
 import org.apache.directory.server.core.authn.AuthenticationInterceptor;
+import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.server.core.authz.AciAuthorizationInterceptor;
 import org.apache.directory.server.core.authz.DefaultAuthorizationInterceptor;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
@@ -44,7 +49,6 @@
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
-import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
@@ -52,14 +56,11 @@
 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.invocation.Invocation;
-import org.apache.directory.server.core.invocation.InvocationStack;
-import org.apache.directory.server.core.jndi.ServerLdapContext;
 import org.apache.directory.server.core.normalization.NormalizationInterceptor;
 import org.apache.directory.server.core.operational.OperationalAttributeInterceptor;
+import org.apache.directory.server.core.partition.ByPassConstants;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.PartitionNexus;
-import org.apache.directory.server.core.partition.PartitionNexusProxy;
 import org.apache.directory.server.core.schema.SchemaInterceptor;
 import org.apache.directory.server.core.subtree.SubentryInterceptor;
 import org.apache.directory.server.core.trigger.TriggerInterceptor;
@@ -69,6 +70,7 @@
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.codec.util.LdapURL;
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
@@ -104,10 +106,6 @@
 public class ReferralInterceptor extends BaseInterceptor
 {
     private static final Logger LOG = LoggerFactory.getLogger( ReferralInterceptor.class );
-    private static final String IGNORE = "ignore";
-    private static final String THROW_FINDING_BASE = "throw-finding-base";
-    private static final String THROW = "throw";
-    private static final String FOLLOW = "follow";
     private static final Collection<String> SEARCH_BYPASS;
 
     private ReferralLut lut = new ReferralLut();
@@ -261,7 +259,13 @@
         while ( suffixes.hasNext() )
         {
             LdapDN suffix = new LdapDN( suffixes.next() );
-            addReferrals( nexus.search( new SearchOperationContext( registries, suffix, AliasDerefMode.DEREF_ALWAYS,
+            
+            LdapDN adminDn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+            adminDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+            CoreSession adminSession = new DefaultCoreSession( 
+                new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), directoryService );
+
+            addReferrals( nexus.search( new SearchOperationContext( adminSession, suffix, AliasDerefMode.DEREF_ALWAYS,
                 getReferralFilter(), getControls() ) ), suffix );
         }
     }
@@ -350,52 +354,45 @@
 
     public void add( NextInterceptor next, AddOperationContext opContext ) throws Exception
     {
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
         LdapDN name = opContext.getDn();
         ServerEntry entry = opContext.getEntry();
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
 
-        // handle a normal add without following referrals
-        if ( ( refval == null ) || refval.equals( IGNORE ) )
+        switch( refval )
         {
-            next.add( opContext );
-
-            if ( isReferral( entry ) )
-            {
-                lut.referralAdded( name );
-            }
-        }
-        else if ( refval.equals( THROW ) )
-        {
-            LdapDN farthest = lut.getFarthestReferralAncestor( name );
-
-            if ( farthest == null )
-            {
+            case IGNORE:
                 next.add( opContext );
 
                 if ( isReferral( entry ) )
                 {
                     lut.referralAdded( name );
                 }
-                return;
-            }
+                break;
+            case THROW:
+                LdapDN farthest = lut.getFarthestReferralAncestor( name );
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
+                if ( farthest == null )
+                {
+                    next.add( opContext );
 
-            AttributeType refsType = atRegistry.lookup( oidRegistry.getOid( SchemaConstants.REF_AT ) );
-            EntryAttribute refs = referral.get( refsType );
-            doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
-        }
-        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 );
+                    if ( isReferral( entry ) )
+                    {
+                        lut.referralAdded( name );
+                    }
+                    return;
+                }
+
+                ClonedServerEntry referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+
+                AttributeType refsType = atRegistry.lookup( oidRegistry.getOid( SchemaConstants.REF_AT ) );
+                EntryAttribute refs = referral.get( refsType );
+                doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
+                break;
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -403,43 +400,31 @@
     public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws Exception
     {
         LdapDN name = opContext.getDn();
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
 
-        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( opContext );
-        }
-
-        if ( refval.equals( THROW ) )
+        switch( refval )
         {
-            LdapDN farthest = lut.getFarthestReferralAncestor( name );
-
-            if ( farthest == null )
-            {
+            case IGNORE:
                 return next.compare( opContext );
-            }
+            case THROW:
+                LdapDN farthest = lut.getFarthestReferralAncestor( name );
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
+                if ( farthest == null )
+                {
+                    return next.compare( opContext );
+                }
 
-            EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-            doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
+                ClonedServerEntry referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                doReferralException( farthest, new LdapDN( name.getUpName() ), 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 );
+                // we really can't get here since doReferralException will throw an exception
+                return false;
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -447,29 +432,11 @@
     public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws Exception
     {
         LdapDN name = opContext.getDn();
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
-
-        // handle a normal delete without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
-        {
-            next.delete( opContext );
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
 
-            if ( lut.isReferral( name ) )
-            {
-                lut.referralDeleted( name );
-            }
-
-            return;
-        }
-
-        if ( refval.equals( THROW ) )
+        switch( refval )
         {
-            LdapDN farthest = lut.getFarthestReferralAncestor( name );
-
-            if ( farthest == null )
-            {
+            case IGNORE:
                 next.delete( opContext );
 
                 if ( lut.isReferral( name ) )
@@ -478,23 +445,30 @@
                 }
 
                 return;
-            }
+            case THROW:
+                LdapDN farthest = lut.getFarthestReferralAncestor( name );
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
+                if ( farthest == null )
+                {
+                    next.delete( opContext );
 
-            EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-            doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
+                    if ( lut.isReferral( name ) )
+                    {
+                        lut.referralDeleted( name );
+                    }
 
-        }
-        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 );
+                    return;
+                }
+
+                ClonedServerEntry referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
+                break;
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -517,33 +491,13 @@
     public void move( NextInterceptor next, MoveOperationContext opContext ) throws Exception
     {
         LdapDN oldName = opContext.getDn();
-
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
         LdapDN newName = ( LdapDN ) opContext.getParent().clone();
         newName.add( oldName.get( oldName.size() - 1 ) );
 
-        // handle a normal modify without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
-        {
-            next.move( opContext );
-
-            if ( lut.isReferral( oldName ) )
-            {
-                lut.referralChanged( oldName, newName );
-            }
-
-            return;
-        }
-
-        if ( refval.equals( THROW ) )
+        switch( refval )
         {
-            LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
-            LdapDN farthestDst = lut.getFarthestReferralAncestor( newName ); // note will not return newName so safe
-
-            if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
-            {
+            case IGNORE:
                 next.move( opContext );
 
                 if ( lut.isReferral( oldName ) )
@@ -552,38 +506,46 @@
                 }
 
                 return;
-            }
-            else if ( farthestSrc != null )
-            {
-                ServerEntry referral = invocation.getProxy().lookup(
-                    new LookupOperationContext( registries, farthestSrc ), PartitionNexusProxy.LOOKUP_BYPASS );
+            case THROW:
+                LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
+                LdapDN farthestDst = lut.getFarthestReferralAncestor( newName ); // note will not return newName so safe
 
-                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-                doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
-            }
-            else if ( farthestDst != null )
-            {
-                throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
-                    + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
-            else if ( lut.isReferral( newName ) )
-            {
-                throw new LdapNamingException( newName
-                    + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
-                    ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
+                if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
+                {
+                    next.move( opContext );
 
-            throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
-                + "modifyDn operation while processing referrals.  Report this as a bug!" );
-        }
-        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 );
+                    if ( lut.isReferral( oldName ) )
+                    {
+                        lut.referralChanged( oldName, newName );
+                    }
+
+                    return;
+                }
+                else if ( farthestSrc != null )
+                {
+                    ClonedServerEntry referral = opContext.lookup( farthestSrc, ByPassConstants.LOOKUP_BYPASS );
+                    EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                    doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
+                }
+                else if ( farthestDst != null )
+                {
+                    throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
+                        + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
+                else if ( lut.isReferral( newName ) )
+                {
+                    throw new LdapNamingException( newName
+                        + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
+                        ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
+
+                throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
+                    + "modifyDn operation while processing referrals.  Report this as a bug!" );                
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -591,32 +553,13 @@
     public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws Exception
     {
         LdapDN oldName = opContext.getDn();
-
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
         LdapDN newName = ( LdapDN ) opContext.getParent().clone();
         newName.add( opContext.getNewRdn() );
 
-        // handle a normal modify without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
-        {
-            next.moveAndRename( opContext );
-
-            if ( lut.isReferral( oldName ) )
-            {
-                lut.referralChanged( oldName, newName );
-            }
-            return;
-        }
-
-        if ( refval.equals( THROW ) )
+        switch( refval )
         {
-            LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
-            LdapDN farthestDst = lut.getFarthestReferralAncestor( newName ); // safe to use - does not return newName
-
-            if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
-            {
+            case IGNORE:
                 next.moveAndRename( opContext );
 
                 if ( lut.isReferral( oldName ) )
@@ -624,39 +567,45 @@
                     lut.referralChanged( oldName, newName );
                 }
                 return;
-            }
-            else if ( farthestSrc != null )
-            {
-                ServerEntry referral = invocation.getProxy().lookup(
-                    new LookupOperationContext( registries, farthestSrc ), PartitionNexusProxy.LOOKUP_BYPASS );
+            case THROW:
+                LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
+                LdapDN farthestDst = lut.getFarthestReferralAncestor( newName ); // safe to use - does not return newName
 
-                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-                doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
+                if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
+                {
+                    next.moveAndRename( opContext );
 
-            }
-            else if ( farthestDst != null )
-            {
-                throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
-                    + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
-            else if ( lut.isReferral( newName ) )
-            {
-                throw new LdapNamingException( newName
-                    + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
-                    ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
+                    if ( lut.isReferral( oldName ) )
+                    {
+                        lut.referralChanged( oldName, newName );
+                    }
+                    return;
+                }
+                else if ( farthestSrc != null )
+                {
+                    ClonedServerEntry referral = opContext.lookup( farthestSrc, ByPassConstants.LOOKUP_BYPASS );
+                    EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                    doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
+                }
+                else if ( farthestDst != null )
+                {
+                    throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
+                        + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
+                else if ( lut.isReferral( newName ) )
+                {
+                    throw new LdapNamingException( newName
+                        + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
+                        ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
 
-            throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
-                + "modifyDn operation while processing referrals.  Report this as a bug!" );
-        }
-        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 );
+                throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
+                    + "modifyDn operation while processing referrals.  Report this as a bug!" );
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -664,35 +613,14 @@
     public void rename( NextInterceptor next, RenameOperationContext opContext ) throws Exception
     {
         LdapDN oldName = opContext.getDn();
-
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
         LdapDN newName = ( LdapDN ) oldName.clone();
         newName.remove( oldName.size() - 1 );
-
         newName.add( opContext.getNewRdn() );
 
-        // handle a normal modify without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
-        {
-            next.rename( opContext );
-
-            if ( lut.isReferral( oldName ) )
-            {
-                lut.referralChanged( oldName, newName );
-            }
-
-            return;
-        }
-
-        if ( refval.equals( THROW ) )
+        switch( refval )
         {
-            LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
-            LdapDN farthestDst = lut.getFarthestReferralAncestor( newName );
-
-            if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
-            {
+            case IGNORE:
                 next.rename( opContext );
 
                 if ( lut.isReferral( oldName ) )
@@ -701,40 +629,48 @@
                 }
 
                 return;
-            }
+            case THROW:
+                LdapDN farthestSrc = lut.getFarthestReferralAncestor( oldName );
+                LdapDN farthestDst = lut.getFarthestReferralAncestor( newName );
 
-            if ( farthestSrc != null )
-            {
-                ServerEntry referral = invocation.getProxy().lookup(
-                    new LookupOperationContext( registries, farthestSrc ), PartitionNexusProxy.LOOKUP_BYPASS );
+                if ( farthestSrc == null && farthestDst == null && !lut.isReferral( newName ) )
+                {
+                    next.rename( opContext );
 
-                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-                doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
+                    if ( lut.isReferral( oldName ) )
+                    {
+                        lut.referralChanged( oldName, newName );
+                    }
 
-            }
-            else if ( farthestDst != null )
-            {
-                throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
-                    + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
-            else if ( lut.isReferral( newName ) )
-            {
-                throw new LdapNamingException( newName
-                    + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
-                    ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
-            }
+                    return;
+                }
 
-            throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
-                + "modifyDn operation while processing referrals.  Report this as a bug!" );
-        }
-        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 );
+                if ( farthestSrc != null )
+                {
+                    ClonedServerEntry referral = opContext.lookup( farthestSrc, ByPassConstants.LOOKUP_BYPASS );
+                    EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                    doReferralException( farthestSrc, new LdapDN( oldName.getUpName() ), refs );
+
+                }
+                else if ( farthestDst != null )
+                {
+                    throw new LdapNamingException( farthestDst + " ancestor is a referral for modifyDn on " + newName
+                        + " so it affects multiple DSAs", ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
+                else if ( lut.isReferral( newName ) )
+                {
+                    throw new LdapNamingException( newName
+                        + " exists and is a referral for modifyDn destination so it affects multiple DSAs",
+                        ResultCodeEnum.AFFECTS_MULTIPLE_DSAS );
+                }
+
+                throw new IllegalStateException( "If you get this exception the server's logic was flawed in handling a "
+                    + "modifyDn operation while processing referrals.  Report this as a bug!" );
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -812,45 +748,35 @@
 
     public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception
     {
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
         LdapDN name = opContext.getDn();
         List<Modification> mods = opContext.getModItems();
 
-        // handle a normal modify without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
+        switch( refval )
         {
-            next.modify( opContext );
-            checkModify( name, mods );
-            return;
-        }
-
-        if ( refval.equals( THROW ) )
-        {
-            LdapDN farthest = lut.getFarthestReferralAncestor( name );
-
-            if ( farthest == null )
-            {
+            case IGNORE:
                 next.modify( opContext );
                 checkModify( name, mods );
                 return;
-            }
+            case THROW:
+                LdapDN farthest = lut.getFarthestReferralAncestor( name );
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
+                if ( farthest == null )
+                {
+                    next.modify( opContext );
+                    checkModify( name, mods );
+                    return;
+                }
 
-            EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-            doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
-        }
-        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 );
+                ClonedServerEntry referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
+                doReferralException( farthest, new LdapDN( name.getUpName() ), refs );
+                break;
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
@@ -879,10 +805,11 @@
         // add referrals immediately after adding the new partition
         Partition partition = opContext.getPartition();
         LdapDN suffix = partition.getSuffixDn();
-        Invocation invocation = InvocationStack.getInstance().peek();
-        EntryFilteringCursor list = invocation.getProxy().search(
-            new SearchOperationContext( registries, suffix, AliasDerefMode.DEREF_ALWAYS, getReferralFilter(),
-                getControls() ), SEARCH_BYPASS );
+        SearchOperationContext searchContext = new SearchOperationContext( 
+            opContext.getSession(), suffix, AliasDerefMode.DEREF_ALWAYS, getReferralFilter(), getControls() );
+        searchContext.setByPassed( SEARCH_BYPASS );
+        EntryFilteringCursor list = opContext.getSession().getDirectoryService()
+            .getOperationManager().search( searchContext );
         addReferrals( list, suffix );
     }
 
@@ -891,10 +818,12 @@
         throws Exception
     {
         // remove referrals immediately before removing the partition
-        Invocation invocation = InvocationStack.getInstance().peek();
-        EntryFilteringCursor cursor = invocation.getProxy().search(
-            new SearchOperationContext( registries, opContext.getDn(), AliasDerefMode.DEREF_ALWAYS,
-                getReferralFilter(), getControls() ), SEARCH_BYPASS );
+        SearchOperationContext searchContext = new SearchOperationContext( 
+            opContext.getSession(), opContext.getDn(), AliasDerefMode.DEREF_ALWAYS, 
+            getReferralFilter(), getControls() );
+        searchContext.setByPassed( SEARCH_BYPASS );
+        EntryFilteringCursor cursor = opContext.getSession().getDirectoryService()
+            .getOperationManager().search( searchContext );
 
         deleteReferrals( cursor, opContext.getDn() );
         next.removeContextPartition( opContext );
@@ -938,84 +867,75 @@
 
     public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext opContext ) throws Exception
     {
-        Invocation invocation = InvocationStack.getInstance().peek();
-        ServerLdapContext caller = ( ServerLdapContext ) invocation.getCaller();
-        String refval = ( String ) caller.getEnvironment().get( Context.REFERRAL );
-
-        // handle a normal search without following referrals
-        if ( refval == null || refval.equals( IGNORE ) )
-        {
-            return next.search( opContext );
-        }
-
+        ReferralHandlingMode refval = opContext.getSession().getReferralHandlingMode();
         LdapDN base = opContext.getDn();
         SearchControls controls = opContext.getSearchControls();
-
-        /**
-         * THROW_FINDING_BASE is a special setting which allows for finding base to 
-         * throw exceptions but not when searching.  While search all results are 
-         * returned as if they are regular entries.
-         */
-        if ( refval.equals( THROW_FINDING_BASE ) )
+        
+        // set inside switch
+        ClonedServerEntry referral = null;
+        LdapDN farthest = null;
+        EntryAttribute refs = null;
+        
+        switch( refval )
         {
-            if ( lut.isReferral( base ) )
-            {
-                ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, base ),
-                    PartitionNexusProxy.LOOKUP_BYPASS );
-                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-                doReferralExceptionOnSearchBase( base, refs, controls.getSearchScope() );
-            }
+            case IGNORE:
+                return next.search( opContext );
 
-            LdapDN farthest = lut.getFarthestReferralAncestor( base );
+            /*
+             * THROW_FINDING_BASE is a special setting which allows for finding base to 
+             * throw exceptions but not when searching.  While search all results are 
+             * returned as if they are regular entries.
+             */
+            case THROW_FINDING_BASE:
+                if ( lut.isReferral( base ) )
+                {
+                    referral = opContext.lookup( base, ByPassConstants.LOOKUP_BYPASS );
+                    refs = referral.get( SchemaConstants.REF_AT );
+                    doReferralExceptionOnSearchBase( base, refs, controls.getSearchScope() );
+                }
 
-            if ( farthest == null )
-            {
-                return next.search( opContext );
-            }
+                farthest = lut.getFarthestReferralAncestor( base );
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
-            EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-            doReferralExceptionOnSearchBase( farthest, new LdapDN( base.getUpName() ), refs, controls.getSearchScope() );
-            throw new IllegalStateException( "Should never get here: shutting up compiler" );
-        }
+                if ( farthest == null )
+                {
+                    return next.search( opContext );
+                }
 
-        if ( refval.equals( THROW ) )
-        {
-            if ( lut.isReferral( base ) )
-            {
-                ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, base ),
-                    PartitionNexusProxy.LOOKUP_BYPASS );
-                EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-                doReferralExceptionOnSearchBase( base, refs, controls.getSearchScope() );
-            }
+                referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+                refs = referral.get( SchemaConstants.REF_AT );
+                doReferralExceptionOnSearchBase( farthest, new LdapDN( base.getUpName() ), refs, controls.getSearchScope() );
+                throw new IllegalStateException( "Should never get here: shutting up compiler" );
+            case THROW:
+                if ( lut.isReferral( base ) )
+                {
+                    referral = opContext.lookup( base, ByPassConstants.LOOKUP_BYPASS );
+                    refs = referral.get( SchemaConstants.REF_AT );
+                    doReferralExceptionOnSearchBase( base, refs, controls.getSearchScope() );
+                }
 
-            LdapDN farthest = lut.getFarthestReferralAncestor( base );
+                farthest = lut.getFarthestReferralAncestor( base );
 
-            if ( farthest == null )
-            {
-                EntryFilteringCursor srfe = next.search( opContext );
-                return new ReferralHandlingCursor( srfe, lut, true );
-            }
+                if ( farthest == null )
+                {
+                    EntryFilteringCursor srfe = next.search( opContext );
+                    return new ReferralHandlingCursor( srfe, lut, true );
+                }
 
-            ServerEntry referral = invocation.getProxy().lookup( new LookupOperationContext( registries, farthest ),
-                PartitionNexusProxy.LOOKUP_BYPASS );
-            EntryAttribute refs = referral.get( SchemaConstants.REF_AT );
-            doReferralExceptionOnSearchBase( farthest, new LdapDN( base.getUpName() ), refs, controls.getSearchScope() );
-            throw new IllegalStateException( "Should never get here: shutting up compiler" );
-        }
-        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 );
+                referral = opContext.lookup( farthest, ByPassConstants.LOOKUP_BYPASS );
+                refs = referral.get( SchemaConstants.REF_AT );
+                doReferralExceptionOnSearchBase( farthest, new LdapDN( base.getUpName() ), 
+                    refs, controls.getSearchScope() );
+                throw new IllegalStateException( "Should never get here: shutting up compiler" );
+            case FOLLOW:
+                throw new NotImplementedException( "FOLLOW referral handling mode not implemented" );
+            default:
+                throw new LdapNamingException( "Undefined value for referral handling mode: " + refval,
+                    ResultCodeEnum.OTHER );
         }
     }
 
-    class ReferralFilter implements EntryFilter//, SearchResultEnumerationAppender 
+    
+    class ReferralFilter implements EntryFilter 
     {
         public boolean accept( SearchingOperationContext operation, ClonedServerEntry result ) throws Exception
         {

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java?rev=662440&r1=662439&r2=662440&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java Mon Jun  2 07:00:23 2008
@@ -85,9 +85,6 @@
     /** The attributeType registry */
     private AttributeTypeRegistry atRegistry;
     
-    /** The global registries */
-    private Registries registries;
-    
     private final AttributeType mOidAT;
     private final AttributeType mNameAT;
     private final AttributeType cnAT;
@@ -103,11 +100,11 @@
     private static Map<String, LdapDN> staticSyntaxCheckersDNs = new HashMap<String, LdapDN>();
     private static Map<String, LdapDN> staticSyntaxesDNs = new HashMap<String, LdapDN>();
     
+    
     public PartitionSchemaLoader( Partition partition, Registries registries ) throws Exception
     {
         this.factory = new SchemaEntityFactory( registries );
         this.partition = partition;
-        this.registries = registries;
         atRegistry = registries.getAttributeTypeRegistry();
         
         dao = new SchemaPartitionDao( this.partition, registries );
@@ -129,6 +126,7 @@
         initStaticDNs( "inetorgperson" );
     }
     
+    
     private void initStaticDNs( String schemaName ) throws Exception
     {
         
@@ -418,14 +416,14 @@
             staticObjectClassesDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading objectClasses", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -519,14 +517,14 @@
             staticAttributeTypeDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading attributeTypes", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -617,14 +615,14 @@
             staticMatchingRulesDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading matchingRules", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -650,14 +648,14 @@
             staticSyntaxesDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading syntaxes", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -682,14 +680,14 @@
             staticSyntaxCheckersDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading syntaxCheckers", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -716,14 +714,14 @@
             staticNormalizersDNs.put( schema.getSchemaName(), dn );
         }
         
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading normalizers", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {
@@ -780,10 +778,11 @@
     
     private ClonedServerEntry lookupPartition( LdapDN dn ) throws Exception
     {
-        return partition.lookup( new LookupOperationContext( registries, dn ) );
+        return partition.lookup( new LookupOperationContext( null, dn ) );
     }
     
     
+    @SuppressWarnings("unchecked")
     private void loadComparators( Schema schema, Registries targetRegistries ) throws Exception
     {
         LdapDN dn = staticComparatorsDNs.get( schema.getSchemaName() );
@@ -795,14 +794,14 @@
             staticComparatorsDNs.put( schema.getSchemaName(), dn );
         }
 
-        if ( ! partition.hasEntry( new EntryOperationContext( registries, dn ) ) )
+        if ( ! partition.hasEntry( new EntryOperationContext( null, dn ) ) )
         {
             return;
         }
         
         LOG.debug( "{} schema: loading comparators", schema.getSchemaName() );
         
-        EntryFilteringCursor list = partition.list( new ListOperationContext( registries, dn ) );
+        EntryFilteringCursor list = partition.list( new ListOperationContext( null, dn ) );
         
         while ( list.next() )
         {

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=662440&r1=662439&r2=662440&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Mon Jun  2 07:00:23 2008
@@ -1098,12 +1098,11 @@
     {
         LdapDN oriChildName = opContext.getDn();
 
-        ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, oriChildName ) );
+        ClonedServerEntry entry = nexus.lookup( opContext.newLookupContext( oriChildName ) );
 
         if ( oriChildName.startsWith( schemaBaseDN ) )
         {
-            schemaManager.move( oriChildName, opContext.getParent(), opContext.getNewRdn(), opContext.getDelOldDn(),
-                entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
+            schemaManager.move( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         }
 
         next.moveAndRename( opContext );
@@ -1114,12 +1113,11 @@
     {
         LdapDN oriChildName = opContext.getDn();
 
-        ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, oriChildName ) );
+        ClonedServerEntry entry = nexus.lookup( opContext.newLookupContext( oriChildName ) );
 
         if ( oriChildName.startsWith( schemaBaseDN ) )
         {
-            schemaManager.replace( oriChildName, opContext.getParent(), entry, opContext
-                .hasRequestControl( CascadeControl.CONTROL_OID ) );
+            schemaManager.replace( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         }
 
         next.move( opContext );
@@ -1132,11 +1130,11 @@
         Rdn newRdn = opContext.getNewRdn();
         boolean deleteOldRn = opContext.getDelOldDn();
 
-        ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, name ) );
+        ServerEntry entry = nexus.lookup( opContext.newLookupContext( name ) );
 
         if ( name.startsWith( schemaBaseDN ) )
         {
-            schemaManager.modifyRn( name, newRdn, deleteOldRn, entry, opContext
+            schemaManager.modifyRn( opContext, entry, opContext
                 .hasRequestControl( CascadeControl.CONTROL_OID ) );
         }
 
@@ -1158,7 +1156,7 @@
         }
         else
         {
-            entry = nexus.lookup( new LookupOperationContext( registries, name ) );
+            entry = nexus.lookup( opContext.newLookupContext( name ) );
         }
 
         // First, we get the entry from the backend. If it does not exist, then we throw an exception
@@ -1431,14 +1429,14 @@
         {
             LOG.debug( "Modification attempt on schema partition {}: \n{}", name, opContext );
 
-            schemaManager.modify( name, mods, entry, targetEntry, opContext
+            schemaManager.modify( opContext, entry, targetEntry, opContext
                 .hasRequestControl( CascadeControl.CONTROL_OID ) );
         }
         else if ( subschemaSubentryDnNorm.equals( name.getNormName() ) )
         {
             LOG.debug( "Modification attempt on schema subentry {}: \n{}", name, opContext );
 
-            schemaManager.modifySchemaSubentry( name, mods, entry, targetEntry, opContext
+            schemaManager.modifySchemaSubentry( opContext, entry, targetEntry, opContext
                 .hasRequestControl( CascadeControl.CONTROL_OID ) );
             return;
         }
@@ -1661,7 +1659,7 @@
 
         if ( name.startsWith( schemaBaseDN ) )
         {
-            schemaManager.add( name, entry );
+            schemaManager.add( addContext );
         }
 
         next.add( addContext );
@@ -1711,8 +1709,8 @@
 
         if ( name.startsWith( schemaBaseDN ) )
         {
-            ServerEntry entry = nexus.lookup( new LookupOperationContext( registries, name ) );
-            schemaManager.delete( name, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
+            ClonedServerEntry entry = nexus.lookup( opContext.newLookupContext( name ) );
+            schemaManager.delete( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         }
 
         next.delete( opContext );