davsclaus commented on code in PR #28305:
URL: https://github.com/apache/camel/pull/28305#discussion_r4353260796


##########
components/camel-vertx/camel-vertx-common/src/test/java/org/apache/camel/component/vertx/common/VertxHelperTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.vertx.common;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+import io.vertx.core.net.NetClientOptions;
+import io.vertx.core.net.TCPSSLOptions;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustAllTrustManager;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class VertxHelperTest {
+
+    private CamelContext context;
+
+    @BeforeEach
+    public void setUp() {
+        context = new DefaultCamelContext();
+    }
+
+    @AfterEach
+    public void tearDown() throws Exception {
+        if (context != null) {
+            context.stop();
+        }
+    }
+
+    @Test
+    public void testStandaloneCustomTrustManagerApplied() throws Exception {
+        SSLContextParameters sslContextParameters = new SSLContextParameters();
+        TrustManagersParameters trustManagers = new TrustManagersParameters();
+
+        X509TrustManager customTrustManager = new X509TrustManager() {
+            @Override
+            public void checkClientTrusted(X509Certificate[] chain, String 
authType) throws CertificateException {
+                throw new CertificateException("Custom reject");
+            }
+
+            @Override
+            public void checkServerTrusted(X509Certificate[] chain, String 
authType) throws CertificateException {
+                throw new CertificateException("Custom reject");
+            }
+
+            @Override
+            public X509Certificate[] getAcceptedIssuers() {
+                return new X509Certificate[0];
+            }
+        };
+
+        trustManagers.setTrustManager(customTrustManager);
+        sslContextParameters.setTrustManagers(trustManagers);
+
+        TCPSSLOptions options = new NetClientOptions();
+        VertxHelper.setupSSLOptions(context, sslContextParameters, options);
+
+        assertThat(options.isSsl()).isTrue();
+        assertThat(options.getTrustOptions()).isNotNull();
+    }
+
+    @Test
+    public void testTrustAllTrustManagerApplied() throws Exception {
+        SSLContextParameters sslContextParameters = new SSLContextParameters();
+        TrustManagersParameters trustManagers = new TrustManagersParameters();
+        trustManagers.setTrustManager(TrustAllTrustManager.INSTANCE);
+        sslContextParameters.setTrustManagers(trustManagers);
+
+        TCPSSLOptions options = new NetClientOptions();
+        VertxHelper.setupSSLOptions(context, sslContextParameters, options);
+
+        assertThat(options.isSsl()).isTrue();
+        assertThat(options.getTrustOptions()).isNotNull();

Review Comment:
   Same here:
   
   ```suggestion
           assertThat(options.getTrustOptions()).isNotNull();
           
assertThat(options.getTrustOptions().getTrustManagerFactory(null).getTrustManagers())
                   .containsExactly(TrustAllTrustManager.INSTANCE);
   ```



##########
components/camel-vertx/camel-vertx-common/src/test/java/org/apache/camel/component/vertx/common/VertxHelperTest.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.vertx.common;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+import io.vertx.core.net.NetClientOptions;
+import io.vertx.core.net.TCPSSLOptions;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.support.jsse.TrustAllTrustManager;
+import org.apache.camel.support.jsse.TrustManagersParameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class VertxHelperTest {
+
+    private CamelContext context;
+
+    @BeforeEach
+    public void setUp() {
+        context = new DefaultCamelContext();
+    }
+
+    @AfterEach
+    public void tearDown() throws Exception {
+        if (context != null) {
+            context.stop();
+        }
+    }
+
+    @Test
+    public void testStandaloneCustomTrustManagerApplied() throws Exception {
+        SSLContextParameters sslContextParameters = new SSLContextParameters();
+        TrustManagersParameters trustManagers = new TrustManagersParameters();
+
+        X509TrustManager customTrustManager = new X509TrustManager() {
+            @Override
+            public void checkClientTrusted(X509Certificate[] chain, String 
authType) throws CertificateException {
+                throw new CertificateException("Custom reject");
+            }
+
+            @Override
+            public void checkServerTrusted(X509Certificate[] chain, String 
authType) throws CertificateException {
+                throw new CertificateException("Custom reject");
+            }
+
+            @Override
+            public X509Certificate[] getAcceptedIssuers() {
+                return new X509Certificate[0];
+            }
+        };
+
+        trustManagers.setTrustManager(customTrustManager);
+        sslContextParameters.setTrustManagers(trustManagers);
+
+        TCPSSLOptions options = new NetClientOptions();
+        VertxHelper.setupSSLOptions(context, sslContextParameters, options);
+
+        assertThat(options.isSsl()).isTrue();
+        assertThat(options.getTrustOptions()).isNotNull();

Review Comment:
   This passes for any trust options. `TrustOptions.wrap(tm)` returns Vert.x's 
`TrustManagerFactoryOptions`, whose `getTrustManagerFactory(Vertx)` only 
returns the wrapped factory (it does not use the `Vertx`), so the test can 
check that the custom manager is the one applied:
   
   ```suggestion
           assertThat(options.getTrustOptions()).isNotNull();
           
assertThat(options.getTrustOptions().getTrustManagerFactory(null).getTrustManagers())
                   .containsExactly(customTrustManager);
   ```



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc:
##########
@@ -1464,6 +1464,10 @@ Every other value is converted to one String and sent as 
one header as before: a
 commas), a `byte[]` and the other primitive arrays, a `Map`, and a Vert.x 
`JsonObject` or `JsonArray` (sent as JSON).
 A route that needs the old single header can set the header to a String, for 
example with `String.valueOf(list)`.
 
+=== camel-vertx - standalone TrustManager on SSLContextParameters is applied
+
+When configuring TLS through `SSLContextParameters` with a standalone 
`TrustManager` instance (via `TrustManagersParameters.setTrustManager(...)`), 
Vert.x components now wrap and apply the configured `TrustManager`. Previously, 
only `TrustAllTrustManager.INSTANCE` and KeyStore-backed configurations were 
applied, and other standalone `TrustManager` instances were not set on the 
underlying Vert.x options.

Review Comment:
   One more change for upgrading users: when both a standalone `TrustManager` 
and a keystore are set on `TrustManagersParameters`, the keystore-based trust 
options were used before, and now the `TrustManager` is (as 
`TrustManagersParameters.createTrustManagers()` does). Maybe add a sentence 
such as: "When both a `TrustManager` and a keystore are configured, the 
`TrustManager` is now used, as with the other components that use 
`SSLContextParameters`."



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to