This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch 2.2.X
in repository https://gitbox.apache.org/repos/asf/mina.git
The following commit(s) were added to refs/heads/2.2.X by this push:
new e9d4fae3e Applied patch proposed by kllbzz
(https://github.com/apache/mina/pull/41): reintroduced the autoStart flag for
SSL (allowing the user to differ the HandShake after the addition in the chain
if false)
e9d4fae3e is described below
commit e9d4fae3ed320a382060063a4687954f1069380a
Author: emmanuel lecharny <[email protected]>
AuthorDate: Wed Nov 1 18:29:56 2023 +0100
Applied patch proposed by kllbzz (https://github.com/apache/mina/pull/41):
reintroduced the autoStart flag for SSL (allowing the user to differ the
HandShake after the addition in the chain if false)
---
.../java/org/apache/mina/filter/ssl/SslFilter.java | 28 ++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/mina-core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java
b/mina-core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java
index c3f167e84..418be5ab2 100644
--- a/mina-core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java
+++ b/mina-core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java
@@ -75,6 +75,12 @@ public class SslFilter extends IoFilterAdapter {
protected final SSLContext sslContext;
+ /** A flag used to tell the filter to start the handshake immediately (in
onPostAdd method)
+ * alternatively handshake will be started after session is connected (in
sessionOpened method)
+ * default value is true
+ **/
+ private final boolean autoStart;
+
/** A flag set if client authentication is required */
protected boolean needClientAuth = false;
@@ -110,9 +116,23 @@ public class SslFilter extends IoFilterAdapter {
* @param sslContext The SSLContext to use
*/
public SslFilter(SSLContext sslContext) {
+ this(sslContext, true);
+ }
+
+ /**
+ * Creates a new SSL filter using the specified {@link SSLContext}.
+ * If the <code>autostart</code> flag is set to <code>true</code>, the
+ * handshake will start immediately after the filter has been added
+ * to the chain.
+ *
+ * @param sslContext The SSLContext to use
+ * @param autoStart The flag used to tell the filter to start the
handshake immediately
+ */
+ public SslFilter(SSLContext sslContext, boolean autoStart) {
Objects.requireNonNull(sslContext, "ssl must not be null");
this.sslContext = sslContext;
+ this.autoStart = autoStart;
}
/**
@@ -245,8 +265,11 @@ public class SslFilter extends IoFilterAdapter {
@Override
public void onPostAdd(IoFilterChain parent, String name, NextFilter next)
throws Exception {
IoSession session = parent.getSession();
-
- if (session.isConnected()) {
+
+ // The SslFilter has been added *after* the session has been created
and opened.
+ // We need to initiate the HandShake, this is done here, unless the
user wants
+ // to differ the HandShake to later (and in this case autoStart is set
to false)
+ if (session.isConnected() && autoStart) {
onConnected(next, session);
}
@@ -359,6 +382,7 @@ public class SslFilter extends IoFilterAdapter {
}
}
+ // Used to initiate the HandShake if differed
onConnected(next, session);
super.sessionOpened(next, session);
}