You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2019/05/14 12:31:32 UTC
[cxf] 01/02: Adding an XKMS Register system test
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 422c433189c7cc1ddcb32fe369e9df49354baf60
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue May 14 13:15:47 2019 +0100
Adding an XKMS Register system test
(cherry picked from commit f09ae1ed3bbc88a6d7860697dd65821fd9958d99)
# Conflicts:
# systests/ws-security/src/test/java/org/apache/cxf/systest/ws/xkms/XKMSTest.java
---
.../org/apache/cxf/systest/ws/xkms/XKMSTest.java | 89 ++++++++++++++++++++-
.../org/apache/cxf/systest/ws/xkms/xkms-server.xml | 10 ++-
.../org/apache/cxf/systest/ws/xkms/xkmstest.cer | Bin 0 -> 709 bytes
3 files changed, 97 insertions(+), 2 deletions(-)
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/xkms/XKMSTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/xkms/XKMSTest.java
index ceccb75..e659f64 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/xkms/XKMSTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/xkms/XKMSTest.java
@@ -19,7 +19,14 @@
package org.apache.cxf.systest.ws.xkms;
+import java.io.InputStream;
import java.net.URL;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collection;
@@ -29,10 +36,21 @@ import javax.xml.ws.Service;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
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.xkms.model.xkms.LocateRequestType;
+import org.apache.cxf.xkms.model.xkms.LocateResultType;
+import org.apache.cxf.xkms.model.xkms.PrototypeKeyBindingType;
+import org.apache.cxf.xkms.model.xkms.QueryKeyBindingType;
+import org.apache.cxf.xkms.model.xkms.RegisterRequestType;
+import org.apache.cxf.xkms.model.xkms.RegisterResultType;
+import org.apache.cxf.xkms.model.xkms.UseKeyWithType;
+import org.apache.cxf.xkms.model.xmldsig.KeyInfoType;
+import org.apache.cxf.xkms.x509.utils.X509Utils;
import org.example.contract.doubleit.DoubleItPortType;
+import org.w3._2002._03.xkms_wsdl.XKMSPortType;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@@ -94,6 +112,76 @@ public class XKMSTest extends AbstractBusClientServerTestBase {
stopAllServers();
}
+ @org.junit.Test
+ public void testRegisterUnitTest() throws Exception {
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = XKMSTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ BusFactory.setDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = //XKMSTest.class.getResource("xkms.wsdl");
+ new URL("https://localhost:" + PORT2 + "/XKMS?wsdl");
+
+ String ns = "http://www.w3.org/2002/03/xkms#wsdl";
+ QName serviceQName = new QName(ns, "XKMSService");
+ Service service = Service.create(wsdl, serviceQName);
+ QName portQName = new QName(NAMESPACE, "XKMSPort");
+ XKMSPortType port =
+ service.getPort(portQName, XKMSPortType.class);
+ //updateAddressPort(port, PORT2);
+
+ // First try to locate - which should fail
+
+ LocateRequestType locateRequest = new LocateRequestType();
+ locateRequest.setId("_xyz");
+ locateRequest.setService("http://cxf.apache.org/services/XKMS/");
+ QueryKeyBindingType queryKeyBinding = new QueryKeyBindingType();
+ UseKeyWithType useKeyWithType = new UseKeyWithType();
+ useKeyWithType.setApplication("urn:ietf:rfc:2459");
+ useKeyWithType.setIdentifier("CN=client");
+ queryKeyBinding.getUseKeyWith().add(useKeyWithType);
+ locateRequest.setQueryKeyBinding(queryKeyBinding);
+
+ LocateResultType locateResultType = port.locate(locateRequest);
+ assertTrue(locateResultType.getResultMajor().endsWith("Success"));
+ assertTrue(locateResultType.getResultMinor().endsWith("NoMatch"));
+
+ // Now register
+
+ RegisterRequestType registerRequest = new RegisterRequestType();
+ registerRequest.setId("_xyz");
+ registerRequest.setService("http://cxf.apache.org/services/XKMS/");
+
+ PrototypeKeyBindingType prototypeKeyBinding = new PrototypeKeyBindingType();
+ CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
+ InputStream certInputStream = ClassLoaderUtils.getResourceAsStream("xkmstest.cer", this.getClass());
+ Certificate certificate =
+ certificateFactory.generateCertificate(certInputStream);
+ KeyInfoType keyInfo = X509Utils.getKeyInfo((X509Certificate)certificate);
+ prototypeKeyBinding.setKeyInfo(keyInfo);
+
+ prototypeKeyBinding.getUseKeyWith().add(useKeyWithType);
+ registerRequest.setPrototypeKeyBinding(prototypeKeyBinding);
+
+ RegisterResultType registerResult = port.register(registerRequest);
+ assertTrue(registerResult.getResultMajor().endsWith("Success"));
+ assertFalse(registerResult.getKeyBinding().isEmpty());
+
+ // Now locate again - which should work
+
+ locateResultType = port.locate(locateRequest);
+ assertTrue(locateResultType.getResultMajor().endsWith("Success"));
+ assertFalse(locateResultType.getUnverifiedKeyBinding().isEmpty());
+
+ // Delete the certificate so that the test works when run again
+ Path path = FileSystems.getDefault().getPath("target/test-classes/certs/xkms/CN-client.cer");
+ Files.delete(path);
+
+ }
+
+
// The client uses XKMS to locate the public key of the service with which to encrypt
// the message.
@org.junit.Test
@@ -153,5 +241,4 @@ public class XKMSTest extends AbstractBusClientServerTestBase {
bus.shutdown(true);
}
-
}
diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkms-server.xml b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkms-server.xml
index f211b7a..4c68cff 100644
--- a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkms-server.xml
+++ b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkms-server.xml
@@ -46,9 +46,12 @@
<bean id="x509Locator" class="org.apache.cxf.xkms.x509.handlers.X509Locator">
<constructor-arg ref="certificateRepo"/>
</bean>
+ <bean id="x509Register" class="org.apache.cxf.xkms.x509.handlers.X509Register">
+ <constructor-arg ref="certificateRepo"/>
+ </bean>
<!-- File based implementation -->
<bean id="certificateRepo" class="org.apache.cxf.xkms.x509.repo.file.FileCertificateRepo">
- <constructor-arg value="src/test/resources/certs/xkms"/>
+ <constructor-arg value="target/test-classes/certs/xkms"/>
</bean>
<bean id="xkmsProviderBean" class="org.apache.cxf.xkms.service.XKMSService">
<property name="validators">
@@ -62,6 +65,11 @@
<ref bean="x509Locator"/>
</list>
</property>
+ <property name="keyRegisterHandlers">
+ <list>
+ <ref bean="x509Register"/>
+ </list>
+ </property>
</bean>
<bean id="additionalClasses" class="org.apache.cxf.xkms.model.extensions.AdditionalClassesFactory"/>
<jaxws:endpoint xmlns:serviceNamespace="http://www.w3.org/2002/03/xkms#wsdl" id="XKMSService" serviceName="serviceNamespace:XKMSService" endpointName="serviceNamespace:XKMSPort" implementor="#xkmsProviderBean" address="https://localhost:${testutil.ports.xkms.XKMSServer}/XKMS">
diff --git a/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkmstest.cer b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkmstest.cer
new file mode 100644
index 0000000..53a45f0
Binary files /dev/null and b/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/xkms/xkmstest.cer differ