You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/09 01:35:38 UTC

[james-project] 08/09: JAMES-3737 AuthenticateProcessor should disable reads when adding a line handler

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0941a11ebf74aefa68cffc11b5c30d42ab798759
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu May 5 07:03:01 2022 +0700

    JAMES-3737 AuthenticateProcessor should disable reads when adding a line handler
---
 .../apache/james/imap/api/process/ImapSession.java   |  4 ++++
 .../james/imap/processor/AuthenticateProcessor.java  | 12 +++++++-----
 .../james/imapserver/netty/NettyImapSession.java     | 20 ++++++++++++--------
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java b/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
index d0d0e9359d..65287b1f10 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
@@ -90,6 +90,10 @@ public interface ImapSession extends CommandDetectionSession {
      */
     SessionId sessionId();
 
+    default void executeSafely(Runnable runnable) {
+        runnable.run();
+    }
+
     /**
      * Logs out the session. Marks the connection for closure;
      */
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
index 598333f5eb..590242dfa3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
@@ -79,11 +79,13 @@ public class AuthenticateProcessor extends AbstractAuthProcessor<AuthenticateReq
                     IRAuthenticateRequest irRequest = (IRAuthenticateRequest) request;
                     doPlainAuth(irRequest.getInitialClientResponse(), session, request, responder);
                 } else {
-                    responder.respond(new AuthenticateResponse());
-                    session.pushLineHandler((requestSession, data) -> {
-                        doPlainAuth(extractInitialClientResponse(data), requestSession, request, responder);
-                        // remove the handler now
-                        requestSession.popLineHandler();
+                    session.executeSafely(() -> {
+                        responder.respond(new AuthenticateResponse());
+                        session.pushLineHandler((requestSession, data) -> {
+                            doPlainAuth(extractInitialClientResponse(data), requestSession, request, responder);
+                            // remove the handler now
+                            requestSession.popLineHandler();
+                        });
                     });
                 }
             }
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
index 5e2dd29cf8..fb47fc2609 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
@@ -95,6 +95,16 @@ public class NettyImapSession implements ImapSession, NettyConstants {
         return sessionId;
     }
 
+    @Override
+    public void executeSafely(Runnable runnable) {
+        channel.eventLoop().execute(() -> {
+            channel.config().setAutoRead(false);
+            runnable.run();
+
+            channel.config().setAutoRead(true);
+        });
+    }
+
     @Override
     public Mono<Void> logout() {
         return closeMailbox()
@@ -166,13 +176,10 @@ public class NettyImapSession implements ImapSession, NettyConstants {
         if (!supportStartTLS()) {
             return false;
         }
-        channel.eventLoop().execute(() -> {
-            channel.config().setAutoRead(false);
+        executeSafely(() -> {
             runnable.run();
-
             channel.pipeline().addFirst(SSL_HANDLER, secure.sslHandler());
             stopDetectingCommandInjection();
-            channel.config().setAutoRead(true);
         });
 
         return true;
@@ -215,8 +222,7 @@ public class NettyImapSession implements ImapSession, NettyConstants {
             return false;
         }
 
-        channel.eventLoop().execute(() -> {
-            channel.config().setAutoRead(false);
+        executeSafely(() -> {
             runnable.run();
             ZlibDecoder decoder = new JZlibDecoder(ZlibWrapper.NONE);
             ZlibEncoder encoder = new JZlibEncoder(ZlibWrapper.NONE, 5);
@@ -232,8 +238,6 @@ public class NettyImapSession implements ImapSession, NettyConstants {
                 channel.pipeline().addAfter(SSL_HANDLER, ZLIB_DECODER, decoder);
                 channel.pipeline().addAfter(SSL_HANDLER, ZLIB_ENCODER, encoder);
             }
-
-            channel.config().setAutoRead(true);
         });
 
         return true;


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org