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 a6f0a9c970439c1514f65bfbd32f5a058a1beb48 Author: Colm O hEigeartaigh <cohei...@apache.org> AuthorDate: Wed Sep 11 23:07:18 2019 +0100 Adding a test to show how to configure TLS to get the WSDL programatically (cherry picked from commit 0295f5cb98fd48bd19f68aea49acecb111a614f6) --- .../cxf/systest/ws/ut/UsernameTokenTest.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/ut/UsernameTokenTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/ut/UsernameTokenTest.java index b7b16de..1028beb 100644 --- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/ut/UsernameTokenTest.java +++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/ut/UsernameTokenTest.java @@ -46,6 +46,7 @@ import org.apache.cxf.systest.ws.common.SecurityTestUtil; import org.apache.cxf.systest.ws.common.TestParam; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transport.http.HTTPConduitConfigurer; import org.apache.cxf.ws.policy.WSPolicyFeature; import org.apache.cxf.ws.security.SecurityConstants; import org.apache.wss4j.common.ext.WSSecurityException; @@ -257,6 +258,60 @@ public class UsernameTokenTest extends AbstractBusClientServerTestBase { } @org.junit.Test + public void testPlaintextWSDLOverHTTPSViaCode() throws Exception { + + TrustManagerFactory tmf = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + final KeyStore ts = KeyStore.getInstance("JKS"); + try (InputStream trustStore = + ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", UsernameTokenTest.class)) { + ts.load(trustStore, "password".toCharArray()); + } + tmf.init(ts); + + TLSClientParameters tlsParams = new TLSClientParameters(); + tlsParams.setTrustManagers(tmf.getTrustManagers()); + tlsParams.setDisableCNCheck(true); + + HTTPConduitConfigurer myHttpConduitConfig = new HTTPConduitConfigurer() { + public void configure(String name, String address, HTTPConduit c) { + if ("{http://cxf.apache.org}TransportURIResolver.http-conduit".equals(name)) { + c.setTlsClientParameters(tlsParams); + } + } + }; + + BusFactory busFactory = BusFactory.newInstance(); + bus = busFactory.createBus(); + bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class); + BusFactory.setThreadDefaultBus(bus); + + URL wsdl = new URL("https://localhost:" + PORT + "/DoubleItUTPlaintext?wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort"); + DoubleItPortType utPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(utPort, test.getPort()); + + if (test.isStreaming()) { + SecurityTestUtil.enableStreaming(utPort); + } + + ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice"); + + ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, + "org.apache.cxf.systest.ws.common.UTPasswordCallback"); + + Client client = ClientProxy.getClient(utPort); + HTTPConduit http = (HTTPConduit) client.getConduit(); + http.setTlsClientParameters(tlsParams); + + assertEquals(50, utPort.doubleIt(25)); + + ((java.io.Closeable)utPort).close(); + } + + @org.junit.Test public void testPlaintextCreated() throws Exception { SpringBusFactory bf = new SpringBusFactory();