This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch 3.3.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 04ad8b57f8f9261653fc00e31a0e5a985edab143 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Tue Mar 31 13:20:59 2020 +0100 Adding a test case for TlS trustManager refs in Spring (cherry picked from commit 7b4622f5689507e9c2415b239569d849613a1672) --- .../cxf/systest/https/trust/TrustManagerTest.java | 33 +++++++++++++++++ .../https/trust/client-trust-manager-ref.xml | 42 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java index 1516342..90030a0 100644 --- a/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java +++ b/systests/transports/src/test/java/org/apache/cxf/systest/https/trust/TrustManagerTest.java @@ -140,6 +140,35 @@ public class TrustManagerTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } + // The X509TrustManager is effectively empty here so trust verification should work + @org.junit.Test + public void testNoOpX509TrustManagerTrustManagersRef() throws Exception { + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = TrustManagerTest.class.getResource("client-trust-manager-ref.xml"); + + Bus bus = bf.createBus(busFile.toString()); + BusFactory.setDefaultBus(bus); + BusFactory.setThreadDefaultBus(bus); + + URL url = SOAPService.WSDL_LOCATION; + SOAPService service = new SOAPService(url, SOAPService.SERVICE); + assertNotNull("Service is null", service); + final Greeter port = service.getHttpsPort(); + assertNotNull("Port is null", port); + + updateAddressPort(port, PORT); + + // Enable Async + if (async) { + ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); + } + + assertEquals(port.greetMe("Kitty"), "Hello Kitty"); + + ((java.io.Closeable)port).close(); + bus.shutdown(true); + } + // Here the Trust Manager checks the server cert @org.junit.Test public void testValidServerCertX509TrustManager() throws Exception { @@ -412,6 +441,10 @@ public class TrustManagerTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } + public static TrustManager[] getNoOpX509TrustManagers() { + return new TrustManager[] {new NoOpX509TrustManager()}; + } + public static class NoOpX509TrustManager implements X509TrustManager { public NoOpX509TrustManager() { diff --git a/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/client-trust-manager-ref.xml b/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/client-trust-manager-ref.xml new file mode 100644 index 0000000..b1dfa47 --- /dev/null +++ b/systests/transports/src/test/resources/org/apache/cxf/systest/https/trust/client-trust-manager-ref.xml @@ -0,0 +1,42 @@ +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:jaxws="http://cxf.apache.org/jaxws" + xmlns:cxf="http://cxf.apache.org/core" + xmlns:p="http://cxf.apache.org/policy" + xmlns:sec="http://cxf.apache.org/configuration/security" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache [...] + + <cxf:bus> + <cxf:features> + <cxf:logging/> + </cxf:features> + </cxf:bus> + + <bean id="trustManagers" class="org.apache.cxf.systest.https.trust.TrustManagerTest" factory-method="getNoOpX509TrustManagers"/> + + <http:conduit name="https://localhost:.*"> + <http:tlsClientParameters disableCNCheck="true"> + <sec:trustManagers ref="trustManagers" /> + </http:tlsClientParameters> + </http:conduit> + +</beans> \ No newline at end of file
