Repository: cxf Updated Branches: refs/heads/master cf806d5cb -> 08acb2e98
Adding BasicAuth policy test Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/08acb2e9 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/08acb2e9 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/08acb2e9 Branch: refs/heads/master Commit: 08acb2e98cb32b598f2dbad44b1334c9895ac2ed Parents: cf806d5 Author: Colm O hEigeartaigh <[email protected]> Authored: Wed Mar 15 16:38:56 2017 +0000 Committer: Colm O hEigeartaigh <[email protected]> Committed: Wed Mar 15 16:42:02 2017 +0000 ---------------------------------------------------------------------- .../cxf/systest/ws/basicauth/BasicAuthTest.java | 112 +++++++++++++++++++ .../apache/cxf/systest/ws/basicauth/Server.java | 47 ++++++++ .../systest/ws/basicauth/DoubleItBasicAuth.wsdl | 75 +++++++++++++ .../apache/cxf/systest/ws/basicauth/client.xml | 48 ++++++++ .../apache/cxf/systest/ws/basicauth/server.xml | 52 +++++++++ .../cxf/systest/ws/security/DoubleIt.wsdl | 4 +- 6 files changed, 336 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/BasicAuthTest.java ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/BasicAuthTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/BasicAuthTest.java new file mode 100644 index 0000000..22850fb --- /dev/null +++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/BasicAuthTest.java @@ -0,0 +1,112 @@ +/** + * 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.cxf.systest.ws.basicauth; + +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.systest.ws.common.SecurityTestUtil; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.example.contract.doubleit.DoubleItPortType; +import org.junit.BeforeClass; + +/** + * A test for Basic Auth using the WS-SecurityPolicy HttpBasicAuthentication policy. + * Note the basic auth credentials are not actually authenticated in this test...we are testing + * the WS-SecurityPolicy enforcement of whether the credentials are present or not. + */ +public class BasicAuthTest extends AbstractBusClientServerTestBase { + static final String PORT = allocatePort(Server.class); + + private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt"; + private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService"); + + @BeforeClass + public static void startServers() throws Exception { + assertTrue( + "Server failed to launch", + // run the server in the same process + // set this to false to fork + launchServer(Server.class, true) + ); + } + + @org.junit.AfterClass + public static void cleanup() throws Exception { + SecurityTestUtil.cleanup(); + stopAllServers(); + } + + @org.junit.Test + public void testBasicAuth() throws Exception { + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = BasicAuthTest.class.getResource("client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort"); + DoubleItPortType utPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(utPort, PORT); + + utPort.doubleIt(25); + + ((java.io.Closeable)utPort).close(); + bus.shutdown(true); + } + + @org.junit.Test + public void testNoBasicAuthCredentials() throws Exception { + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = BasicAuthTest.class.getResource("client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort2"); + DoubleItPortType utPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(utPort, PORT); + + try { + utPort.doubleIt(25); + fail("Failure expected on no basic auth creds"); + } catch (javax.xml.ws.soap.SOAPFaultException ex) { + // expected + } + + ((java.io.Closeable)utPort).close(); + bus.shutdown(true); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/Server.java ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/Server.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/Server.java new file mode 100644 index 0000000..eb0053f --- /dev/null +++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/basicauth/Server.java @@ -0,0 +1,47 @@ +/** + * 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.cxf.systest.ws.basicauth; + +import java.net.URL; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; + +public class Server extends AbstractBusTestServerBase { + + public Server() { + + } + + protected void run() { + URL busFile = Server.class.getResource("server.xml"); + Bus busLocal = new SpringBusFactory().createBus(busFile); + BusFactory.setDefaultBus(busLocal); + setBus(busLocal); + + try { + new Server(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl new file mode 100644 index 0000000..b92a7a1 --- /dev/null +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/contract/DoubleIt" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sp13="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802" name="DoubleIt" targetNamespace="http://www.example.org/contract/DoubleIt"> + <wsdl:import location="src/test/resources/DoubleItLogical.wsdl" namespace="http://www.example.org/contract/DoubleIt"/> + <wsdl:binding name="DoubleItBasicAuthBinding" type="tns:DoubleItPortType"> + <wsp:PolicyReference URI="#DoubleItBasicAuthPolicy"/> + <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <wsdl:operation name="DoubleIt"> + <soap:operation soapAction=""/> + <wsdl:input> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output> + <soap:body use="literal"/> + </wsdl:output> + <wsdl:fault name="DoubleItFault"> + <soap:body use="literal" name="DoubleItFault"/> + </wsdl:fault> + </wsdl:operation> + </wsdl:binding> + <wsdl:service name="DoubleItService"> + <wsdl:port name="DoubleItBasicAuthPort" binding="tns:DoubleItBasicAuthBinding"> + <soap:address location="https://localhost:9009/DoubleItBasicAuth"/> + </wsdl:port> + <wsdl:port name="DoubleItBasicAuthPort2" binding="tns:DoubleItBasicAuthBinding"> + <soap:address location="https://localhost:9009/DoubleItBasicAuth2"/> + </wsdl:port> + </wsdl:service> + <wsp:Policy wsu:Id="DoubleItBasicAuthPolicy"> + <wsp:ExactlyOne> + <wsp:All> + <sp:TransportBinding> + <wsp:Policy> + <sp:TransportToken> + <wsp:Policy> + <sp:HttpsToken> + <wsp:Policy> + <sp:HttpBasicAuthentication /> + </wsp:Policy> + </sp:HttpsToken> + </wsp:Policy> + </sp:TransportToken> + <sp:Layout> + <wsp:Policy> + <sp:Lax/> + </wsp:Policy> + </sp:Layout> + <sp:AlgorithmSuite> + <wsp:Policy> + <sp:Basic128/> + </wsp:Policy> + </sp:AlgorithmSuite> + </wsp:Policy> + </sp:TransportBinding> + </wsp:All> + </wsp:ExactlyOne> + </wsp:Policy> +</wsdl:definitions> http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/client.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/client.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/client.xml new file mode 100644 index 0000000..e2fbf85 --- /dev/null +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/client.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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-4.2.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.org/policy http://cxf.apache.org/schemas/ policy.xsd"> + <cxf:bus> + <cxf:features> + <p:policies/> + <cxf:logging/> + </cxf:features> + </cxf:bus> + <http:conduit name="https://localhost:(\d)*/DoubleItBasicAuth"> + <http:tlsClientParameters disableCNCheck="true"> + <sec:trustManagers> + <sec:keyStore type="jks" password="password" resource="keys/Truststore.jks"/> + </sec:trustManagers> + </http:tlsClientParameters> + <http:authorization> + <sec:UserName>Alice</sec:UserName> + <sec:Password>ecilA</sec:Password> + <sec:AuthorizationType>Basic</sec:AuthorizationType> + </http:authorization> + </http:conduit> + <http:conduit name="https://localhost:(\d)*/DoubleItBasicAuth2"> + <http:tlsClientParameters disableCNCheck="true"> + <sec:trustManagers> + <sec:keyStore type="jks" password="password" resource="keys/Truststore.jks"/> + </sec:trustManagers> + </http:tlsClientParameters> + </http:conduit> + <jaxws:client name="{http://www.example.org/contract/DoubleIt}DoubleItBasicAuthPort" createdFromAPI="true" /> + <jaxws:client name="{http://www.example.org/contract/DoubleIt}DoubleItBasicAuthPort2" createdFromAPI="true" /> +</beans> http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/server.xml ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/server.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/server.xml new file mode 100644 index 0000000..db8d2a0 --- /dev/null +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/basicauth/server.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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:jaxws="http://cxf.apache.org/jaxws" xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:cxf="http://cxf.apache.org/core" xmlns:p="http://cxf.apache.org/policy" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf .apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd "> + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + <cxf:bus> + <cxf:features> + <p:policies/> + <cxf:logging/> + </cxf:features> + </cxf:bus> + <!-- --> + <!-- Any services listening on port 9009 must use the following --> + <!-- Transport Layer Security (TLS) settings --> + <!-- --> + <httpj:engine-factory id="tls-settings"> + <httpj:engine port="${testutil.ports.basicauth.Server}"> + <httpj:tlsServerParameters> + <sec:keyManagers keyPassword="password"> + <sec:keyStore type="jks" password="password" resource="keys/Bethal.jks"/> + </sec:keyManagers> + <sec:trustManagers> + <sec:keyStore type="jks" password="password" resource="keys/Truststore.jks"/> + </sec:trustManagers> + <sec:clientAuthentication want="true" required="false"/> + </httpj:tlsServerParameters> + </httpj:engine> + </httpj:engine-factory> + <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt" id="BasicAuth" address="https://localhost:${testutil.ports.basicauth.Server}/DoubleItBasicAuth" serviceName="s:DoubleItService" endpointName="s:DoubleItBasicAuthPort" implementor="org.apache.cxf.systest.ws.common.DoubleItImpl" wsdlLocation="org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl" depends-on="tls-settings"> + <jaxws:properties /> + </jaxws:endpoint> + <jaxws:endpoint xmlns:s="http://www.example.org/contract/DoubleIt" id="BasicAuth2" address="https://localhost:${testutil.ports.basicauth.Server}/DoubleItBasicAuth2" serviceName="s:DoubleItService" endpointName="s:DoubleItBasicAuthPort2" implementor="org.apache.cxf.systest.ws.common.DoubleItImpl" wsdlLocation="org/apache/cxf/systest/ws/basicauth/DoubleItBasicAuth.wsdl" depends-on="tls-settings"> + <jaxws:properties /> + </jaxws:endpoint> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/08acb2e9/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl ---------------------------------------------------------------------- diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl index 20f2f2e..b915ead 100644 --- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl +++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/security/DoubleIt.wsdl @@ -864,7 +864,7 @@ <wsp:All> <wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp:Optional="true"/> <wsp:All> - <sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sapsp="http://www.sap.com/webas/630/soap/features/security/policy" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"> + <sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"> <wsp:Policy> <sp:TransportToken> <wsp:Policy> @@ -892,7 +892,7 @@ <wsp:All> <wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp:Optional="true"/> <wsp:All> - <sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sapsp="http://www.sap.com/webas/630/soap/features/security/policy" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"> + <sp:TransportBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"> <wsp:Policy> <sp:TransportToken> <wsp:Policy>
