This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new e9b0373efb55 [backport camel-4.18.x] CAMEL-25105: camel-netty - The
client authentication of sslContextParameters is overridden by
needClientAuth=false (#29861)
e9b0373efb55 is described below
commit e9b0373efb550cdd80008ae119faa30a7e025d69
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 13 20:44:40 2026 +0100
[backport camel-4.18.x] CAMEL-25105: camel-netty - The client
authentication of sslContextParameters is overridden by needClientAuth=false
(#29861)
Backport of #27009 to camel-4.18.x.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
.../netty/http/HttpServerInitializerFactory.java | 6 +-
.../http/HttpServerSharedInitializerFactory.java | 6 +-
.../netty/DefaultServerInitializerFactory.java | 6 +-
.../NettySSLContextParametersClientAuthTest.java | 111 +++++++++++++++++++++
4 files changed, 126 insertions(+), 3 deletions(-)
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
index 4a73003b7257..9b74ac499102 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
@@ -174,7 +174,11 @@ public class HttpServerInitializerFactory extends
ServerInitializerFactory {
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
-
engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth());
+ if (consumer.getConfiguration().isNeedClientAuth()) {
+ // only when enabled, to keep the client authentication from
the sslContextParameters (such as
+ // REQUIRE or WANT) when needClientAuth is not enabled
+ engine.setNeedClientAuth(true);
+ }
if (consumer.getConfiguration().isHostnameVerification()) {
SSLParameters sslParams = engine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
diff --git
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedInitializerFactory.java
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedInitializerFactory.java
index 8413675f419d..fde1383bc445 100644
---
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedInitializerFactory.java
+++
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedInitializerFactory.java
@@ -134,7 +134,11 @@ public class HttpServerSharedInitializerFactory extends
HttpServerInitializerFac
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
- engine.setNeedClientAuth(configuration.isNeedClientAuth());
+ if (configuration.isNeedClientAuth()) {
+ // only when enabled, to keep the client authentication from
the sslContextParameters (such as
+ // REQUIRE or WANT) when needClientAuth is not enabled
+ engine.setNeedClientAuth(true);
+ }
if (configuration.getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter
doesn't set
engine.setEnabledProtocols(configuration.getEnabledProtocols().split(","));
diff --git
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
index 638f37ad7fcd..dee8ebab338a 100644
---
a/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
+++
b/components/camel-netty/src/main/java/org/apache/camel/component/netty/DefaultServerInitializerFactory.java
@@ -140,7 +140,11 @@ public class DefaultServerInitializerFactory extends
ServerInitializerFactory {
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(consumer.getConfiguration().isClientMode());
-
engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth());
+ if (consumer.getConfiguration().isNeedClientAuth()) {
+ // only when enabled, to keep the client authentication from
the sslContextParameters (such as
+ // REQUIRE or WANT) when needClientAuth is not enabled
+ engine.setNeedClientAuth(true);
+ }
if (consumer.getConfiguration().isHostnameVerification()) {
SSLParameters sslParams = engine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
diff --git
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLContextParametersClientAuthTest.java
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLContextParametersClientAuthTest.java
new file mode 100644
index 000000000000..73e605f96bb7
--- /dev/null
+++
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySSLContextParametersClientAuthTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.camel.component.netty;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.jsse.ClientAuthentication;
+import org.apache.camel.support.jsse.KeyManagersParameters;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.SSLContextServerParameters;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * The client authentication (REQUIRE) of the sslContextParameters is used,
also when needClientAuth is not enabled.
+ */
+@DisabledIfSystemProperty(named = "java.vendor", matches = ".*ibm.*")
+public class NettySSLContextParametersClientAuthTest extends BaseNettyTest {
+
+ private KeyStoreParameters keyStore() {
+ KeyStoreParameters ksp = new KeyStoreParameters();
+
ksp.setResource(this.getClass().getClassLoader().getResource("keystore.jks").toString());
+ ksp.setPassword("changeit");
+ return ksp;
+ }
+
+ private KeyManagersParameters keyManagers() {
+ KeyManagersParameters kmp = new KeyManagersParameters();
+ kmp.setKeyPassword("changeit");
+ kmp.setKeyStore(keyStore());
+ return kmp;
+ }
+
+ private TrustManagersParameters trustManagers() {
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(keyStore());
+ return tmp;
+ }
+
+ @BindToRegistry("serverParameters")
+ public SSLContextParameters serverParameters() {
+ SSLContextServerParameters scsp = new SSLContextServerParameters();
+ scsp.setClientAuthentication(ClientAuthentication.REQUIRE.name());
+
+ SSLContextParameters scp = new SSLContextParameters();
+ scp.setKeyManagers(keyManagers());
+ scp.setTrustManagers(trustManagers());
+ scp.setServerParameters(scsp);
+ return scp;
+ }
+
+ @BindToRegistry("clientParameters")
+ public SSLContextParameters clientParameters() {
+ SSLContextParameters scp = new SSLContextParameters();
+ scp.setKeyManagers(keyManagers());
+ scp.setTrustManagers(trustManagers());
+ return scp;
+ }
+
+ @BindToRegistry("noCertificateParameters")
+ public SSLContextParameters noCertificateParameters() {
+ SSLContextParameters scp = new SSLContextParameters();
+ scp.setTrustManagers(trustManagers());
+ return scp;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+
from("netty:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#serverParameters")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+
+ @Test
+ public void testClientWithCertificate() {
+ String response = template.requestBody(
+
"netty:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#clientParameters",
+ "Hello World", String.class);
+ assertEquals("Bye World", response);
+ }
+
+ @Test
+ public void testClientWithoutCertificate() {
+ assertThrows(CamelExecutionException.class, () -> template.requestBody(
+
"netty:tcp://localhost:{{port}}?sync=true&ssl=true&sslContextParameters=#noCertificateParameters",
+ "Hello World", String.class));
+ }
+}