directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r702434 [4/5] - in /directory: apacheds/trunk/ apacheds/trunk/all/ apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/ apached...
Date Tue, 07 Oct 2008 11:27:01 GMT
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java Tue Oct  7 04:26:55 2008
@@ -24,7 +24,6 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -287,7 +286,7 @@
     }
 
 
-    public Iterator<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
+    public Set<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
     {
         if ( IS_DEBUG )
         {

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java Tue Oct  7 04:26:55 2008
@@ -25,7 +25,6 @@
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -135,11 +134,10 @@
         filter.addNode( new EqualityNode<String>( SchemaConstants.OBJECT_CLASS_AT, new ClientStringValue(
             SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC ) ) );
 
-        Iterator<String> suffixes = nexus.listSuffixes( null );
+        Set<String> suffixes = nexus.listSuffixes( null );
 
-        while ( suffixes.hasNext() )
+        for ( String suffix:suffixes )
         {
-            String suffix = suffixes.next();
             LdapDN baseDn = new LdapDN( suffix );
             SearchControls ctls = new SearchControls();
             ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java Tue Oct  7 04:26:55 2008
@@ -55,9 +55,9 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 
 /**
@@ -125,11 +125,10 @@
         // search all naming contexts for access control subentenries
         // generate ACITuple Arrays for each subentry
         // add that subentry to the hash
-        Iterator<String> suffixes = nexus.listSuffixes( null );
+        Set<String> suffixes = nexus.listSuffixes( null );
 
-        while ( suffixes.hasNext() )
+        for ( String suffix:suffixes )
         {
-            String suffix = suffixes.next();
             LdapDN baseDn = parseNormalized( suffix );
             ExprNode filter = new EqualityNode<String>( SchemaConstants.OBJECT_CLASS_AT, 
                 new ClientStringValue( SchemaConstants.ACCESS_CONTROL_SUBENTRY_OC ) );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java Tue Oct  7 04:26:55 2008
@@ -48,7 +48,7 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 import javax.naming.Context;
-import java.util.Iterator;
+import java.util.Set;
 
 
 /**
@@ -166,7 +166,7 @@
     }
 
 
-    public Iterator<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) 
+    public Set<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) 
         throws Exception
     {
         return next.listSuffixes( opContext );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java Tue Oct  7 04:26:55 2008
@@ -46,7 +46,7 @@
 import org.apache.directory.server.core.partition.PartitionNexus;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
-import java.util.Iterator;
+import java.util.Set;
 
 
 /**
@@ -104,7 +104,7 @@
  * {
  *     // transform deletion into modification.
  *     Attribute mark = new AttributeImpl( "entryDeleted", "true" );
- *     nextInterceptor.modify( name, DirContext.REPLACE_ATTRIBUTE, mark );
+ *     nextInterceptor.modify( name, DirIteratorContext.REPLACE_ATTRIBUTE, mark );
  * }
  * </pre>
  *
@@ -156,7 +156,7 @@
     /**
      * Filters {@link PartitionNexus#listSuffixes( ListSuffixOperationContext )} call.
      */
-    Iterator<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception;
+    Set<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception;
 
 
     /**

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java Tue Oct  7 04:26:55 2008
@@ -22,9 +22,9 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
@@ -52,6 +52,7 @@
 import org.apache.directory.server.core.invocation.InvocationStack;
 import org.apache.directory.server.core.partition.ByPassConstants;
 import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -118,7 +119,7 @@
         }
 
 
-        public Iterator<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
+        public Set<String> listSuffixes( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
         {
             return nexus.listSuffixes( opContext );
         }
@@ -623,7 +624,7 @@
     }
 
 
-    public Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
+    public Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
     {
         Entry entry = getStartingEntry();
         Interceptor head = entry.interceptor;
@@ -706,7 +707,7 @@
         {
             try
             {
-                opContext.setEntry( opContext.getSession().lookup( opContext.getDn() ) );
+                opContext.setEntry( opContext.getSession().lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES_ARRAY ) );
             }
             catch ( Exception e )
             {
@@ -1138,7 +1139,7 @@
                 }
 
 
-                public Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
+                public Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
                 {
                     Entry next = getNextEntry();
                     Interceptor interceptor = next.interceptor;

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java Tue Oct  7 04:26:55 2008
@@ -20,7 +20,7 @@
 package org.apache.directory.server.core.interceptor;
 
 
-import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
@@ -84,7 +84,7 @@
     /**
      * Calls the next interceptor's {@link Interceptor#listSuffixes( NextInterceptor, ListSuffixOperationContext )}.
      */
-    Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception;
+    Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception;
 
 
     /**

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java Tue Oct  7 04:26:55 2008
@@ -64,12 +64,15 @@
     
     protected LdapPrincipal authorizedPrincipal;
     
+    /** The core session */
     protected CoreSession session;
     
     protected OperationContext next;
     
     protected OperationContext previous;
 
+    /** A flag used to tell if we should consider referrals as standard entries */
+    protected boolean throwReferral;
 
     /**
      * Creates a new instance of AbstractOperationContext.
@@ -89,6 +92,10 @@
     {
         this.dn = dn;
         this.session = session;
+        
+        // The flag is set to ignore, so that the revert operation can act on 
+        // the entries, even if they are referrals.
+        ignoreReferral();
     }
 
 
@@ -422,4 +429,40 @@
     {
         return entry;
     }
+    
+    
+    /**
+     * Set the throwReferral flag to true
+     */
+    public void throwReferral()
+    {
+        throwReferral = true;
+    }
+    
+    
+    /**
+     * @return <code>true</code> if the referrals are thrown
+     */
+    public boolean isReferralThrown()
+    {
+        return throwReferral;
+    }
+
+
+    /**
+     * Set the throwReferral flag to false
+     */
+    public void ignoreReferral()
+    {
+        throwReferral = false;
+    }
+
+
+    /**
+     * @return <code>true</code> if the referrals are ignored
+     */
+    public boolean isReferralIgnored()
+    {
+        return !throwReferral;
+    }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java Tue Oct  7 04:26:55 2008
@@ -26,6 +26,7 @@
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.shared.ldap.message.AddRequest;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 
@@ -91,10 +92,19 @@
     public AddOperationContext( CoreSession session, AddRequest addRequest ) throws Exception
     {
         super( session );
-        this.entry = new ClonedServerEntry( 
+        entry = new ClonedServerEntry( 
             new DefaultServerEntry( session.getDirectoryService().getRegistries(), addRequest.getEntry() ) );
-        this.dn = addRequest.getEntry().getDn();
-        this.requestControls = addRequest.getControls();
+        dn = addRequest.getEntry().getDn();
+        requestControls = addRequest.getControls();
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java Tue Oct  7 04:26:55 2008
@@ -516,4 +516,40 @@
     {
         this.entry = entry;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void throwReferral()
+    {
+        throw new NotImplementedException( " The throwReferral method is not implemented for a Bind operation" );
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isReferralThrown()
+    {
+        throw new NotImplementedException( " The isReferralThrown method is not implemented for a Bind operation" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void ignoreReferral()
+    {
+        throw new NotImplementedException( " The ignoreReferral method is not implemented for a Bind operation" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isReferralIgnored()
+    {
+        throw new NotImplementedException( " The isReferralIgnored method is not implemented for a Bind operation" );
+    }
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java Tue Oct  7 04:26:55 2008
@@ -21,8 +21,12 @@
 
 
 import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
 import org.apache.directory.shared.ldap.message.CompareRequest;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -40,7 +44,7 @@
     private String oid;
 
     /** The value to be compared */
-    private Object value;
+    private Value<?> value;
     
     
     /**
@@ -94,7 +98,7 @@
      * Creates a new instance of LookupOperationContext.
      *
      */
-    public CompareOperationContext( CoreSession session, LdapDN dn, String oid, Object value )
+    public CompareOperationContext( CoreSession session, LdapDN dn, String oid, Value<?> value )
     {
     	super( session, dn );
         this.oid = oid;
@@ -108,6 +112,15 @@
         this.oid = compareRequest.getAttributeId();
         this.value = compareRequest.getAssertionValue();
         this.requestControls = compareRequest.getControls();
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 
@@ -143,7 +156,7 @@
      * Set the value to compare
      * @param value The value to compare
      */
-    public void setValue( Object value ) 
+    public void setValue( Value<?> value ) 
     {
         this.value = value;
     }
@@ -166,10 +179,10 @@
         return "CompareContext for DN '" + getDn().getUpName() + "'" + 
             ( ( oid != null ) ? ", oid : <" + oid + ">" : "" ) +
             ( ( value != null ) ? ", value :'" +
-                    ( ( value instanceof String ) ?
-                            value :
-                            ( ( value instanceof byte[] ) ?
-                                    StringTools.dumpBytes( (byte[])value ) : 
+                    ( ( value instanceof ClientStringValue ) ?
+                            ((ClientStringValue)value).get() :
+                            ( ( value instanceof ClientBinaryValue ) ?
+                                    StringTools.dumpBytes( ((ClientBinaryValue)value).getReference() ) : 
                                         "unknown value type" ) )
                         + "'"
                     : "" );

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java Tue Oct  7 04:26:55 2008
@@ -24,6 +24,7 @@
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.shared.ldap.message.DeleteRequest;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 
@@ -66,7 +67,16 @@
     public DeleteOperationContext( CoreSession session, DeleteRequest deleteRequest )
     {
         super( session, deleteRequest.getName() );
-        this.requestControls = deleteRequest.getControls();
+        requestControls = deleteRequest.getControls();
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
     
     

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java Tue Oct  7 04:26:55 2008
@@ -36,6 +36,7 @@
 import org.apache.directory.shared.ldap.entry.client.ClientModification;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
 import org.apache.directory.shared.ldap.message.ModifyRequest;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 
@@ -83,10 +84,21 @@
     public ModifyOperationContext( CoreSession session, ModifyRequest modifyRequest ) throws Exception
     {
         super( session, modifyRequest.getName() );
-        this.modItems = ServerEntryUtils.toServerModification( 
+        
+        modItems = ServerEntryUtils.toServerModification( 
             modifyRequest.getModificationItems().toArray( new ClientModification[0]), 
             session.getDirectoryService().getRegistries().getAttributeTypeRegistry() );
-        this.requestControls = modifyRequest.getControls();
+        
+        requestControls = modifyRequest.getControls();
+
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveAndRenameOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveAndRenameOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveAndRenameOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveAndRenameOperationContext.java Tue Oct  7 04:26:55 2008
@@ -22,6 +22,7 @@
 
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 
@@ -75,6 +76,15 @@
         {
             throw new IllegalStateException( "NewSuperior must not be null: " + modifyDnRequest );
         }
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java Tue Oct  7 04:26:55 2008
@@ -23,6 +23,7 @@
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 
@@ -69,10 +70,20 @@
         }
         
         this.requestControls = modifyDnRequest.getControls();
+        
         if ( modifyDnRequest.getNewRdn() != null )
         {
             throw new IllegalArgumentException( modifyDnRequest + " represents a move and rename operation." );
         }
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java Tue Oct  7 04:26:55 2008
@@ -324,8 +324,26 @@
     boolean hasEntry( LdapDN dn, Collection<String> byPass ) throws Exception;
     
     
-//    AddOperationContext newAddContext( ServerEntry entry );
+    /**
+     * Set the throwReferral flag to true
+     */
+    void throwReferral();
     
     
-//    void add( AddOperationContext addContext ) throws Exception;
+    /**
+     * @return <code>true</code> if the referrals are thrown
+     */
+    boolean isReferralThrown();
+
+
+    /**
+     * Set the throwReferral flag to false
+     */
+    void ignoreReferral();
+
+
+    /**
+     * @return <code>true</code> if the referrals are ignored
+     */
+    boolean isReferralIgnored();
 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/RenameOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/RenameOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/RenameOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/RenameOperationContext.java Tue Oct  7 04:26:55 2008
@@ -24,6 +24,7 @@
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.message.control.ManageDsaITControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 
@@ -88,6 +89,15 @@
         
         this.delOldDn = modifyDnRequest.getDeleteOldRdn();
         this.requestControls = modifyDnRequest.getControls();
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java Tue Oct  7 04:26:55 2008
@@ -76,6 +76,15 @@
         this.timeLimit = searchRequest.getTimeLimit();
         this.noAttributes = searchRequest.getTypesOnly();
         setReturningAttributes( searchRequest.getAttributes() );
+        
+        if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
+        {
+            ignoreReferral();
+        }
+        else
+        {
+            throwReferral();
+        }
     }
 
 

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=702434&r1=702433&r2=702434&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 Tue Oct  7 04:26:55 2008
@@ -312,7 +312,7 @@
         {
             filterOperationalAttributes( result );
         }
-        else
+        else if ( ( opContext.getAllOperational() == null ) || ( opContext.getAllOperational() == false ) )
         {
             filter( opContext, result );
         }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java Tue Oct  7 04:26:55 2008
@@ -664,6 +664,7 @@
         // Update the partition tree
         partitionLookupTree.remove( partition );
         partitions.remove( key );
+        partition.destroy();
     }
 
 
@@ -727,9 +728,9 @@
     /**
      * @see PartitionNexus#listSuffixes( ListSuffixOperationContext )
      */
-    public Iterator<String> listSuffixes ( ListSuffixOperationContext emptyContext ) throws Exception
+    public Set<String> listSuffixes( ListSuffixOperationContext emptyContext ) throws Exception
     {
-        return Collections.unmodifiableSet( partitions.keySet() ).iterator();
+        return Collections.unmodifiableSet( partitions.keySet() );
     }
 
 

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexus.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexus.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexus.java Tue Oct  7 04:26:55 2008
@@ -21,7 +21,6 @@
 
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -237,7 +236,7 @@
      * @return Iteration over ContextPartition suffix names as Names.
      * @throws Exception if there are any problems
      */
-    public abstract Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception;
+    public abstract Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception;
 
 
     /**

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java Tue Oct  7 04:26:55 2008
@@ -21,7 +21,6 @@
 
 
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -276,13 +275,13 @@
     }
 
 
-    public Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
+    public Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
     {
         return listSuffixes( opContext, null );
     }
 
 
-    public Iterator<String> listSuffixes( ListSuffixOperationContext opContext, Collection<String> byPassed ) throws Exception
+    public Set<String> listSuffixes( ListSuffixOperationContext opContext, Collection<String> byPassed ) throws Exception
     {
         ensureStarted();
         opContext.setByPassed( byPassed );

Added: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java?rev=702434&view=auto
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java (added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java Tue Oct  7 04:26:55 2008
@@ -0,0 +1,439 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.referral;
+
+
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.ReferralManager;
+import org.apache.directory.server.core.ReferralManagerImpl;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.entry.ServerStringValue;
+import org.apache.directory.server.core.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.interceptor.NextInterceptor;
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+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.partition.PartitionNexus;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.LdapURL;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+
+
+/**
+ * An service which is responsible referral handling behavoirs.  It manages 
+ * referral handling behavoir when the {@link Context#REFERRAL} is implicitly
+ * or explicitly set to "ignore", when set to "throw" and when set to "follow". 
+ * 
+ * @org.apache.xbean.XBean
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ReferralInterceptor extends BaseInterceptor
+{
+    private static final Logger LOG = LoggerFactory.getLogger( ReferralInterceptor.class );
+
+    /** The directoryService */
+    private DirectoryService directoryService;
+    
+    private PartitionNexus nexus;
+
+    /** The attributeType registry */
+    private AttributeTypeRegistry atRegistry;
+
+    /** The global registries */
+    private Registries registries;
+
+    /** The referralManager */
+    private ReferralManager referralManager;
+
+    /** A normalized form for the SubschemaSubentry DN */
+    private String subschemaSubentryDnNorm;
+
+    
+    static private void checkRefAttributeValue( Value<?> value ) throws NamingException, LdapURLEncodingException
+    {
+        ServerStringValue ref = ( ServerStringValue ) value;
+
+        String refVal = ref.get();
+
+        LdapURL ldapUrl = new LdapURL( refVal );
+
+        // We have a LDAP URL, we have to check that :
+        // - we don't have scope specifier
+        // - we don't have filters
+        // - we don't have attribute description list
+        // - we don't have extensions
+        // - the DN is not empty
+
+        if ( ldapUrl.getScope() != SearchControls.OBJECT_SCOPE )
+        {
+            // This is the default value if we don't have any scope
+            // Let's assume that it's incorrect if we get something
+            // else in the LdapURL
+            String message = "An LDAPURL should not contains a scope";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+
+        if ( !StringTools.isEmpty( ldapUrl.getFilter() ) )
+        {
+            String message = "An LDAPURL should not contains filters";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+
+        if ( ( ldapUrl.getAttributes() != null ) && ( ldapUrl.getAttributes().size() != 0 ) )
+        {
+            String message = "An LDAPURL should not contains any description attribute list";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+
+        if ( ( ldapUrl.getExtensions() != null ) && ( ldapUrl.getExtensions().size() != 0 ) )
+        {
+            String message = "An LDAPURL should not contains any extension";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+
+        if ( ( ldapUrl.getExtensions() != null ) && ( ldapUrl.getExtensions().size() != 0 ) )
+        {
+            String message = "An LDAPURL should not contains any critical extension";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+
+        LdapDN dn = ldapUrl.getDn();
+
+        if ( ( dn == null ) || dn.isEmpty() )
+        {
+            String message = "An LDAPURL should contains a non-empty DN";
+            LOG.error( message );
+            throw new NamingException( message );
+        }
+    }
+
+    
+    static private boolean isReferral( ServerEntry entry ) throws NamingException
+    {
+        EntryAttribute oc = entry.get( SchemaConstants.OBJECT_CLASS_AT );
+
+        if ( oc == null )
+        {
+            LOG.warn( "could not find objectClass attribute in entry: " + entry );
+            return false;
+        }
+
+        if ( !oc.contains( SchemaConstants.REFERRAL_OC ) )
+        {
+            return false;
+        }
+        else
+        {
+            // We have a referral ObjectClass, let's check that the ref is
+            // valid, accordingly to the RFC
+
+            // Get the 'ref' attributeType
+            EntryAttribute refAttr = entry.get( SchemaConstants.REF_AT );
+
+            if ( refAttr == null )
+            {
+                // very unlikely, as we have already checked the entry in SchemaInterceptor
+                String message = "An entry with a 'referral' ObjectClass must contains a 'ref' Attribute";
+                LOG.error( message );
+                throw new NamingException( message );
+            }
+
+            for ( Value<?> value : refAttr )
+            {
+                try
+                {
+                    checkRefAttributeValue( value );
+                }
+                catch ( LdapURLEncodingException luee )
+                {
+                    // Either the URL is invalid, or it's not a LDAP URL.
+                    // we will just ignore this LdapURL.
+                }
+            }
+
+            return true;
+        }
+    }
+
+
+    public void init( DirectoryService directoryService ) throws Exception
+    {
+        nexus = directoryService.getPartitionNexus();
+        registries = directoryService.getRegistries();
+        atRegistry = registries.getAttributeTypeRegistry();
+        this.directoryService = directoryService;
+
+        // Initialize the referralManager
+        referralManager = new ReferralManagerImpl( directoryService );
+        directoryService.setReferralManager( referralManager );
+
+        Value<?> subschemaSubentry = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
+        LdapDN subschemaSubentryDn = new LdapDN( ( String ) ( subschemaSubentry.get() ) );
+        subschemaSubentryDn.normalize( atRegistry.getNormalizerMapping() );
+        subschemaSubentryDnNorm = subschemaSubentryDn.getNormName();
+    }
+
+
+    /**
+     * Add an entry into the server. We have 3 cases :
+     * (1) The entry does not have any parent referral and is not a referral itself
+     * (2) The entry does not have any parent referral and is a referral itself
+     * (3) The entry has a parent referral
+     * 
+     * Case (1) is easy : we inject the entry into the server and we are done.
+     * Case (2) is the same as case (1), but we have to update the referral manager.
+     * Case (3) is handled by the LdapProcotol handler, as we have to return a 
+     * LdapResult containing a list of this entry's parent's referrals URL, if the 
+     * ManageDSAIT control is not present, or the parent's entry if the control 
+     * is present. 
+     * 
+     * Of course, if the entry already exists, nothing will be done, as we will get an
+     * entryAlreadyExists error.
+     *  
+     */
+    public void add( NextInterceptor next, AddOperationContext opContext ) throws Exception
+    {
+        ServerEntry entry = opContext.getEntry();
+        
+        // Check if the entry is a referral itself
+        boolean isReferral = isReferral( entry );
+
+        // We add the entry into the server
+        next.add( opContext );
+        
+        // If the addition is successful, we update the referralManager 
+        if ( isReferral )
+        {
+            // We have to add it to the referralManager
+            referralManager.lockWrite();
+
+            referralManager.addReferral( entry );
+
+            referralManager.unlock();
+        }
+
+    }
+
+
+    /**
+     * Delete an entry in the server. We have 4 cases :
+     * (1) the entry is not a referral and does not have a parent referral
+     * (2) the entry is not a referral but has a parent referral
+     * (3) the entry is a referral
+     * 
+     * Case (1) is handled by removing the entry from the server
+     * In case (2), we return an exception build using the parent referral 
+     * For case(3), we remove the entry from the server and remove the referral
+     * from the referral manager.
+     * 
+     * If the entry does not exist in the server, we will get a NoSuchObject error
+     */
+    public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws Exception
+    {
+        ServerEntry entry = opContext.getEntry();
+
+        // First delete the entry into the server
+        next.delete( opContext );
+        
+        // Check if the entry exists and is a referral itself
+        // If so, we have to update the referralManager
+        if ( ( entry != null ) && isReferral( entry ) )
+        {
+            // We have to remove it from the referralManager
+            referralManager.lockWrite();
+
+            referralManager.removeReferral( entry );
+
+            referralManager.unlock();
+        }
+    }
+
+
+    /*
+    public void move( NextInterceptor next, MoveOperationContext opContext ) throws Exception
+    {
+        LdapDN oldName = opContext.getDn();
+
+        LdapDN newName = ( LdapDN ) opContext.getParent().clone();
+        newName.add( oldName.get( oldName.size() - 1 ) );
+
+        next.move( opContext );
+        
+        // Update the referralManager
+        LookupOperationContext lookupContext = new LookupOperationContext( opContext.getSession(), newName );
+        
+        ServerEntry newEntry = nexus.lookup( lookupContext );
+        
+        referralManager.lockWrite();
+        
+        referralManager.addReferral( newEntry );
+        referralManager.removeReferral( opContext.getEntry() );
+        
+        referralManager.unlock();
+    }
+
+
+    public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws Exception
+    {
+        LdapDN newName = ( LdapDN ) opContext.getParent().clone();
+        newName.add( opContext.getNewRdn() );
+
+        next.moveAndRename( opContext );
+        
+        // Update the referralManager
+        LookupOperationContext lookupContext = new LookupOperationContext( opContext.getSession(), newName );
+        
+        ServerEntry newEntry = nexus.lookup( lookupContext );
+        
+        referralManager.lockWrite();
+        
+        referralManager.addReferral( newEntry );
+        referralManager.removeReferral( opContext.getEntry() );
+        
+        referralManager.unlock();
+    }
+
+
+    public void rename( NextInterceptor next, RenameOperationContext opContext ) throws Exception
+    {
+        LdapDN oldName = opContext.getDn();
+
+        LdapDN newName = ( LdapDN ) oldName.clone();
+        newName.remove( oldName.size() - 1 );
+
+        newName.add( opContext.getNewRdn() );
+
+        next.rename( opContext );
+        
+        // Update the referralManager
+        LookupOperationContext lookupContext = new LookupOperationContext( opContext.getSession(), newName );
+        
+        ServerEntry newEntry = nexus.lookup( lookupContext );
+        
+        referralManager.lockWrite();
+        
+        referralManager.addReferral( newEntry );
+        referralManager.removeReferral( opContext.getEntry() );
+        
+        referralManager.unlock();
+    }
+    */
+
+    /**
+     * Modify an entry in the server.
+     */
+    public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception
+    {
+        LdapDN name = opContext.getDn();
+        
+        // handle a normal modify without following referrals
+        next.modify( opContext );
+
+        // Check if we are trying to modify the schema or the rootDSE,
+        // if so, we don't modify the referralManager
+        if ( ( name == LdapDN.EMPTY_LDAPDN ) || ( subschemaSubentryDnNorm.equals( name.getNormName() ) ) )
+        {
+            // Do nothing
+            return;
+        }
+
+        // Update the referralManager. We have to read the entry again
+        // as it has been modified, before updating the ReferralManager
+        // TODO: this can be spare, as we build the entry later.
+        // But we will have to store the modified entry into the opContext
+        LookupOperationContext lookupContext = new LookupOperationContext( opContext.getSession(), name );
+        
+        ServerEntry newEntry = nexus.lookup( lookupContext );
+
+        // Check that we have the entry, just in case
+        // TODO : entries should be locked until the operation is done on it.
+        if ( newEntry != null )
+        {
+            referralManager.lockWrite();
+
+            if ( referralManager.isReferral( newEntry.getDn() ) )
+            {
+                referralManager.removeReferral( opContext.getEntry() );
+                referralManager.addReferral( newEntry );
+            }
+            
+            referralManager.unlock();
+        }
+    }
+
+
+    /**
+     * When adding a new context partition, we have to update the referralManager
+     * by injecting all the new referrals into it. This is done using the init()
+     * method of the referralManager.
+     *
+    public void addContextPartition( NextInterceptor next, AddContextPartitionOperationContext opContext )
+        throws Exception
+    {
+        // First, inject the partition
+        next.addContextPartition( opContext );
+
+        Partition partition = opContext.getPartition();
+        LdapDN suffix = partition.getSuffixDn();
+        
+        // add referrals immediately after adding the new partition
+        referralManager.init( directoryService, new String[]{ suffix.getNormName() } );
+    }
+
+
+    /**
+     * Remove a partion's referrals from the server. We have to first
+     * clear the referrals manager from all of this partition's referrals,
+     * then we can delete the partition.
+     *
+    public void removeContextPartition( NextInterceptor next, RemoveContextPartitionOperationContext opContext )
+        throws Exception
+    {
+        // get the partition suffix
+        LdapDN suffix = opContext.getDn();
+
+        // remove referrals immediately before removing the partition
+        referralManager.remove( directoryService, suffix );
+
+        // And remove the partition from the server
+        next.removeContextPartition( opContext );
+    }*/
+}

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/sp/LdapClassLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/sp/LdapClassLoader.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/sp/LdapClassLoader.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/sp/LdapClassLoader.java Tue Oct  7 04:26:55 2008
@@ -21,8 +21,8 @@
 
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
@@ -183,13 +183,13 @@
                 
                 // TODO - why is this an operation????  Why can't we just list these damn things
                 // who went stupid crazy making everything into a damn operation  !!!! grrrr 
-                Iterator<String> suffixes = 
+                Set<String> suffixes = 
                     directoryService.getPartitionNexus().listSuffixes( 
                         new ListSuffixOperationContext( directoryService.getAdminSession() ) );
 
-                while ( suffixes.hasNext() )
+                for ( String suffix:suffixes )
                 {
-                    LdapDN dn = new LdapDN( suffixes.next() );
+                    LdapDN dn = new LdapDN( suffix );
                     dn.normalize( directoryService.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
                     namingContexts.add( dn );
                 }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Tue Oct  7 04:26:55 2008
@@ -84,6 +84,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 
 /**
@@ -157,7 +158,7 @@
         evaluator = new SubtreeEvaluator( oidRegistry, atRegistry );
 
         // prepare to find all subentries in all namingContexts
-        Iterator<String> suffixes = this.nexus.listSuffixes( null );
+        Set<String> suffixes = this.nexus.listSuffixes( null );
         ExprNode filter = new EqualityNode<String>( SchemaConstants.OBJECT_CLASS_AT, new ClientStringValue(
             SchemaConstants.SUBENTRY_OC ) );
         SearchControls controls = new SearchControls();
@@ -166,11 +167,10 @@
             { SchemaConstants.SUBTREE_SPECIFICATION_AT, SchemaConstants.OBJECT_CLASS_AT } );
 
         // search each namingContext for subentries
-        while ( suffixes.hasNext() )
+        for ( String suffix:suffixes )
         {
-            LdapDN suffix = new LdapDN( suffixes.next() );
-            //suffix = LdapDN.normalize( suffix, registry.getNormalizerMapping() );
-            suffix.normalize( atRegistry.getNormalizerMapping() );
+            LdapDN suffixDn = new LdapDN( suffix );
+            suffixDn.normalize( atRegistry.getNormalizerMapping() );
 
             LdapDN adminDn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
             adminDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
@@ -178,7 +178,7 @@
                 new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), directoryService );
 
             EntryFilteringCursor subentries = nexus.search( new SearchOperationContext( adminSession,
-                suffix, AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls ) );
+                suffixDn, AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls ) );
 
             while ( subentries.next() )
             {

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java Tue Oct  7 04:26:55 2008
@@ -55,9 +55,9 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 
 /**
@@ -110,11 +110,10 @@
         // search all naming contexts for trigger subentenries
         // generate TriggerSpecification arrays for each subentry
         // add that subentry to the hash
-        Iterator<String> suffixes = nexus.listSuffixes( null );
+        Set<String> suffixes = nexus.listSuffixes( null );
         
-        while ( suffixes.hasNext() )
+        for ( String suffix:suffixes )
         {
-            String suffix = suffixes.next();
             LdapDN baseDn = new LdapDN( suffix );
             ExprNode filter = new EqualityNode<String>( SchemaConstants.OBJECT_CLASS_AT, 
                     new ClientStringValue( ApacheSchemaConstants.TRIGGER_EXECUTION_SUBENTRY_OC ) );

Modified: directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java (original)
+++ directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java Tue Oct  7 04:26:55 2008
@@ -437,6 +437,28 @@
         public void setEntry( ClonedServerEntry entry )
         {
         }
+
+
+        public void throwReferral()
+        {
+        }
+        
+        
+        public boolean isReferralThrown()
+        {
+            return false;
+        }
+
+
+        public void ignoreReferral()
+        {
+        }
+
+
+        public boolean isReferralIgnored()
+        {
+            return false;
+        }
     }
 
     class MockDirectoryService implements DirectoryService
@@ -506,6 +528,11 @@
         }
 
 
+        public void setReferralManager( ReferralManager referralManager )
+        {
+        }
+
+
         public void setRegistries( Registries registries )
         {
         }
@@ -845,7 +872,7 @@
             return null;
         }
 
-        public Iterator<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
+        public Set<String> listSuffixes( ListSuffixOperationContext opContext ) throws Exception
         {
             return null;
         }

Modified: directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java (original)
+++ directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java Tue Oct  7 04:26:55 2008
@@ -306,6 +306,11 @@
         }
 
 
+        public void setReferralManager( ReferralManager referralManager )
+        {
+        }
+
+
         public Registries getRegistries()
         {
             return null;

Modified: directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/MockInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/MockInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/MockInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/MockInterceptor.java Tue Oct  7 04:26:55 2008
@@ -45,7 +45,7 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 
 import javax.naming.NamingException;
-import java.util.Iterator;
+import java.util.Set;
 
 
 public class MockInterceptor implements Interceptor
@@ -104,7 +104,7 @@
     }
 
 
-    public Iterator<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
+    public Set<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) throws Exception
     {
         test.interceptors.add( this );
         return next.listSuffixes( opContext );

Modified: directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java (original)
+++ directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java Tue Oct  7 04:26:55 2008
@@ -42,6 +42,7 @@
 import org.apache.directory.server.core.authz.DefaultAuthorizationInterceptor;
 import org.apache.directory.server.core.exception.ExceptionInterceptor;
 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.collective.CollectiveAttributeInterceptor;
@@ -103,6 +104,7 @@
         Set<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() );

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Tue Oct  7 04:26:55 2008
@@ -384,7 +384,7 @@
 
 
     /**
-     * Close the parttion : we have to close all the userIndices and the master table.
+     * Close the partition : we have to close all the userIndices and the master table.
      * 
      * @throws Exception lazily thrown on any closer failures to avoid leaving
      * open files

Modified: directory/apacheds/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/pom.xml?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/pom.xml (original)
+++ directory/apacheds/trunk/pom.xml Tue Oct  7 04:26:55 2008
@@ -66,12 +66,6 @@
       </dependency>
 
       <dependency>
-        <groupId>org.apache.directory.shared</groupId>
-        <artifactId>shared-bouncycastle-reduced</artifactId>
-        <version>${org.apache.directory.shared.version}</version>
-      </dependency>
-
-      <dependency>
         <groupId>org.apache.directory.daemon</groupId>
         <artifactId>daemon-bootstrappers</artifactId>
         <version>1.1.6-SNAPSHOT</version>

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java Tue Oct  7 04:26:55 2008
@@ -20,12 +20,11 @@
 package org.apache.directory.server.ldap.handlers;
 
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.message.AddRequest;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,26 +36,25 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class AddHandler extends ReferralAwareRequestHandler<AddRequest>
+public class AddHandler extends LdapRequestHandler<AddRequest>
 {
 	/** The logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( AddHandler.class );
     
     
     /**
-     * @see ReferralAwareRequestHandler#handleIgnoringReferrals(LdapSession, LdapDN, ClonedServerEntry, 
-     * org.apache.directory.shared.ldap.message.SingleReplyRequest)
+     * {@inheritDoc}
      */
-    public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, 
-        ClonedServerEntry entry, AddRequest req ) 
+    public void handle( LdapSession session, AddRequest req ) 
     {
-        LOG.debug( "Handling add request while ignoring referrals: {}", req );
+        LOG.debug( "Handling request: {}", req );
         LdapResult result = req.getResultResponse().getLdapResult();
 
         try
         {
         	// Call the underlying layer to inject the new entry 
-            session.getCoreSession().add( req );
+            CoreSession coreSession = session.getCoreSession();
+            coreSession.add( req );
 
             // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java Tue Oct  7 04:26:55 2008
@@ -20,7 +20,6 @@
 package org.apache.directory.server.ldap.handlers;
 
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.message.CompareRequest;
 import org.apache.directory.shared.ldap.message.LdapResult;
@@ -37,7 +36,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664302 $
  */
-public class CompareHandler extends ReferralAwareRequestHandler<CompareRequest>
+public class CompareHandler extends LdapRequestHandler<CompareRequest>
 {
     private static final Logger LOG = LoggerFactory.getLogger( CompareHandler.class );
 
@@ -48,8 +47,7 @@
      * org.apache.directory.shared.ldap.message.SingleReplyRequest)
      */
     @Override
-    public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, 
-        ClonedServerEntry entry, CompareRequest req )
+    public void handle( LdapSession session, CompareRequest req )
     {
         LOG.debug( "Handling compare request while ignoring referrals: {}", req );
         LdapResult result = req.getResultResponse().getLdapResult();
@@ -65,7 +63,7 @@
                 result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
             }
 
-            result.setMatchedDn( reqTargetDn );
+            result.setMatchedDn( req.getName() );
             session.getIoSession().write( req.getResultResponse() );
         }
         catch ( Exception e )

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java Tue Oct  7 04:26:55 2008
@@ -20,12 +20,11 @@
 package org.apache.directory.server.ldap.handlers;
 
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.message.DeleteRequest;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,21 +36,29 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664302 $
  */
-public class DeleteHandler extends ReferralAwareRequestHandler<DeleteRequest>
+public class DeleteHandler extends LdapRequestHandler<DeleteRequest>
 {
     private static final Logger LOG = LoggerFactory.getLogger( DeleteHandler.class );
 
 
-    public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, 
-        ClonedServerEntry entry, DeleteRequest req )
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, DeleteRequest req )
     {
-        LOG.debug( "Handling request while ignoring referrals: {}", req );
+        LOG.debug( "Handling request: {}", req );
         LdapResult result = req.getResultResponse().getLdapResult();
 
         try
         {
-            session.getCoreSession().delete( req );
+            // Call the underlying layer to delete the entry 
+            CoreSession coreSession = session.getCoreSession();
+            coreSession.delete( req );
+            
+            // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );
+            
+            // Write the DeleteResponse message
             session.getIoSession().write( req.getResultResponse() );
         }
         catch ( Exception e )

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java Tue Oct  7 04:26:55 2008
@@ -20,21 +20,31 @@
 package org.apache.directory.server.ldap.handlers;
 
 
+import javax.naming.NamingException;
+
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.ldap.LdapService;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapReferralException;
 import org.apache.directory.shared.ldap.message.AbandonRequest;
 import org.apache.directory.shared.ldap.message.BindRequest;
 import org.apache.directory.shared.ldap.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.message.LdapResult;
+import org.apache.directory.shared.ldap.message.Referral;
+import org.apache.directory.shared.ldap.message.ReferralImpl;
 import org.apache.directory.shared.ldap.message.Request;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.ResultResponse;
 import org.apache.directory.shared.ldap.message.ResultResponseRequest;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.handler.demux.MessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -45,7 +55,10 @@
  */
 public abstract class LdapRequestHandler<T extends Request> implements MessageHandler<T>
 {
-	/** The reference on the Ldap server instance */
+    /** The logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( LdapRequestHandler.class );
+
+    /** The reference on the Ldap server instance */
     protected LdapService ldapService;
 
 
@@ -194,4 +207,78 @@
      * @throws Exception If there is an error during the processing of this message
      */
     public abstract void handle( LdapSession session, T message ) throws Exception;
+    
+    
+    /**
+     * Handles processing with referrals without ManageDsaIT control.
+     */
+    public void handleException( LdapSession session, ResultResponseRequest req, Exception e )
+    {
+        LdapResult result = req.getResultResponse().getLdapResult();
+
+        /*
+         * Set the result code or guess the best option.
+         */
+        ResultCodeEnum code;
+        if ( e instanceof LdapException )
+        {
+            code = ( ( LdapException ) e ).getResultCode();
+        }
+        else
+        {
+            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+        }
+        
+        result.setResultCode( code );
+
+        /*
+         * Setup the error message to put into the request and put entire
+         * exception into the message if we are in debug mode.  Note we 
+         * embed the result code name into the message.
+         */
+        String msg = code.toString() + ": failed for " + req + ": " + e.getMessage();
+
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( msg, e );
+        
+            msg += ":\n" + ExceptionUtils.getStackTrace( e );
+        }
+        
+        result.setErrorMessage( msg );
+
+        if ( e instanceof NamingException )
+        {
+            NamingException ne = ( NamingException ) e;
+
+            // Add the matchedDN if necessary
+            boolean setMatchedDn = 
+                code == ResultCodeEnum.NO_SUCH_OBJECT             || 
+                code == ResultCodeEnum.ALIAS_PROBLEM              ||
+                code == ResultCodeEnum.INVALID_DN_SYNTAX          || 
+                code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM;
+            
+            if ( ( ne.getResolvedName() != null ) && setMatchedDn )
+            {
+                result.setMatchedDn( ( LdapDN ) ne.getResolvedName() );
+            }
+            
+            // Add the referrals if necessary
+            if ( e instanceof LdapReferralException )
+            {
+                Referral referrals = new ReferralImpl();
+                
+                do
+                {
+                    String ref = ((LdapReferralException)e).getReferralInfo();
+                    referrals.addLdapUrl( ref );
+                }
+                while ( ((LdapReferralException)e).skipReferral() );
+                
+                result.setReferral( referrals );
+            }
+        }
+
+        session.getIoSession().write( req.getResultResponse() );
+    }
 }

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java Tue Oct  7 04:26:55 2008
@@ -20,7 +20,7 @@
 package org.apache.directory.server.ldap.handlers;
 
  
-import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
@@ -37,7 +37,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664302 $
  */
-public class ModifyDnHandler extends ReferralAwareRequestHandler<ModifyDnRequest>
+public class ModifyDnHandler extends LdapRequestHandler<ModifyDnRequest>
 {
     private static final Logger LOG = LoggerFactory.getLogger( ModifyDnHandler.class );
 
@@ -58,8 +58,7 @@
      * - newSuperior : this is a move operation. The entry is removed from its
      * current location, and created in the new one.
      */
-    public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, 
-        ClonedServerEntry entry, ModifyDnRequest req )
+    public void handle( LdapSession session, ModifyDnRequest req )
     {
         LdapResult result = req.getResultResponse().getLdapResult();
         LOG.debug( "Handling modify dn request while ignoring referrals: {}", req );
@@ -87,21 +86,23 @@
             boolean rdnChanged = req.getNewRdn() != null && 
                 ! newRdn.getNormName().equals( oldRdn.getNormName() );
             
+            CoreSession coreSession = session.getCoreSession();
+            
             if ( rdnChanged )
             {
                 if ( req.getNewSuperior() != null )
                 {
-                    session.getCoreSession().moveAndRename( req );
+                    coreSession.moveAndRename( req );
                 }
                 else
                 {
-                    session.getCoreSession().rename( req );
+                    coreSession.rename( req );
                 }
             }
             else if ( req.getNewSuperior() != null )
             {
                 req.setNewRdn( null );
-                session.getCoreSession().move( req );
+                coreSession.move( req );
             }
             else
             {

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java Tue Oct  7 04:26:55 2008
@@ -20,12 +20,11 @@
 package org.apache.directory.server.ldap.handlers;
 
 
-import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.message.LdapResult;
 import org.apache.directory.shared.ldap.message.ModifyRequest;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,26 +36,29 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev: 664302 $
  */
-public class ModifyHandler extends ReferralAwareRequestHandler<ModifyRequest>
+public class ModifyHandler extends LdapRequestHandler<ModifyRequest>
 {
     private static final Logger LOG = LoggerFactory.getLogger( ModifyHandler.class );
 
 
     /**
-     * @see ReferralAwareRequestHandler#handleIgnoringReferrals(LdapSession, LdapDN, ClonedServerEntry, 
-     * org.apache.directory.shared.ldap.message.SingleReplyRequest)
+     * {@inheritDoc}
      */
-    @Override
-    public void handleIgnoringReferrals( LdapSession session, LdapDN reqTargetDn, 
-        ClonedServerEntry entry, ModifyRequest req )
+    public void handle( LdapSession session, ModifyRequest req )
     {
-        LOG.debug( "Handling modify request while ignoring referrals: {}", req );
+        LOG.debug( "Handling request : {}", req );
         LdapResult result = req.getResultResponse().getLdapResult();
 
         try
         {
-            session.getCoreSession().modify( req );
+            // Call the underlying layer to delete the entry
+            CoreSession coreSession = session.getCoreSession();
+            coreSession.modify( req );
+            
+            // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );
+            
+            // Write the DeleteResponse message
             session.getIoSession().write( req.getResultResponse() );
         }
         catch ( Exception e )



Mime
View raw message