directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1414588 [1/3] - in /directory/apacheds/trunk/protocol-ldap/src: main/java/org/apache/directory/server/ldap/ main/java/org/apache/directory/server/ldap/handlers/ main/java/org/apache/directory/server/ldap/handlers/request/ main/java/org/apa...
Date Wed, 28 Nov 2012 08:53:13 GMT
Author: elecharny
Date: Wed Nov 28 08:53:09 2012
New Revision: 1414588

URL: http://svn.apache.org/viewvc?rev=1414588&view=rev
Log:
o Added the handlers for the MessageSent event
o Adding missing Javadocs

Added:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AbandonRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AddRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/CompareRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/DeleteRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ExtendedRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ModifyDnRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ModifyRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/SearchRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/UnbindRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/AddResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/BindResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/CompareResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/DeleteResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/ExtendedResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/IntermediateResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/ModifyDnResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/ModifyResponseHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/SearchResultDoneHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/SearchResultEntryHandler.java   (with props)
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/response/SearchResultReferenceHandler.java   (with props)
Removed:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AbandonHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ExtendedHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/UnbindHandler.java
Modified:
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java
    directory/apacheds/trunk/protocol-ldap/src/test/java/org/apache/directory/server/ldap/SettingAlternativeHandlersTest.java

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java?rev=1414588&r1=1414587&r2=1414588&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java Wed Nov 28 08:53:09 2012
@@ -34,6 +34,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.ResultResponse;
 import org.apache.directory.shared.ldap.model.message.ResultResponseRequest;
 import org.apache.directory.shared.ldap.model.message.extended.NoticeOfDisconnect;
+import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.service.IoHandler;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.ssl.SslFilter;
@@ -153,6 +154,13 @@ class LdapProtocolHandler extends Demuxi
     {
         // Do nothing : we have to ignore this message, otherwise we get an exception,
         // thanks to the way MINA 2 works ...
+        if ( message instanceof IoBuffer )
+        {
+            // Nothing to do in this case
+            return;
+        }
+
+        super.messageSent( session, message );
     }
 
 

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java?rev=1414588&r1=1414587&r2=1414588&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java Wed Nov 28 08:53:09 2012
@@ -40,19 +40,31 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.partition.PartitionNexus;
 import org.apache.directory.server.core.security.CoreKeyStoreSpi;
 import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.ldap.handlers.AbandonHandler;
-import org.apache.directory.server.ldap.handlers.AddHandler;
-import org.apache.directory.server.ldap.handlers.BindHandler;
-import org.apache.directory.server.ldap.handlers.CompareHandler;
-import org.apache.directory.server.ldap.handlers.DeleteHandler;
-import org.apache.directory.server.ldap.handlers.ExtendedHandler;
 import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
-import org.apache.directory.server.ldap.handlers.ModifyDnHandler;
-import org.apache.directory.server.ldap.handlers.ModifyHandler;
-import org.apache.directory.server.ldap.handlers.SearchHandler;
-import org.apache.directory.server.ldap.handlers.UnbindHandler;
+import org.apache.directory.server.ldap.handlers.LdapResponseHandler;
 import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.server.ldap.handlers.request.AbandonRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.AddRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.BindRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.CompareRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.DeleteRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.ExtendedRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.ModifyDnRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.ModifyRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.SearchRequestHandler;
+import org.apache.directory.server.ldap.handlers.request.UnbindRequestHandler;
+import org.apache.directory.server.ldap.handlers.response.AddResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.BindResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.CompareResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.DeleteResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.ExtendedResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.IntermediateResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.ModifyDnResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.ModifyResponseHandler;
+import org.apache.directory.server.ldap.handlers.response.SearchResultDoneHandler;
+import org.apache.directory.server.ldap.handlers.response.SearchResultEntryHandler;
+import org.apache.directory.server.ldap.handlers.response.SearchResultReferenceHandler;
 import org.apache.directory.server.ldap.handlers.ssl.LdapsInitializer;
 import org.apache.directory.server.ldap.replication.consumer.ReplicationConsumer;
 import org.apache.directory.server.ldap.replication.provider.ReplicationRequestHandler;
@@ -65,14 +77,24 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapConfigurationException;
 import org.apache.directory.shared.ldap.model.message.AbandonRequest;
 import org.apache.directory.shared.ldap.model.message.AddRequest;
+import org.apache.directory.shared.ldap.model.message.AddResponse;
 import org.apache.directory.shared.ldap.model.message.BindRequest;
+import org.apache.directory.shared.ldap.model.message.BindResponse;
 import org.apache.directory.shared.ldap.model.message.CompareRequest;
+import org.apache.directory.shared.ldap.model.message.CompareResponse;
 import org.apache.directory.shared.ldap.model.message.DeleteRequest;
+import org.apache.directory.shared.ldap.model.message.DeleteResponse;
 import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
+import org.apache.directory.shared.ldap.model.message.IntermediateResponse;
 import org.apache.directory.shared.ldap.model.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.model.message.ModifyDnResponse;
 import org.apache.directory.shared.ldap.model.message.ModifyRequest;
+import org.apache.directory.shared.ldap.model.message.ModifyResponse;
 import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchResultDone;
+import org.apache.directory.shared.ldap.model.message.SearchResultEntry;
+import org.apache.directory.shared.ldap.model.message.SearchResultReference;
 import org.apache.directory.shared.ldap.model.message.UnbindRequest;
 import org.apache.directory.shared.ldap.model.message.extended.NoticeOfDisconnect;
 import org.apache.directory.shared.util.Strings;
@@ -171,16 +193,30 @@ public class LdapServer extends Director
     private List<String> saslRealms;
 
     /** The protocol handlers */
-    private LdapRequestHandler<AbandonRequest> abandonHandler;
-    private LdapRequestHandler<AddRequest> addHandler;
-    private LdapRequestHandler<BindRequest> bindHandler;
-    private LdapRequestHandler<CompareRequest> compareHandler;
-    private LdapRequestHandler<DeleteRequest> deleteHandler;
-    private ExtendedHandler extendedHandler;
-    private LdapRequestHandler<ModifyRequest> modifyHandler;
-    private LdapRequestHandler<ModifyDnRequest> modifyDnHandler;
-    private LdapRequestHandler<SearchRequest> searchHandler;
-    private LdapRequestHandler<UnbindRequest> unbindHandler;
+    // MessageReceived handlers
+    private LdapRequestHandler<AbandonRequest> abandonRequestHandler;
+    private LdapRequestHandler<AddRequest> addRequestHandler;
+    private LdapRequestHandler<BindRequest> bindRequestHandler;
+    private LdapRequestHandler<CompareRequest> compareRequestHandler;
+    private LdapRequestHandler<DeleteRequest> deleteRequestHandler;
+    private ExtendedRequestHandler extendedRequestHandler;
+    private LdapRequestHandler<ModifyRequest> modifyRequestHandler;
+    private LdapRequestHandler<ModifyDnRequest> modifyDnRequestHandler;
+    private LdapRequestHandler<SearchRequest> searchRequestHandler;
+    private LdapRequestHandler<UnbindRequest> unbindRequestHandler;
+    
+    // MessageSent handlers
+    private LdapResponseHandler<AddResponse> addResponseHandler;
+    private LdapResponseHandler<BindResponse> bindResponseHandler;
+    private LdapResponseHandler<CompareResponse> compareResponseHandler;
+    private LdapResponseHandler<DeleteResponse> deleteResponseHandler;
+    private ExtendedResponseHandler extendedResponseHandler;
+    private LdapResponseHandler<ModifyResponse> modifyResponseHandler;
+    private LdapResponseHandler<IntermediateResponse> intermediateResponseHandler;
+    private LdapResponseHandler<ModifyDnResponse> modifyDnResponseHandler;
+    private LdapResponseHandler<SearchResultEntry> searchResultEntryHandler;
+    private LdapResponseHandler<SearchResultReference> searchResultReferenceHandler;
+    private LdapResponseHandler<SearchResultDone> searchResultDoneHandler;
 
     /** the underlying provider codec factory */
     private ProtocolCodecFactory codecFactory = LdapApiServiceFactory.getSingleton().getProtocolCodecFactory();
@@ -235,56 +271,66 @@ public class LdapServer extends Director
      */
     private void installDefaultHandlers()
     {
-        if ( getAbandonHandler() == null )
+        if ( getAbandonRequestHandler() == null )
         {
-            setAbandonHandler( new AbandonHandler() );
+            setAbandonHandler( new AbandonRequestHandler() );
         }
 
-        if ( getAddHandler() == null )
+        if ( getAddRequestHandler() == null )
         {
-            setAddHandler( new AddHandler() );
+            setAddHandlers( new AddRequestHandler(), new AddResponseHandler() );
+        }
+
+        if ( getBindRequestHandler() == null )
+        {
+            BindRequestHandler bindRequestHandler = new BindRequestHandler();
+            bindRequestHandler.setSaslMechanismHandlers( saslMechanismHandlers );
+            
+            setBindHandlers( bindRequestHandler, new BindResponseHandler() );
         }
 
-        if ( getBindHandler() == null )
+        if ( getCompareRequestHandler() == null )
         {
-            BindHandler handler = new BindHandler();
-            handler.setSaslMechanismHandlers( saslMechanismHandlers );
-            setBindHandler( handler );
+            setCompareHandlers( new CompareRequestHandler(), new CompareResponseHandler() );
         }
 
-        if ( getCompareHandler() == null )
+        if ( getDeleteRequestHandler() == null )
         {
-            setCompareHandler( new CompareHandler() );
+            setDeleteHandlers( new DeleteRequestHandler(), new DeleteResponseHandler() );
         }
 
-        if ( getDeleteHandler() == null )
+        if ( getExtendedRequestHandler() == null )
         {
-            setDeleteHandler( new DeleteHandler() );
+            setExtendedHandlers( new ExtendedRequestHandler(), new ExtendedResponseHandler() );
         }
 
-        if ( getExtendedHandler() == null )
+        if ( getIntermediateResponseHandler() == null )
         {
-            setExtendedHandler( new ExtendedHandler() );
+            setIntermediateHandler( new IntermediateResponseHandler() );
         }
 
-        if ( getModifyHandler() == null )
+        if ( getModifyRequestHandler() == null )
         {
-            setModifyHandler( new ModifyHandler() );
+            setModifyHandlers( new ModifyRequestHandler(), new ModifyResponseHandler() );
         }
 
-        if ( getModifyDnHandler() == null )
+        if ( getModifyDnRequestHandler() == null )
         {
-            setModifyDnHandler( new ModifyDnHandler() );
+            setModifyDnHandlers( new ModifyDnRequestHandler(), new ModifyDnResponseHandler() );
         }
 
-        if ( getSearchHandler() == null )
+        if ( getSearchRequestHandler() == null )
         {
-            setSearchHandler( new SearchHandler() );
+            setSearchHandlers( new SearchRequestHandler(), 
+                new SearchResultEntryHandler(),
+                new SearchResultReferenceHandler(),
+                new SearchResultDoneHandler()
+                );
         }
 
-        if ( getUnbindHandler() == null )
+        if ( getUnbindRequestHandler() == null )
         {
-            setUnbindHandler( new UnbindHandler() );
+            setUnbindHandler( new UnbindRequestHandler() );
         }
     }
 
@@ -494,7 +540,7 @@ public class LdapServer extends Director
         if ( replicationReqHandler != null )
         {
             replicationReqHandler.start( this );
-            ( ( SearchHandler ) getSearchHandler() ).setReplicationReqHandler( replicationReqHandler );
+            ( ( SearchRequestHandler ) getSearchRequestHandler() ).setReplicationReqHandler( replicationReqHandler );
         }
     }
 
@@ -1025,174 +1071,419 @@ public class LdapServer extends Director
     }
 
 
-    public MessageHandler<AbandonRequest> getAbandonHandler()
+    /**
+     * @return The MessageReceived handler for the AbandonRequest
+     */
+    public MessageHandler<AbandonRequest> getAbandonRequestHandler()
     {
-        return abandonHandler;
+        return abandonRequestHandler;
     }
 
 
     /**
-     * @param abandonHandler The AbandonRequest handler
+     * Inject the MessageReceived handler into the IoHandler
+     * 
+     * @param abandonRequestdHandler The AbandonRequest message received handler
      */
-    public void setAbandonHandler( LdapRequestHandler<AbandonRequest> abandonHandler )
+    public void setAbandonHandler( LdapRequestHandler<AbandonRequest> abandonRequestdHandler )
     {
         this.handler.removeReceivedMessageHandler( AbandonRequest.class );
-        this.abandonHandler = abandonHandler;
-        this.abandonHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( AbandonRequest.class, this.abandonHandler );
+        this.abandonRequestHandler = abandonRequestdHandler;
+        this.abandonRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( AbandonRequest.class, this.abandonRequestHandler );
     }
 
 
-    public LdapRequestHandler<AddRequest> getAddHandler()
+    /**
+     * @return The MessageReceived handler for the AddRequest
+     */
+    public LdapRequestHandler<AddRequest> getAddRequestHandler()
+    {
+        return addRequestHandler;
+    }
+
+
+    /**
+     * @return The MessageSent handler for the AddResponse
+     */
+    public LdapResponseHandler<AddResponse> getAddResponseHandler()
     {
-        return addHandler;
+        return addResponseHandler;
     }
 
 
     /**
-     * @param addHandler The AddRequest handler
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param addRequestHandler The AddRequest message received handler
+     * @param addResponseHandler The AddResponse message sent handler
      */
-    public void setAddHandler( LdapRequestHandler<AddRequest> addHandler )
+    public void setAddHandlers( LdapRequestHandler<AddRequest> addRequestHandler, 
+        LdapResponseHandler<AddResponse> addResponseHandler )
     {
         this.handler.removeReceivedMessageHandler( AddRequest.class );
-        this.addHandler = addHandler;
-        this.addHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( AddRequest.class, this.addHandler );
+        this.addRequestHandler = addRequestHandler;
+        this.addRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( AddRequest.class, this.addRequestHandler );
+        
+        this.handler.removeSentMessageHandler( AddResponse.class );
+        this.addResponseHandler = addResponseHandler;
+        this.addResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( AddResponse.class, this.addResponseHandler );
     }
 
 
-    public LdapRequestHandler<BindRequest> getBindHandler()
+    /**
+     * @return The MessageReceived handler for the BindRequest
+     */
+    public LdapRequestHandler<BindRequest> getBindRequestHandler()
     {
-        return bindHandler;
+        return bindRequestHandler;
     }
 
 
     /**
-     * @param bindHandler The BindRequest handler
+     * @return The MessageSent handler for the BindResponse
      */
-    public void setBindHandler( LdapRequestHandler<BindRequest> bindHandler )
+    public LdapResponseHandler<BindResponse> getBindResponseHandler()
     {
-        this.bindHandler = bindHandler;
-        this.bindHandler.setLdapServer( this );
+        return bindResponseHandler;
+    }
 
+
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param bindRequestHandler The BindRequest message received handler
+     * @param bindResponseHandler The BindResponse message sent handler
+     */
+    public void setBindHandlers( LdapRequestHandler<BindRequest> bindRequestHandler,
+        LdapResponseHandler<BindResponse> bindResponseHandler)
+    {
         handler.removeReceivedMessageHandler( BindRequest.class );
-        handler.addReceivedMessageHandler( BindRequest.class, this.bindHandler );
+        this.bindRequestHandler = bindRequestHandler;
+        this.bindRequestHandler.setLdapServer( this );
+        handler.addReceivedMessageHandler( BindRequest.class, this.bindRequestHandler );
+        
+        handler.removeSentMessageHandler( BindResponse.class );
+        this.bindResponseHandler = bindResponseHandler;
+        this.bindResponseHandler.setLdapServer( this );
+        handler.addSentMessageHandler( BindResponse.class, this.bindResponseHandler );
     }
 
 
-    public LdapRequestHandler<CompareRequest> getCompareHandler()
+    /**
+     * @return The MessageReceived handler for the CompareRequest
+     */
+    public LdapRequestHandler<CompareRequest> getCompareRequestHandler()
     {
-        return compareHandler;
+        return compareRequestHandler;
     }
 
 
     /**
-     * @param compareHandler The CompareRequest handler
+     * @return The MessageSent handler for the CompareResponse
      */
-    public void setCompareHandler( LdapRequestHandler<CompareRequest> compareHandler )
+    public LdapResponseHandler<CompareResponse> getCompareResponseHandler()
     {
-        this.handler.removeReceivedMessageHandler( CompareRequest.class );
-        this.compareHandler = compareHandler;
-        this.compareHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareHandler );
+        return compareResponseHandler;
     }
 
 
-    public LdapRequestHandler<DeleteRequest> getDeleteHandler()
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param compareRequestHandler The CompareRequest message received handler
+     * @param compareResponseHandler The CompareResponse message sent handler
+     */
+    public void setCompareHandlers( LdapRequestHandler<CompareRequest> compareRequestHandler,
+        LdapResponseHandler<CompareResponse> compareResponseHandler)
     {
-        return deleteHandler;
+        handler.removeReceivedMessageHandler( CompareRequest.class );
+        this.compareRequestHandler = compareRequestHandler;
+        this.compareRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( CompareRequest.class, this.compareRequestHandler );
+
+        handler.removeReceivedMessageHandler( CompareResponse.class );
+        this.compareResponseHandler = compareResponseHandler;
+        this.compareResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( CompareResponse.class, this.compareResponseHandler );
     }
 
 
     /**
-     * @param deleteHandler The DeleteRequest handler
+     * @return The MessageReceived handler for the DeleteRequest
      */
-    public void setDeleteHandler( LdapRequestHandler<DeleteRequest> deleteHandler )
+    public LdapRequestHandler<DeleteRequest> getDeleteRequestHandler()
     {
-        this.handler.removeReceivedMessageHandler( DeleteRequest.class );
-        this.deleteHandler = deleteHandler;
-        this.deleteHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( DeleteRequest.class, this.deleteHandler );
+        return deleteRequestHandler;
     }
 
 
-    public LdapRequestHandler<ExtendedRequest<ExtendedResponse>> getExtendedHandler()
+    /**
+     * @return The MessageSent handler for the DeleteResponse
+     */
+    public LdapResponseHandler<DeleteResponse> getDeleteResponseHandler()
+    {
+        return deleteResponseHandler;
+    }
+
+
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param deleteRequestHandler The DeleteRequest message received handler
+     * @param deleteResponseHandler The DeleteResponse message sent handler
+     */
+    public void setDeleteHandlers( LdapRequestHandler<DeleteRequest> deleteRequestHandler,
+        LdapResponseHandler<DeleteResponse> deleteResponseHandler)
+    {
+        handler.removeReceivedMessageHandler( DeleteRequest.class );
+        this.deleteRequestHandler = deleteRequestHandler;
+        this.deleteRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( DeleteRequest.class, this.deleteRequestHandler );
+
+        handler.removeSentMessageHandler( DeleteResponse.class );
+        this.deleteResponseHandler = deleteResponseHandler;
+        this.deleteResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( DeleteResponse.class, this.deleteResponseHandler );
+    }
+
+
+    /**
+     * @return The MessageReceived handler for the ExtendedRequest
+     */
+    public LdapRequestHandler<ExtendedRequest<ExtendedResponse>> getExtendedRequestHandler()
     {
-        return extendedHandler;
+        return extendedRequestHandler;
+    }
+    
+    
+    /**
+     * @return The MessageSent handler for the ExtendedResponse
+     */
+    public LdapResponseHandler<ExtendedResponse> getExtendedResponseHandler()
+    {
+        return extendedResponseHandler;
     }
 
 
     /**
-     * @param extendedHandler The ExtendedRequest handler
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param extendedRequestHandler The ExtendedRequest message received handler
+     * @param extendedResponseHandler The ExtendedResponse message sent handler
      */
     @SuppressWarnings(
         { "unchecked", "rawtypes" })
-    public void setExtendedHandler( ExtendedHandler extendedHandler )
+    public void setExtendedHandlers( ExtendedRequestHandler extendedRequestHandler,
+        ExtendedResponseHandler extendedResponseHandler )
+    {
+        handler.removeReceivedMessageHandler( ExtendedRequest.class );
+        this.extendedRequestHandler = extendedRequestHandler;
+        this.extendedRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( ExtendedRequest.class, ( LdapRequestHandler ) this.extendedRequestHandler );
+
+        handler.removeSentMessageHandler( ExtendedResponse.class );
+        this.extendedResponseHandler = extendedResponseHandler;
+        this.extendedResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( ExtendedResponse.class, ( LdapResponseHandler ) this.extendedResponseHandler );
+    }
+
+
+    /**
+     * @return The MessageSent handler for the IntermediateResponse
+     */
+    public LdapResponseHandler<IntermediateResponse> getIntermediateResponseHandler()
+    {
+        return intermediateResponseHandler;
+    }
+
+
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param intermediateResponseHandler The IntermediateResponse message sent handler
+     */
+    public void setIntermediateHandler( LdapResponseHandler<IntermediateResponse> intermediateResponseHandler)
     {
-        this.handler.removeReceivedMessageHandler( ExtendedRequest.class );
-        this.extendedHandler = extendedHandler;
-        this.extendedHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( ExtendedRequest.class, ( LdapRequestHandler ) this.extendedHandler );
+        handler.removeSentMessageHandler( IntermediateResponse.class );
+        this.intermediateResponseHandler = intermediateResponseHandler;
+        this.intermediateResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( IntermediateResponse.class, this.intermediateResponseHandler );
     }
 
 
-    public LdapRequestHandler<ModifyRequest> getModifyHandler()
+    /**
+     * @return The MessageReceived handler for the ModifyRequest
+     */
+    public LdapRequestHandler<ModifyRequest> getModifyRequestHandler()
     {
-        return modifyHandler;
+        return modifyRequestHandler;
     }
 
 
     /**
-     * @param modifyHandler The ModifyRequest handler
+     * @return The MessageSent handler for the ModifyResponse
      */
-    public void setModifyHandler( LdapRequestHandler<ModifyRequest> modifyHandler )
+    public LdapResponseHandler<ModifyResponse> getModifyResponseHandler()
     {
-        this.handler.removeReceivedMessageHandler( ModifyRequest.class );
-        this.modifyHandler = modifyHandler;
-        this.modifyHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( ModifyRequest.class, this.modifyHandler );
+        return modifyResponseHandler;
     }
 
 
-    public LdapRequestHandler<ModifyDnRequest> getModifyDnHandler()
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param modifyRequestHandler The ModifyRequest message received handler
+     * @param modifyResponseHandler The ModifyResponse message sent handler
+     */
+    public void setModifyHandlers( LdapRequestHandler<ModifyRequest> modifyRequestHandler,
+        LdapResponseHandler<ModifyResponse> modifyResponseHandler)
+    {
+        handler.removeReceivedMessageHandler( ModifyRequest.class );
+        this.modifyRequestHandler = modifyRequestHandler;
+        this.modifyRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( ModifyRequest.class, this.modifyRequestHandler );
+
+        handler.removeSentMessageHandler( ModifyResponse.class );
+        this.modifyResponseHandler = modifyResponseHandler;
+        this.modifyResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( ModifyResponse.class, this.modifyResponseHandler );
+    }
+
+
+    /**
+     * @return The MessageSent handler for the ModifyDnRequest
+     */
+    public LdapRequestHandler<ModifyDnRequest> getModifyDnRequestHandler()
     {
-        return modifyDnHandler;
+        return modifyDnRequestHandler;
     }
 
 
     /**
-     * @param modifyDnHandler The ModifyDNRequest handler
+     * @return The MessageSent handler for the ModifyDnResponse
      */
-    public void setModifyDnHandler( LdapRequestHandler<ModifyDnRequest> modifyDnHandler )
+    public LdapResponseHandler<ModifyDnResponse> getModifyDnResponseHandler()
     {
-        this.handler.removeReceivedMessageHandler( ModifyDnRequest.class );
-        this.modifyDnHandler = modifyDnHandler;
-        this.modifyDnHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( ModifyDnRequest.class, this.modifyDnHandler );
+        return modifyDnResponseHandler;
     }
 
 
-    public LdapRequestHandler<SearchRequest> getSearchHandler()
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param modifyDnRequestHandler The ModifyDnRequest message received handler
+     * @param modifyDnResponseHandler The ModifyDnResponse message sent handler
+     */
+    public void setModifyDnHandlers( LdapRequestHandler<ModifyDnRequest> modifyDnRequestHandler,
+        LdapResponseHandler<ModifyDnResponse> modifyDnResponseHandler)
+    {
+        handler.removeReceivedMessageHandler( ModifyDnRequest.class );
+        this.modifyDnRequestHandler = modifyDnRequestHandler;
+        this.modifyDnRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( ModifyDnRequest.class, this.modifyDnRequestHandler );
+        
+        handler.removeSentMessageHandler( ModifyDnResponse.class );
+        this.modifyDnResponseHandler = modifyDnResponseHandler;
+        this.modifyDnResponseHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( ModifyDnResponse.class, this.modifyDnResponseHandler );
+    }
+
+
+    /**
+     * @return The MessageReceived handler for the SearchRequest
+     */
+    public LdapRequestHandler<SearchRequest> getSearchRequestHandler()
+    {
+        return searchRequestHandler;
+    }
+
+
+    /**
+     * @return The MessageSent handler for the SearchResultEntry
+     */
+    public LdapResponseHandler<SearchResultEntry> getSearchResultEntryHandler()
     {
-        return searchHandler;
+        return searchResultEntryHandler;
     }
 
 
     /**
-     * @param searchHandler The SearchRequest handler
+     * @return The MessageSent handler for the SearchResultReference
      */
-    public void setSearchHandler( LdapRequestHandler<SearchRequest> searchHandler )
+    public LdapResponseHandler<SearchResultReference> getSearchResultReferenceHandler()
+    {
+        return searchResultReferenceHandler;
+    }
+
+
+    /**
+     * @return The MessageSent handler for the SearchResultDone
+     */
+    public LdapResponseHandler<SearchResultDone> getSearchResultDoneHandler()
+    {
+        return searchResultDoneHandler;
+    }
+
+
+    /**
+     * Inject the MessageReceived and MessageSent handler into the IoHandler
+     * 
+     * @param searchRequestHandler The SearchRequest message received handler
+     * @param searchResultEntryHandler The SearchResultEntry message sent handler
+     * @param searchResultReferenceHandler The SearchResultReference message sent handler
+     * @param searchResultDoneHandler The SearchResultDone message sent handler
+     */
+    public void setSearchHandlers( LdapRequestHandler<SearchRequest> searchRequestHandler,
+        LdapResponseHandler<SearchResultEntry> searchResultEntryHandler,
+        LdapResponseHandler<SearchResultReference> searchResultReferenceHandler,
+        LdapResponseHandler<SearchResultDone> searchResultDoneHandler
+        )
     {
         this.handler.removeReceivedMessageHandler( SearchRequest.class );
-        this.searchHandler = searchHandler;
-        this.searchHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( SearchRequest.class, this.searchHandler );
+        this.searchRequestHandler = searchRequestHandler;
+        this.searchRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( SearchRequest.class, this.searchRequestHandler );
+
+        this.handler.removeSentMessageHandler( SearchResultEntry.class );
+        this.searchResultEntryHandler = searchResultEntryHandler;
+        this.searchResultEntryHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( SearchResultEntry.class, this.searchResultEntryHandler );
+
+        this.handler.removeSentMessageHandler( SearchResultReference.class );
+        this.searchResultReferenceHandler = searchResultReferenceHandler;
+        this.searchResultReferenceHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( SearchResultReference.class, this.searchResultReferenceHandler );
+
+        this.handler.removeSentMessageHandler( SearchResultDone.class );
+        this.searchResultDoneHandler = searchResultDoneHandler;
+        this.searchResultDoneHandler.setLdapServer( this );
+        this.handler.addSentMessageHandler( SearchResultDone.class, this.searchResultDoneHandler );
+    }
+
+
+    /**
+     * @return The MessageReceived handler for the UnbindRequest
+     */
+    public LdapRequestHandler<UnbindRequest> getUnbindRequestHandler()
+    {
+        return unbindRequestHandler;
     }
 
 
-    public LdapRequestHandler<UnbindRequest> getUnbindHandler()
+    /**
+     * Inject the MessageReceived handler into the IoHandler
+     * 
+     * @param unbindRequestHandler The UnbindRequest message received handler
+     */
+    public void setUnbindHandler( LdapRequestHandler<UnbindRequest> unbindRequestHandler )
     {
-        return unbindHandler;
+        this.handler.removeReceivedMessageHandler( UnbindRequest.class );
+        this.unbindRequestHandler = unbindRequestHandler;
+        this.unbindRequestHandler.setLdapServer( this );
+        this.handler.addReceivedMessageHandler( UnbindRequest.class, this.unbindRequestHandler );
     }
 
 
@@ -1252,18 +1543,6 @@ public class LdapServer extends Director
     }
 
 
-    /**
-     * @param unbindHandler The UnbindRequest handler
-     */
-    public void setUnbindHandler( LdapRequestHandler<UnbindRequest> unbindHandler )
-    {
-        this.handler.removeReceivedMessageHandler( UnbindRequest.class );
-        this.unbindHandler = unbindHandler;
-        this.unbindHandler.setLdapServer( this );
-        this.handler.addReceivedMessageHandler( UnbindRequest.class, this.unbindHandler );
-    }
-
-
     public boolean isStarted()
     {
         return started;

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,97 @@
+/*
+ *  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.ldap.handlers;
+
+
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.shared.ldap.model.message.Response;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.handler.demux.MessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A base class for all LDAP response handlers.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class LdapResponseHandler<T extends Response> implements MessageHandler<T>
+{
+    /** The logger for this class */
+    protected static final Logger LOG = LoggerFactory.getLogger( LdapResponseHandler.class );
+
+    /** The reference on the Ldap server instance */
+    protected LdapServer ldapServer;
+
+    /**
+     * @return The associated ldap server instance
+     */
+    public final LdapServer getLdapServer()
+    {
+        return ldapServer;
+    }
+
+
+    /**
+     * Associates a Ldap server instance to the message handler
+     * @param ldapServer the associated ldap server instance
+     */
+    public final void setLdapServer( LdapServer ldapServer )
+    {
+        this.ldapServer = ldapServer;
+    }
+
+
+    /**
+     *{@inheritDoc} 
+     */
+    public final void handleMessage( IoSession session, T message ) throws Exception
+    {
+        LdapSession ldapSession = ldapServer.getLdapSessionManager().getLdapSession( session );
+
+        if ( ldapSession == null )
+        {
+            // in some cases the session is becoming null though the client is sending the UnbindRequest
+            // before closing
+            LOG.info( "ignoring the message {} received from null session", message );
+            
+            return;
+        }
+
+        // TODO - session you get from LdapServer should have the ldapServer 
+        // member already set no?  Should remove these lines where ever they
+        // may be if that's the case.
+        ldapSession.setLdapServer( ldapServer );
+
+        handle( ldapSession, message );
+    }
+
+
+    /**
+     * Handle a Ldap message associated with a session
+     * 
+     * @param session The associated session
+     * @param message The message we have to handle
+     * @throws Exception If there is an error during the processing of this message
+     */
+    public abstract void handle( LdapSession session, T message ) throws Exception;
+}

Propchange: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapResponseHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java?rev=1414588&r1=1414587&r2=1414588&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/PersistentSearchListener.java Wed Nov 28 08:53:09 2012
@@ -64,7 +64,7 @@ public class PersistentSearchListener im
     final PersistentSearch psearchControl;
 
 
-    PersistentSearchListener( LdapSession session, SearchRequest req )
+    public PersistentSearchListener( LdapSession session, SearchRequest req )
     {
         this.session = session;
         this.req = req;

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AbandonRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AbandonRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AbandonRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AbandonRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,49 @@
+/*
+ *   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.ldap.handlers.request;
+
+
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.shared.ldap.model.message.AbandonRequest;
+
+
+/**
+ * AbandonRequest message received handler implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbandonRequestHandler extends LdapRequestHandler<AbandonRequest>
+{
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, AbandonRequest request ) throws Exception
+    {
+        int abandonedId = request.getAbandoned();
+
+        if ( abandonedId < 0 )
+        {
+            return;
+        }
+
+        session.abandonOutstandingRequest( abandonedId );
+    }
+}

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AddRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AddRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AddRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/AddRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,70 @@
+/*
+ *   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.ldap.handlers.request;
+
+
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.shared.ldap.model.message.AddRequest;
+import org.apache.directory.shared.ldap.model.message.LdapResult;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An LDAP add operation {@link AddRequest} MessageReceived handler.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddRequestHandler extends LdapRequestHandler<AddRequest>
+{
+    /** The logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( AddRequestHandler.class );
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, AddRequest req )
+    {
+        LOG.debug( "Handling request: {}", req );
+        LdapResult result = req.getResultResponse().getLdapResult();
+
+        try
+        {
+            // Call the underlying layer to inject the new entry 
+            CoreSession coreSession = session.getCoreSession();
+            coreSession.add( req );
+
+            // If success, here now, otherwise, we would have an exception.
+            result.setResultCode( ResultCodeEnum.SUCCESS );
+
+            // Write the AddResponse message
+            session.getIoSession().write( req.getResultResponse() );
+        }
+        catch ( Exception e )
+        {
+            handleException( session, req, e );
+        }
+    }
+}

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,616 @@
+/*
+ *  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.ldap.handlers.request;
+
+
+import java.util.Map;
+
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.OperationEnum;
+import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.interceptor.context.BindOperationContext;
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.ldap.LdapProtocolUtils;
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.SaslConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapAuthenticationException;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+import org.apache.directory.shared.ldap.model.message.BindRequest;
+import org.apache.directory.shared.ldap.model.message.BindResponse;
+import org.apache.directory.shared.ldap.model.message.LdapResult;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.util.StringConstants;
+import org.apache.directory.shared.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A single reply MessageReceived handler for {@link BindRequest}s.
+ *
+ * Implements server-side of RFC 2222, sections 4.2 and 4.3.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BindRequestHandler extends LdapRequestHandler<BindRequest>
+{
+    private static final Logger LOG = LoggerFactory.getLogger( BindRequestHandler.class );
+
+    /** A Hashed Adapter mapping SASL mechanisms to their handlers. */
+    private Map<String, MechanismHandler> handlers;
+
+
+    /**
+     * Set the mechanisms handler map.
+     * 
+     * @param handlers The associations btween a machanism and its handler
+     */
+    public void setSaslMechanismHandlers( Map<String, MechanismHandler> handlers )
+    {
+        this.handlers = handlers;
+    }
+
+
+    /**
+     * Handle the Simple authentication.
+     *
+     * @param ldapSession The associated Session
+     * @param bindRequest The BindRequest received
+     * @throws Exception If the authentication cannot be done
+     */
+    // This will suppress PMD.EmptyCatchBlock warnings in this method
+    @SuppressWarnings("PMD.EmptyCatchBlock")
+    public void handleSimpleAuth( LdapSession ldapSession, BindRequest bindRequest ) throws Exception
+    {
+        // if the user is already bound, we have to unbind him
+        if ( ldapSession.isAuthenticated() )
+        {
+            // We already have a bound session for this user. We have to
+            // abandon it first.
+            ldapSession.getCoreSession().unbind();
+        }
+
+        // Set the status to SimpleAuthPending
+        ldapSession.setSimpleAuthPending();
+
+        // Now, bind the user
+
+        // create a new Bind context, with a null session, as we don't have 
+        // any context yet.
+        BindOperationContext bindContext = new BindOperationContext( null );
+
+        // Stores the Dn of the user to check, and its password
+        bindContext.setDn( bindRequest.getDn() );
+        bindContext.setCredentials( bindRequest.getCredentials() );
+        bindContext.setIoSession( ldapSession.getIoSession() );
+        bindContext.setInterceptors( ldapServer.getDirectoryService().getInterceptors( OperationEnum.BIND ) );
+
+        // Stores the request controls into the operation context
+        LdapProtocolUtils.setRequestControls( bindContext, bindRequest );
+
+        try
+        {
+            /*
+             * Referral handling as specified by RFC 3296 here:
+             *    
+             *      http://www.faqs.org/rfcs/rfc3296.html
+             *      
+             * See section 5.6.1 where if the bind principal Dn is a referral
+             * we return an invalidCredentials result response.  Optionally we
+             * could support delegated authentication in the future with this
+             * potential.  See the following JIRA for more on this possibility:
+             * 
+             *      https://issues.apache.org/jira/browse/DIRSERVER-1217
+             *      
+             * NOTE: if this is done then this handler should extend the 
+             * a modified form of the ReferralAwareRequestHandler so it can 
+             * detect conditions where ancestors of the Dn are referrals
+             * and delegate appropriately.
+             */
+            Entry principalEntry = null;
+
+            try
+            {
+                principalEntry = getLdapServer().getDirectoryService().getAdminSession().lookup( bindRequest.getDn() );
+            }
+            catch ( LdapException le )
+            {
+                // this is OK
+            }
+
+            if ( principalEntry == null )
+            {
+                LOG.info( "The {} principalDN cannot be found in the server : bind failure.", bindRequest.getName() );
+            }
+            else if ( ( ( ClonedServerEntry ) principalEntry ).getOriginalEntry().contains(
+                SchemaConstants.OBJECT_CLASS_AT,
+                SchemaConstants.REFERRAL_OC ) )
+            {
+                LOG.info( "Bind principalDn points to referral." );
+                LdapResult result = bindRequest.getResultResponse().getLdapResult();
+                result.setDiagnosticMessage( "Bind principalDn points to referral." );
+                result.setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
+                ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+                return;
+            }
+
+            // TODO - might cause issues since lookups are not returning all 
+            // attributes right now - this is an optimization that can be 
+            // enabled later after determining whether or not this will cause
+            // issues.
+            // reuse the looked up entry so we don't incur another lookup
+            // opContext.setEntry( principalEntry );
+
+            // And call the OperationManager bind operation.
+            bindContext.setInterceptors( getLdapServer().getDirectoryService().getInterceptors( OperationEnum.BIND ) );
+            getLdapServer().getDirectoryService().getOperationManager().bind( bindContext );
+
+            // As a result, store the created session in the Core Session
+            ldapSession.setCoreSession( bindContext.getSession() );
+
+            // And set the current state accordingly
+            if ( !ldapSession.getCoreSession().isAnonymous() )
+            {
+                ldapSession.setAuthenticated();
+            }
+            else
+            {
+                ldapSession.setAnonymous();
+            }
+
+            // Return the successful response
+            bindRequest.getResultResponse().addAllControls( bindContext.getResponseControls() );
+            sendBindSuccess( ldapSession, bindRequest, null );
+        }
+        catch ( Exception e )
+        {
+            // Something went wrong. Write back an error message
+            // For BindRequest, it should be an InvalidCredentials, 
+            // no matter what kind of exception we got.
+            ResultCodeEnum code = null;
+            LdapResult result = bindRequest.getResultResponse().getLdapResult();
+
+            if ( e instanceof LdapUnwillingToPerformException )
+            {
+                code = ResultCodeEnum.UNWILLING_TO_PERFORM;
+                result.setResultCode( code );
+            }
+            else if ( e instanceof LdapInvalidDnException )
+            {
+                code = ResultCodeEnum.INVALID_DN_SYNTAX;
+                result.setResultCode( code );
+            }
+            else
+            {
+                code = ResultCodeEnum.INVALID_CREDENTIALS;
+                result.setResultCode( code );
+            }
+
+            String msg = code.toString() + ": Bind failed: " + e.getLocalizedMessage();
+
+            if ( LOG.isDebugEnabled() )
+            {
+                msg += ":\n" + ExceptionUtils.getStackTrace( e );
+                msg += "\n\nBindRequest = \n" + bindRequest.toString();
+            }
+
+            Dn dn = null;
+
+            if ( e instanceof LdapAuthenticationException )
+            {
+                dn = ( ( LdapAuthenticationException ) e ).getResolvedDn();
+            }
+
+            if ( ( dn != null )
+                && ( ( code == ResultCodeEnum.NO_SUCH_OBJECT ) || ( code == ResultCodeEnum.ALIAS_PROBLEM )
+                    || ( code == ResultCodeEnum.INVALID_DN_SYNTAX ) || ( code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM ) ) )
+            {
+                result.setMatchedDn( dn );
+            }
+
+            result.setDiagnosticMessage( msg );
+            bindRequest.getResultResponse().addAllControls( bindContext.getResponseControls() );
+            ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+        }
+        finally
+        {
+            // Reset LDAP session bind status to anonymous if authentication failed
+            if ( !ldapSession.isAuthenticated() )
+            {
+                ldapSession.setAnonymous();
+            }
+        }
+    }
+
+
+    /**
+     * Check if the mechanism exists.
+     */
+    private boolean checkMechanism( String saslMechanism ) throws Exception
+    {
+        // Guard clause:  Reject unsupported SASL mechanisms.
+        if ( !ldapServer.getSupportedMechanisms().contains( saslMechanism ) )
+        {
+            LOG.error( I18n.err( I18n.ERR_160, saslMechanism ) );
+
+            return false;
+        }
+        else
+        {
+            return true;
+        }
+    }
+
+
+    /**
+     * For challenge/response exchange, generate the challenge. 
+     * If the exchange is complete then send bind success.
+     *
+     * @param ldapSession
+     * @param ss
+     * @param bindRequest
+     */
+    private void generateSaslChallengeOrComplete( LdapSession ldapSession, SaslServer ss,
+        BindRequest bindRequest ) throws Exception
+    {
+        LdapResult result = bindRequest.getResultResponse().getLdapResult();
+
+        // SaslServer will throw an exception if the credentials are null.
+        if ( bindRequest.getCredentials() == null )
+        {
+            bindRequest.setCredentials( StringConstants.EMPTY_BYTES );
+        }
+
+        try
+        {
+            // Compute the challenge
+            byte[] tokenBytes = ss.evaluateResponse( bindRequest.getCredentials() );
+
+            if ( ss.isComplete() )
+            {
+                // This is the end of the C/R exchange
+                if ( tokenBytes != null )
+                {
+                    /*
+                     * There may be a token to return to the client.  We set it here
+                     * so it will be returned in a SUCCESS message, after an LdapContext
+                     * has been initialized for the client.
+                     */
+                    ldapSession.putSaslProperty( SaslConstants.SASL_CREDS, tokenBytes );
+                }
+
+                LdapPrincipal ldapPrincipal = ( LdapPrincipal ) ldapSession
+                    .getSaslProperty( SaslConstants.SASL_AUTHENT_USER );
+
+                if ( ldapPrincipal != null )
+                {
+                    DirectoryService ds = ldapSession.getLdapServer().getDirectoryService();
+                    String saslMechanism = bindRequest.getSaslMechanism();
+                    CoreSession userSession = ds.getSession( ldapPrincipal.getDn(), ldapPrincipal.getUserPassword(),
+                        saslMechanism, null );
+
+                    // Set the user session into the ldap session 
+                    ldapSession.setCoreSession( userSession );
+                }
+
+                // Mark the user as authenticated
+                ldapSession.setAuthenticated();
+
+                // Call the cleanup method for the selected mechanism
+                MechanismHandler handler = ( MechanismHandler ) ldapSession
+                    .getSaslProperty( SaslConstants.SASL_MECH_HANDLER );
+                handler.cleanup( ldapSession );
+
+                // Return the successful response
+                sendBindSuccess( ldapSession, bindRequest, tokenBytes );
+            }
+            else
+            {
+                // The SASL bind must continue, we are sending the computed challenge
+                LOG.info( "Continuation token had length " + tokenBytes.length );
+
+                // Build the response
+                result.setResultCode( ResultCodeEnum.SASL_BIND_IN_PROGRESS );
+                BindResponse resp = ( BindResponse ) bindRequest.getResultResponse();
+
+                // Store the challenge
+                resp.setServerSaslCreds( tokenBytes );
+
+                // Switch to SASLAuthPending
+                ldapSession.setSaslAuthPending();
+
+                // And write back the response
+                ldapSession.getIoSession().write( resp );
+
+                LOG.debug( "Returning final authentication data to client to complete context." );
+            }
+        }
+        catch ( SaslException se )
+        {
+            sendInvalidCredentials( ldapSession, bindRequest, se );
+        }
+    }
+
+
+    /**
+     * Send back an AUTH-METH-NOT-SUPPORTED error message to the client
+     */
+    private void sendAuthMethNotSupported( LdapSession ldapSession, BindRequest bindRequest )
+    {
+        // First, r-einit the state to Anonymous, and clear the
+        // saslProperty map
+        ldapSession.clearSaslProperties();
+        ldapSession.setAnonymous();
+
+        // And send the response to the client
+        LdapResult bindResult = bindRequest.getResultResponse().getLdapResult();
+        bindResult.setResultCode( ResultCodeEnum.AUTH_METHOD_NOT_SUPPORTED );
+        bindResult.setDiagnosticMessage( ResultCodeEnum.AUTH_METHOD_NOT_SUPPORTED.toString() + ": "
+            + bindRequest.getSaslMechanism() + " is not a supported mechanism." );
+
+        // Write back the error
+        ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+    }
+
+
+    /**
+     * Send back an INVALID-CREDENTIAL error message to the user. If we have an exception
+     * as a third argument, then send back the associated message to the client. 
+     */
+    private void sendInvalidCredentials( LdapSession ldapSession, BindRequest bindRequest, Exception e )
+    {
+        LdapResult result = bindRequest.getResultResponse().getLdapResult();
+
+        String message = "";
+
+        if ( e != null )
+        {
+            message = ResultCodeEnum.INVALID_CREDENTIALS + ": " + e.getLocalizedMessage();
+        }
+        else
+        {
+            message = ResultCodeEnum.INVALID_CREDENTIALS.toString();
+        }
+
+        LOG.error( message );
+        result.setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
+        result.setDiagnosticMessage( message );
+
+        // Reinitialize the state to Anonymous and clear the sasl properties
+        ldapSession.clearSaslProperties();
+        ldapSession.setAnonymous();
+
+        // Write back the error response
+        ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+    }
+
+
+    /**
+     * Send a SUCCESS message back to the client.
+     */
+    private void sendBindSuccess( LdapSession ldapSession, BindRequest bindRequest, byte[] tokenBytes )
+    {
+        // Return the successful response
+        BindResponse response = ( BindResponse ) bindRequest.getResultResponse();
+        response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+        response.setServerSaslCreds( tokenBytes );
+
+        if ( !ldapSession.getCoreSession().isAnonymous() )
+        {
+            // If we have not been asked to authenticate as Anonymous, authenticate the user
+            ldapSession.setAuthenticated();
+        }
+        else
+        {
+            // Otherwise, switch back to Anonymous
+            ldapSession.setAnonymous();
+        }
+
+        // Clean the SaslProperties, we don't need them anymore
+        MechanismHandler handler = ( MechanismHandler ) ldapSession.getSaslProperty( SaslConstants.SASL_MECH_HANDLER );
+
+        if ( handler != null )
+        {
+            handler.cleanup( ldapSession );
+        }
+
+        ldapSession.getIoSession().write( response );
+
+        LOG.debug( "Returned SUCCESS message: {}.", response );
+    }
+
+
+    private void handleSaslAuthPending( LdapSession ldapSession, BindRequest bindRequest ) throws Exception
+    {
+        // First, check that we have the same mechanism
+        String saslMechanism = bindRequest.getSaslMechanism();
+
+        // The empty mechanism is also a request for a new Bind session
+        if ( Strings.isEmpty( saslMechanism )
+            || !ldapSession.getSaslProperty( SaslConstants.SASL_MECH ).equals( saslMechanism ) )
+        {
+            sendAuthMethNotSupported( ldapSession, bindRequest );
+            return;
+        }
+
+        // We have already received a first BindRequest, and sent back some challenge.
+        // First, check if the mechanism is the same
+        MechanismHandler mechanismHandler = handlers.get( saslMechanism );
+
+        if ( mechanismHandler == null )
+        {
+            String message = I18n.err( I18n.ERR_161, saslMechanism );
+
+            // Clear the saslProperties, and move to the anonymous state
+            ldapSession.clearSaslProperties();
+            ldapSession.setAnonymous();
+
+            LOG.error( message );
+            throw new IllegalArgumentException( message );
+        }
+
+        // Get the previously created SaslServer instance
+        SaslServer ss = mechanismHandler.handleMechanism( ldapSession, bindRequest );
+
+        generateSaslChallengeOrComplete( ldapSession, ss, bindRequest );
+    }
+
+
+    /**
+     * Handle the SASL authentication. If the mechanism is known, we are
+     * facing three cases :
+     * <ul>
+     * <li>The user does not has a session yet</li>
+     * <li>The user already has a session</li>
+     * <li>The user has started a SASL negotiation</li>
+     * </lu><br/>
+     * 
+     * In the first case, we initiate a SaslBind session, which will be used all
+     * along the negotiation.<br/>
+     * In the second case, we first have to unbind the user, and initiate a new
+     * SaslBind session.<br/>
+     * In the third case, we have sub cases :
+     * <ul>
+     * <li>The mechanism is not provided : that means the user want to reset the
+     * current negotiation. We move back to an Anonymous state</li>
+     * <li>The mechanism is provided : the user is initializing a new negotiation
+     * with another mechanism. The current SaslBind session is reinitialized</li>
+     * <li></li>
+     * </ul><br/>
+     *
+     * @param ldapSession The associated Session
+     * @param bindRequest The BindRequest received
+     * @throws Exception If the authentication cannot be done
+     */
+    public void handleSaslAuth( LdapSession ldapSession, BindRequest bindRequest ) throws Exception
+    {
+        String saslMechanism = bindRequest.getSaslMechanism();
+
+        // Case #2 : the user does have a session. We have to unbind him
+        if ( ldapSession.isAuthenticated() )
+        {
+            // We already have a bound session for this user. We have to
+            // close the previous session first.
+            ldapSession.getCoreSession().unbind();
+
+            // Reset the status to Anonymous
+            ldapSession.setAnonymous();
+
+            // Clean the sasl properties
+            ldapSession.clearSaslProperties();
+
+            // Now we can continue as if the client was Anonymous from the beginning
+        }
+
+        // case #1 : The user does not have a session.
+        if ( ldapSession.isAnonymous() )
+        {
+            // fist check that the mechanism exists
+            if ( !checkMechanism( saslMechanism ) )
+            {
+                // get out !
+                sendAuthMethNotSupported( ldapSession, bindRequest );
+
+                return;
+            }
+
+            // Store the mechanism in the ldap session
+            ldapSession.putSaslProperty( SaslConstants.SASL_MECH, saslMechanism );
+
+            // Get the handler for this mechanism
+            MechanismHandler mechanismHandler = handlers.get( saslMechanism );
+
+            // Store the mechanism handler in the salsProperties
+            ldapSession.putSaslProperty( SaslConstants.SASL_MECH_HANDLER, mechanismHandler );
+
+            // Initialize the mechanism specific data
+            mechanismHandler.init( ldapSession );
+
+            // Get the SaslServer instance which manage the C/R exchange
+            SaslServer ss = mechanismHandler.handleMechanism( ldapSession, bindRequest );
+
+            // We have to generate a challenge
+            generateSaslChallengeOrComplete( ldapSession, ss, bindRequest );
+
+            // And get back
+            return;
+        }
+        else if ( ldapSession.isAuthPending() )
+        {
+            try
+            {
+                handleSaslAuthPending( ldapSession, bindRequest );
+            }
+            catch ( SaslException se )
+            {
+                sendInvalidCredentials( ldapSession, bindRequest, se );
+            }
+
+            return;
+        }
+    }
+
+
+    /**
+     * Deal with a received BindRequest
+     * 
+     * @param ldapSession The current session
+     * @param bindRequest The received BindRequest
+     * @throws Exception If the authentication cannot be handled
+     */
+    public void handle( LdapSession ldapSession, BindRequest bindRequest ) throws Exception
+    {
+        LOG.debug( "Received: {}", bindRequest );
+
+        // Guard clause:  LDAP version 3
+        if ( !bindRequest.getVersion3() )
+        {
+            LOG.error( I18n.err( I18n.ERR_162 ) );
+            LdapResult bindResult = bindRequest.getResultResponse().getLdapResult();
+            bindResult.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
+            bindResult.setDiagnosticMessage( I18n.err( I18n.ERR_163 ) );
+            ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+            return;
+        }
+
+        // Deal with the two kinds of authentication : Simple and SASL
+        if ( bindRequest.isSimple() )
+        {
+            handleSimpleAuth( ldapSession, bindRequest );
+        }
+        else
+        {
+            handleSaslAuth( ldapSession, bindRequest );
+        }
+    }
+}

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/CompareRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/CompareRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/CompareRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/CompareRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,69 @@
+/*
+ *  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.ldap.handlers.request;
+
+
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.shared.ldap.model.message.CompareRequest;
+import org.apache.directory.shared.ldap.model.message.LdapResult;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A single reply MessageReceived handler for {@link org.apache.directory.shared.ldap.model.message.CompareRequest}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareRequestHandler extends LdapRequestHandler<CompareRequest>
+{
+    private static final Logger LOG = LoggerFactory.getLogger( CompareRequestHandler.class );
+
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, CompareRequest req )
+    {
+        LOG.debug( "Handling compare request while ignoring referrals: {}", req );
+        LdapResult result = req.getResultResponse().getLdapResult();
+
+        try
+        {
+            if ( session.getCoreSession().compare( req ) )
+            {
+                result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
+            }
+            else
+            {
+                result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
+            }
+
+            result.setMatchedDn( req.getName() );
+            session.getIoSession().write( req.getResultResponse() );
+        }
+        catch ( Exception e )
+        {
+            handleException( session, req, e );
+        }
+    }
+}
\ No newline at end of file

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/DeleteRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/DeleteRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/DeleteRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/DeleteRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,68 @@
+/*
+ *  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.ldap.handlers.request;
+
+
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.shared.ldap.model.message.DeleteRequest;
+import org.apache.directory.shared.ldap.model.message.LdapResult;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A single reply MessageReceived handler for {@link DeleteRequest}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DeleteRequestHandler extends LdapRequestHandler<DeleteRequest>
+{
+    private static final Logger LOG = LoggerFactory.getLogger( DeleteRequestHandler.class );
+
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, DeleteRequest req )
+    {
+        LOG.debug( "Handling request: {}", req );
+        LdapResult result = req.getResultResponse().getLdapResult();
+
+        try
+        {
+            // 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 )
+        {
+            handleException( session, req, e );
+        }
+    }
+}
\ No newline at end of file

Added: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ExtendedRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ExtendedRequestHandler.java?rev=1414588&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ExtendedRequestHandler.java (added)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/ExtendedRequestHandler.java Wed Nov 28 08:53:09 2012
@@ -0,0 +1,75 @@
+/*
+*  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.ldap.handlers.request;
+
+
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.directory.server.ldap.ExtendedOperationHandler;
+import org.apache.directory.server.ldap.LdapSession;
+import org.apache.directory.server.ldap.handlers.LdapRequestHandler;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
+import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
+import org.apache.directory.shared.ldap.model.message.LdapResult;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+
+
+/**
+* A single reply MessageReceived handler for {@link ExtendedRequest}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedRequestHandler extends LdapRequestHandler<ExtendedRequest<ExtendedResponse>>
+{
+    /**
+     * {@inheritDoc}
+     */
+    public void handle( LdapSession session, ExtendedRequest<ExtendedResponse> req ) throws Exception
+    {
+        ExtendedOperationHandler<ExtendedRequest<ExtendedResponse>, ExtendedResponse> handler = getLdapServer()
+            .getExtendedOperationHandler( req.getRequestName() );
+
+        if ( handler == null )
+        {
+            // As long as no extended operations are implemented, send appropriate
+            // error back to the client.
+            String msg = "Unrecognized extended operation EXTENSION_OID: " + req.getRequestName();
+            LdapResult result = req.getResultResponse().getLdapResult();
+            result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
+            result.setDiagnosticMessage( msg );
+            session.getIoSession().write( req.getResultResponse() );
+            return;
+        }
+
+        try
+        {
+            handler.handleExtendedOperation( session, req );
+        }
+        catch ( Exception e )
+        {
+            LdapResult result = req.getResultResponse().getLdapResult();
+            result.setResultCode( ResultCodeEnum.OTHER );
+            result.setDiagnosticMessage( ResultCodeEnum.OTHER
+                + ": Extended operation handler for the specified EXTENSION_OID (" + req.getRequestName()
+                + ") has failed to process your request:\n" + ExceptionUtils.getStackTrace( e ) );
+            ExtendedResponse resp = req.getResultResponse();
+            session.getIoSession().write( resp );
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message