Author: alessio.soldano(a)jboss.com
Date: 2012-07-26 10:04:53 -0400 (Thu, 26 Jul 2012)
New Revision: 16550
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/sign-encrypt/META-INF/jaxws-client-config.xml
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java
Log:
[JBWS-3529] Adding wsse testcase
Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml 2012-07-26
14:04:23 UTC (rev 16549)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml 2012-07-26
14:04:53 UTC (rev 16550)
@@ -188,6 +188,7 @@
<metainf
dir="${tests.output.dir}/test-resources/jaxws/samples/wsse/policy/basic/sign-encrypt/META-INF">
<include name="alice.properties" />
<include name="alice.jks" />
+ <include name="jaxws-client-config.xml" />
</metainf>
</jar>
<war
warfile="${tests.output.dir}/test-libs/jaxws-samples-wsse-policy-sign-encrypt-client.war"
needxmlfile='false'>
@@ -201,6 +202,7 @@
<zipfileset
dir="${tests.output.dir}/test-resources/jaxws/samples/wsse/policy/basic/sign-encrypt"
prefix="WEB-INF/classes">
<include name="META-INF/alice.properties" />
<include name="META-INF/alice.jks" />
+ <include name="META-INF/jaxws-client-config.xml" />
</zipfileset>
<manifest>
<attribute name="Dependencies"
value="org.jboss.ws.cxf.jbossws-cxf-client services,
org.apache.ws.security"/>
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java 2012-07-26
14:04:23 UTC (rev 16549)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptGCMTestCase.java 2012-07-26
14:04:53 UTC (rev 16550)
@@ -56,6 +56,13 @@
assertTrue(helper.testSignEncrypt());
}
+ public void testClientSideUsingConfigProperties() throws Exception
+ {
+ SignEncryptHelper helper = new SignEncryptHelper();
+ helper.setTargetEndpoint(serviceURL);
+ assertTrue(helper.testSignEncryptUsingConfigProperties());
+ }
+
public void testServerSide() throws Exception
{
URL url = new URL("http://" + getServerHost() +
":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
@@ -63,4 +70,12 @@
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
assertEquals("1", br.readLine());
}
+
+ public void testServerSideUsingConfigProperties() throws Exception
+ {
+ URL url = new URL("http://" + getServerHost() +
":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
+
"path=/jaxws-samples-wsse-policy-sign-encrypt-gcm&method=testSignEncryptUsingConfigProperties&helper="
+ SignEncryptHelper.class.getName());
+ BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+ assertEquals("1", br.readLine());
+ }
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java 2012-07-26
14:04:23 UTC (rev 16549)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptHelper.java 2012-07-26
14:04:53 UTC (rev 16550)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.jaxws.samples.wsse.policy.basic;
+import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
@@ -31,6 +32,8 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.ws.security.SecurityConstants;
+import org.jboss.ws.api.configuration.ClientConfigUtil;
+import org.jboss.ws.api.configuration.ClientConfigurer;
import org.jboss.wsf.test.ClientHelper;
public class SignEncryptHelper implements ClientHelper
@@ -49,20 +52,9 @@
try
{
BusFactory.setThreadDefaultBus(bus);
-
- QName serviceName = new
QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy",
"SecurityService");
- URL wsdlURL = new URL(targetEndpoint + "?wsdl");
- Service service = Service.create(wsdlURL, serviceName);
- ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
+ ServiceIface proxy = getProxy();
setupWsse(proxy);
- try
- {
- return "Secure Hello World!".equals(proxy.sayHello());
- }
- catch (SOAPFaultException e)
- {
- throw new Exception("Please check that the Bouncy Castle provider is
installed.", e);
- }
+ return invoke(proxy);
}
finally
{
@@ -70,6 +62,40 @@
}
}
+ public boolean testSignEncryptUsingConfigProperties() throws Exception
+ {
+ Bus bus = BusFactory.newInstance().createBus();
+ try
+ {
+ BusFactory.setThreadDefaultBus(bus);
+ ServiceIface proxy = getProxy();
+ ClientConfigUtil.setConfigProperties(proxy,
"META-INF/jaxws-client-config.xml", "Custom WS-Security Client");
+ return invoke(proxy);
+ }
+ finally
+ {
+ bus.shutdown(true);
+ }
+ }
+
+ private ServiceIface getProxy() throws MalformedURLException {
+ QName serviceName = new
QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy",
"SecurityService");
+ URL wsdlURL = new URL(targetEndpoint + "?wsdl");
+ Service service = Service.create(wsdlURL, serviceName);
+ return (ServiceIface)service.getPort(ServiceIface.class);
+ }
+
+ private boolean invoke(ServiceIface proxy) throws Exception {
+ try
+ {
+ return "Secure Hello World!".equals(proxy.sayHello());
+ }
+ catch (SOAPFaultException e)
+ {
+ throw new Exception("Please check that the Bouncy Castle provider is
installed.", e);
+ }
+ }
+
private void setupWsse(ServiceIface proxy)
{
((BindingProvider)proxy).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
@@ -78,5 +104,4 @@
((BindingProvider)proxy).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME,
"alice");
((BindingProvider)proxy).getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME,
"bob");
}
-
}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java 2012-07-26
14:04:23 UTC (rev 16549)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/SignEncryptTestCase.java 2012-07-26
14:04:53 UTC (rev 16550)
@@ -55,6 +55,13 @@
assertTrue(helper.testSignEncrypt());
}
+ public void testClientSideUsingConfigProperties() throws Exception
+ {
+ SignEncryptHelper helper = new SignEncryptHelper();
+ helper.setTargetEndpoint(serviceURL);
+ assertTrue(helper.testSignEncryptUsingConfigProperties());
+ }
+
public void testServerSide() throws Exception
{
URL url = new URL("http://" + getServerHost() +
":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
@@ -62,4 +69,12 @@
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
assertEquals("1", br.readLine());
}
+
+ public void testServerSideUsingConfigProperties() throws Exception
+ {
+ URL url = new URL("http://" + getServerHost() +
":8080/jaxws-samples-wsse-policy-sign-encrypt-client?" +
+
"path=/jaxws-samples-wsse-policy-sign-encrypt&method=testSignEncryptUsingConfigProperties&helper="
+ SignEncryptHelper.class.getName());
+ BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+ assertEquals("1", br.readLine());
+ }
}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/sign-encrypt/META-INF/jaxws-client-config.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/sign-encrypt/META-INF/jaxws-client-config.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/sign-encrypt/META-INF/jaxws-client-config.xml 2012-07-26
14:04:53 UTC (rev 16550)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jaxws-config xmlns="urn:jboss:jbossws-jaxws-config:4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
+ xsi:schemaLocation="urn:jboss:jbossws-jaxws-config:4.0
schema/jbossws-jaxws-config_4_0.xsd">
+
+ <client-config>
+ <config-name>Custom WS-Security Client</config-name>
+ <property>
+ <property-name>ws-security.signature.properties</property-name>
+ <property-value>META-INF/alice.properties</property-value>
+ </property>
+ <property>
+ <property-name>ws-security.encryption.properties</property-name>
+ <property-value>META-INF/alice.properties</property-value>
+ </property>
+ <property>
+ <property-name>ws-security.signature.username</property-name>
+ <property-value>alice</property-value>
+ </property>
+ <property>
+ <property-name>ws-security.encryption.username</property-name>
+ <property-value>bob</property-value>
+ </property>
+ <property>
+ <property-name>ws-security.callback-handler</property-name>
+
<property-value>org.jboss.test.ws.jaxws.samples.wsse.policy.basic.KeystorePasswordCallback</property-value>
+ </property>
+ </client-config>
+
+</jaxws-config>
\ No newline at end of file