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

davsclaus pushed a commit to branch CAMEL-28113-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8a3d835b0ddb00c3f2b0662903a0096edf8d6f31
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Dec 5 19:26:36 2026 +0100

    CAMEL-28113: camel-main - honour an explicit 
useGlobalSslContextParameters=false for camel.server and camel.management
    
    The check whether useGlobalSslContextParameters was configured ran after the
    properties were bound, and binding removes them, so with global SSL enabled 
the
    HTTP server and the HTTP management server always used the global SSL 
context.
    
    Backport of the useGlobalSslContextParameters part of CAMEL-25099 
(45cff41ebfca)
    from main; the rest of that commit stays on main.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../org/apache/camel/main/BaseMainSupport.java     |  12 ++-
 .../camel/main/MainHttpServerGlobalSslTest.java    | 107 +++++++++++++++++++++
 2 files changed, 117 insertions(+), 2 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index b9205a0a73b0..9b87c2f0941e 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -2184,6 +2184,10 @@ public abstract class BaseMainSupport extends 
BaseService {
 
         HttpServerConfigurationProperties server = 
mainConfigurationProperties.httpServer();
 
+        // whether useGlobalSslContextParameters is explicit configured (must 
check before the properties are bound
+        // as binding removes them)
+        boolean explicitGlobalSsl = properties.stringPropertyNames().stream()
+                .anyMatch(k -> 
k.equalsIgnoreCase("useGlobalSslContextParameters"));
         setPropertiesOnTarget(camelContext, server, properties, PREFIX_SERVER,
                 mainConfigurationProperties.isAutoConfigurationFailFast(), 
true, autoConfiguredProperties);
 
@@ -2198,7 +2202,7 @@ public abstract class BaseMainSupport extends BaseService 
{
         // (unless the user has explicitly configured 
useGlobalSslContextParameters)
         if (!server.isUseGlobalSslContextParameters()
                 && camelContext.getSSLContextParameters() != null
-                && !properties.containsKey("useGlobalSslContextParameters")) {
+                && !explicitGlobalSsl) {
             server.setUseGlobalSslContextParameters(true);
         }
 
@@ -2232,6 +2236,10 @@ public abstract class BaseMainSupport extends 
BaseService {
 
         HttpManagementServerConfigurationProperties server = 
mainConfigurationProperties.httpManagementServer();
 
+        // whether useGlobalSslContextParameters is explicit configured (must 
check before the properties are bound
+        // as binding removes them)
+        boolean explicitGlobalSsl = properties.stringPropertyNames().stream()
+                .anyMatch(k -> 
k.equalsIgnoreCase("useGlobalSslContextParameters"));
         setPropertiesOnTarget(camelContext, server, properties, 
"camel.management.",
                 mainConfigurationProperties.isAutoConfigurationFailFast(), 
true, autoConfiguredProperties);
 
@@ -2244,7 +2252,7 @@ public abstract class BaseMainSupport extends BaseService 
{
         // (unless the user has explicitly configured 
useGlobalSslContextParameters)
         if (!server.isUseGlobalSslContextParameters()
                 && camelContext.getSSLContextParameters() != null
-                && !properties.containsKey("useGlobalSslContextParameters")) {
+                && !explicitGlobalSsl) {
             server.setUseGlobalSslContextParameters(true);
         }
 
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainHttpServerGlobalSslTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainHttpServerGlobalSslTest.java
new file mode 100644
index 000000000000..3497cf0ee0dd
--- /dev/null
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainHttpServerGlobalSslTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.main;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Service;
+import org.apache.camel.support.service.ServiceSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The HTTP server and the HTTP management server use the global SSL context 
automatically, unless
+ * useGlobalSslContextParameters is configured explicitly.
+ */
+public class MainHttpServerGlobalSslTest {
+
+    @Test
+    public void testGlobalSslUsedByDefault() {
+        MyHttpServerFactory factory = new MyHttpServerFactory();
+        Main main = createMain(factory);
+        main.start();
+        try {
+            assertNotNull(factory.server);
+            assertNotNull(factory.management);
+            assertTrue(factory.server.isUseGlobalSslContextParameters());
+            assertTrue(factory.management.isUseGlobalSslContextParameters());
+        } finally {
+            main.stop();
+        }
+    }
+
+    @Test
+    public void testServerExplicitNotUsingGlobalSsl() {
+        MyHttpServerFactory factory = new MyHttpServerFactory();
+        Main main = createMain(factory);
+        main.addProperty("camel.server.useGlobalSslContextParameters", 
"false");
+        main.start();
+        try {
+            assertFalse(factory.server.isUseGlobalSslContextParameters());
+            assertTrue(factory.management.isUseGlobalSslContextParameters());
+        } finally {
+            main.stop();
+        }
+    }
+
+    @Test
+    public void testManagementExplicitNotUsingGlobalSsl() {
+        MyHttpServerFactory factory = new MyHttpServerFactory();
+        Main main = createMain(factory);
+        main.addProperty("camel.server.useGlobalSslContextParameters", "true");
+        main.addProperty("camel.management.useGlobalSslContextParameters", 
"false");
+        main.start();
+        try {
+            assertTrue(factory.server.isUseGlobalSslContextParameters());
+            assertFalse(factory.management.isUseGlobalSslContextParameters());
+        } finally {
+            main.stop();
+        }
+    }
+
+    private static Main createMain(MyHttpServerFactory factory) {
+        Main main = new Main();
+        main.bind("myFactory", factory);
+        main.addProperty("camel.ssl.enabled", "true");
+        main.addProperty("camel.ssl.selfSigned", "true");
+        main.addProperty("camel.server.enabled", "true");
+        main.addProperty("camel.management.enabled", "true");
+        return main;
+    }
+
+    public static class MyHttpServerFactory implements MainHttpServerFactory {
+        private HttpServerConfigurationProperties server;
+        private HttpManagementServerConfigurationProperties management;
+
+        @Override
+        public Service newHttpServer(CamelContext camelContext, 
HttpServerConfigurationProperties configuration) {
+            this.server = configuration;
+            return new ServiceSupport() {
+            };
+        }
+
+        @Override
+        public Service newHttpManagementServer(
+                CamelContext camelContext, 
HttpManagementServerConfigurationProperties configuration) {
+            this.management = configuration;
+            return new ServiceSupport() {
+            };
+        }
+    }
+}

Reply via email to