Author: coheigea
Date: Fri Feb 14 17:44:49 2014
New Revision: 1568393
URL: http://svn.apache.org/r1568393
Log:
Adding a test for the Symmetric Binding with the Dispatch API
Modified:
cxf/trunk/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java
cxf/trunk/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/symmetric/DoubleIt.wsdl
Modified:
cxf/trunk/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java?rev=1568393&r1=1568392&r2=1568393&view=diff
==============================================================================
---
cxf/trunk/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java
(original)
+++
cxf/trunk/services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java
Fri Feb 14 17:44:49 2014
@@ -21,19 +21,34 @@ package org.apache.cxf.systest.sts.symme
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.jaxws.DispatchImpl;
import org.apache.cxf.systest.sts.common.SecurityTestUtil;
import org.apache.cxf.systest.sts.common.TestParam;
import org.apache.cxf.systest.sts.common.TokenTestUtils;
import org.apache.cxf.systest.sts.deployment.STSServer;
import org.apache.cxf.systest.sts.deployment.StaxSTSServer;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.ws.security.SecurityConstants;
+import org.apache.cxf.ws.security.trust.STSClient;
+import org.apache.wss4j.dom.WSConstants;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@@ -228,6 +243,78 @@ public class SymmetricBindingTest extend
((java.io.Closeable)symmetricSaml2Port).close();
bus.shutdown(true);
}
+
+ @org.junit.Test
+ public void testUsernameTokenSAML2Dispatch() throws Exception {
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = SymmetricBindingTest.class.getResource("cxf-client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = SymmetricBindingTest.class.getResource("DoubleIt.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSAML2Port");
+
+ Dispatch<DOMSource> dispatch =
+ service.createDispatch(portQName, DOMSource.class,
Service.Mode.PAYLOAD);
+ updateAddressPort(dispatch, test.getPort());
+
+ // Setup STSClient
+ STSClient stsClient = createDispatchSTSClient(bus);
+ String wsdlLocation = "http://localhost:" + test.getStsPort() +
"/SecurityTokenService/UT?wsdl";
+ stsClient.setWsdlLocation(wsdlLocation);
+
+ // Creating a DOMSource Object for the request
+ DOMSource request = createDOMRequest();
+
+ // Make a successful request
+ Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
+ client.getRequestContext().put("ws-security.sts.client", stsClient);
+
+ if (test.isStreaming()) {
+
client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY,
"true");
+
client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY,
"true");
+ }
+
+ DOMSource response = dispatch.invoke(request);
+ assertNotNull(response);
+
+ bus.shutdown(true);
+ }
+
+ private DOMSource createDOMRequest() throws ParserConfigurationException {
+ // Creating a DOMSource Object for the request
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document requestDoc = db.newDocument();
+ Element root =
requestDoc.createElementNS("http://www.example.org/schema/DoubleIt",
"ns2:DoubleIt");
+ root.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:ns2",
"http://www.example.org/schema/DoubleIt");
+ Element number = requestDoc.createElementNS(null, "numberToDouble");
+ number.setTextContent("25");
+ root.appendChild(number);
+ requestDoc.appendChild(root);
+ return new DOMSource(requestDoc);
+ }
+
+ private STSClient createDispatchSTSClient(Bus bus) {
+ STSClient stsClient = new STSClient(bus);
+
stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
+
stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("ws-security.username", "alice");
+ properties.put("ws-security.callback-handler",
+
"org.apache.cxf.systest.sts.common.CommonCallbackHandler");
+ properties.put("ws-security.encryption.username", "mystskey");
+ properties.put("ws-security.encryption.properties",
"clientKeystore.properties");
+ properties.put("ws-security.is-bsp-compliant", "false");
+ stsClient.setProperties(properties);
+
+ return stsClient;
+ }
private static void doubleIt(DoubleItPortType port, int numToDouble) {
int resp = port.doubleIt(numToDouble);
Modified:
cxf/trunk/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/symmetric/DoubleIt.wsdl
URL:
http://svn.apache.org/viewvc/cxf/trunk/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/symmetric/DoubleIt.wsdl?rev=1568393&r1=1568392&r2=1568393&view=diff
==============================================================================
---
cxf/trunk/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/symmetric/DoubleIt.wsdl
(original)
+++
cxf/trunk/services/sts/systests/basic/src/test/resources/org/apache/cxf/systest/sts/symmetric/DoubleIt.wsdl
Fri Feb 14 17:44:49 2014
@@ -41,11 +41,9 @@
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
- <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_Input_Policy"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
- <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_Output_Policy"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
@@ -151,6 +149,7 @@
<wsam:Addressing wsp:Optional="false">
<wsp:Policy/>
</wsam:Addressing>
+ <wsp:PolicyReference
URI="#DoubleItBinding_DoubleIt_Input_Policy"/>
<sp:SymmetricBinding>
<wsp:Policy>
<sp:ProtectionToken>