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

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 6686a4144 fix(#732): hide the CXF service list page by default (#740)
6686a4144 is described below

commit 6686a4144e5be78ded899d71435e7f4f92458b7d
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Aug 25 10:01:01 2026 +0200

    fix(#732): hide the CXF service list page by default (#740)
    
    ServletExporter registered the CXF transport servlet with
    hide-service-list-page defaulting to "false" and
    service-list-page-authenticate defaulting to "false". Since
    HTTPTransportActivator registers the ManagedService, those defaults apply
    as-is when no org.apache.cxf.osgi configuration exists, including on the
    updated(null) path that a default install actually takes. Installing the
    feature therefore published an enumerable, unauthenticated listing of
    every CXF endpoint in the container at /cxf with no configuration step.
    
    Default hide-service-list-page to "true" so the listing is opt in. An
    operator who wants it back sets
    org.apache.cxf.servlet.hide-service-list-page=false in the
    org.apache.cxf.osgi PID, optionally with service-list-page-authenticate,
    whose realm already defaults to karaf.
    
    These values match historic upstream CXF defaults, but CXF 4.x ships no
    OSGi transport module, so this glue is maintained here and the default is
    ours to pick.
    
    This is visible behaviour for anyone relying on the page, so it wants a
    release note.
    
    Adds ServletExporterTest, which pins the default on both the empty and
    the null config path, checks an explicit opt in is still honoured, and
    checks the surrounding defaults are untouched. The module had no test
    sources, so this also adds the junit-jupiter and mockito test
    dependencies.
---
 components/camel-cxf/camel-cxf-all/pom.xml         | 26 +++++++
 .../cxf/transport/http/osgi/ServletExporter.java   |  6 +-
 .../transport/http/osgi/ServletExporterTest.java   | 89 ++++++++++++++++++++++
 3 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/components/camel-cxf/camel-cxf-all/pom.xml 
b/components/camel-cxf/camel-cxf-all/pom.xml
index feef1e78d..a7a48f76e 100644
--- a/components/camel-cxf/camel-cxf-all/pom.xml
+++ b/components/camel-cxf/camel-cxf-all/pom.xml
@@ -366,6 +366,32 @@
             <artifactId>jakarta.xml.ws-api</artifactId>
             <scope>provided</scope>
         </dependency>
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>${junit-jupiter-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <version>${junit-jupiter-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>${mockito-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-junit-jupiter</artifactId>
+            <version>${mockito-version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/components/camel-cxf/camel-cxf-all/src/main/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporter.java
 
b/components/camel-cxf/camel-cxf-all/src/main/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporter.java
index dd4cbbb12..6468ffee8 100644
--- 
a/components/camel-cxf/camel-cxf-all/src/main/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporter.java
+++ 
b/components/camel-cxf/camel-cxf-all/src/main/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporter.java
@@ -73,8 +73,12 @@ class ServletExporter implements ManagedService {
                 Boolean.valueOf(getProp(properties, CXF_SERVLET_PREFIX + 
"async-supported", "true").toString()));
 
         // Pass CXF servlet init parameters
+        // the service list page enumerates every CXF endpoint in the 
container and is served
+        // unauthenticated, so it is opt in rather than on by default; set
+        // org.apache.cxf.servlet.hide-service-list-page=false in the 
org.apache.cxf.osgi PID to
+        // get it back, optionally with service-list-page-authenticate=true
         whiteboardProps.put("servlet.init.hide-service-list-page",
-                getProp(properties, CXF_SERVLET_PREFIX + 
"hide-service-list-page", "false"));
+                getProp(properties, CXF_SERVLET_PREFIX + 
"hide-service-list-page", "true"));
         whiteboardProps.put("servlet.init.disable-address-updates",
                 getProp(properties, CXF_SERVLET_PREFIX + 
"disable-address-updates", "true"));
         whiteboardProps.put("servlet.init.base-address",
diff --git 
a/components/camel-cxf/camel-cxf-all/src/test/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporterTest.java
 
b/components/camel-cxf/camel-cxf-all/src/test/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporterTest.java
new file mode 100644
index 000000000..79452cb60
--- /dev/null
+++ 
b/components/camel-cxf/camel-cxf-all/src/test/java/org/apache/camel/component/cxf/transport/http/osgi/ServletExporterTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.cxf.transport.http.osgi;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import jakarta.servlet.Servlet;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+public class ServletExporterTest {
+
+    @Mock
+    private Servlet servlet;
+    @Mock
+    private BundleContext bundleContext;
+    @Mock
+    private ServiceRegistration<Servlet> registration;
+
+    @SuppressWarnings("unchecked")
+    private Dictionary<String, Object> register(Dictionary<String, Object> 
config) throws Exception {
+        lenient().when(bundleContext.registerService(eq(Servlet.class), 
any(Servlet.class), any()))
+                .thenReturn(registration);
+
+        new ServletExporter(servlet, bundleContext).updated(config);
+
+        ArgumentCaptor<Dictionary<String, Object>> captor = 
ArgumentCaptor.forClass(Dictionary.class);
+        verify(bundleContext).registerService(eq(Servlet.class), eq(servlet), 
captor.capture());
+        return captor.getValue();
+    }
+
+    @Test
+    public void testServiceListPageIsHiddenByDefault() throws Exception {
+        assertEquals("true", register(new 
Hashtable<>()).get("servlet.init.hide-service-list-page"),
+                "the endpoint listing must be opt in");
+    }
+
+    @Test
+    public void testServiceListPageIsHiddenWhenThereIsNoConfigurationAtAll() 
throws Exception {
+        // ConfigAdmin calls updated(null) when no org.apache.cxf.osgi 
configuration exists,
+        // which is the shape a default install actually takes
+        assertEquals("true", 
register(null).get("servlet.init.hide-service-list-page"),
+                "the null config path must use the same default");
+    }
+
+    @Test
+    public void testServiceListPageCanStillBeTurnedBackOn() throws Exception {
+        Dictionary<String, Object> config = new Hashtable<>();
+        config.put("org.apache.cxf.servlet.hide-service-list-page", "false");
+        assertEquals("false", 
register(config).get("servlet.init.hide-service-list-page"),
+                "an explicit opt in must still be honoured");
+    }
+
+    @Test
+    public void testOtherDefaultsAreUnchanged() throws Exception {
+        Dictionary<String, Object> props = register(new Hashtable<>());
+        assertEquals("true", 
props.get("servlet.init.disable-address-updates"));
+        assertEquals("karaf", 
props.get("servlet.init.service-list-page-authenticate-realm"));
+        assertEquals("false", 
props.get("servlet.init.use-x-forwarded-headers"));
+        assertEquals("/cxf/*", 
props.get("osgi.http.whiteboard.servlet.pattern"));
+    }
+}

Reply via email to