Author: dkulp
Date: Wed Oct 14 19:31:47 2009
New Revision: 825231
URL: http://svn.apache.org/viewvc?rev=825231&view=rev
Log:
Merged revisions 824872 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r824872 | dkulp | 2009-10-13 14:28:10 -0400 (Tue, 13 Oct 2009) | 2 lines
fix tests that
assumed DOMSource
........
Added:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
(with props)
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssc/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssc/
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec11/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec11/
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/DoubleIt.wsdl
- copied unchanged from r825225,
cxf/trunk/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/DoubleIt.wsdl
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssc/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssc/
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssec10/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssec10/
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssec11/
- copied from r825225,
cxf/trunk/systests/ws-specs/src/test/resources/wsdl_systest_wsspec/wssec11/
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
cxf/branches/2.2.x-fixes/systests/ws-specs/pom.xml
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxSource.java
Wed Oct 14 19:31:47 2009
@@ -117,9 +117,6 @@
String qname = prefix != null && prefix.length() > 0
? prefix + ":" + localName : localName;
contentHandler.endElement(uri, localName, qname);
- //for (int i = 0; i < streamReader.getNamespaceCount();
i++) {
- //
contentHandler.endPrefixMapping(streamReader.getNamespaceURI(i));
- //}
break;
}
case XMLStreamConstants.ENTITY_DECLARATION:
@@ -133,10 +130,6 @@
contentHandler.startDocument();
break;
case XMLStreamConstants.START_ELEMENT: {
- //for (int i = 0; i < streamReader.getNamespaceCount();
i++) {
- //
contentHandler.startPrefixMapping(streamReader.getNamespacePrefix(i),
- //
streamReader.getNamespaceURI(i));
- //}
String uri = streamReader.getNamespaceURI();
String localName = streamReader.getLocalName();
String prefix = streamReader.getPrefix();
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
Wed Oct 14 19:31:47 2009
@@ -217,9 +217,18 @@
writer.writeAttribute(s,
atts.getValue(i));
} else {
- writer.writeAttribute(atts.getURI(i),
- atts.getQName(i),
- atts.getValue(i));
+ String pfx = atts.getQName(i);
+ if (pfx.indexOf(':') != -1) {
+ pfx = pfx.substring(0, pfx.indexOf(':'));
+ writer.writeAttribute(pfx,
+ atts.getURI(i),
+ atts.getLocalName(i),
+ atts.getValue(i));
+ } else {
+ writer.writeAttribute(atts.getURI(i),
+ atts.getLocalName(i),
+ atts.getValue(i));
+ }
}
}
}
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java
Wed Oct 14 19:31:47 2009
@@ -72,7 +72,7 @@
//generic Source, find the preferred type
String s =
(String)message.getContextualProperty(SourceDataBinding.PREFERRED_FORMAT);
if (StringUtils.isEmpty(s)) {
- s = "dom"; //for now, should probably be stax
+ s = "dom";
}
if ("dom".equalsIgnoreCase(s)) {
type = DOMSource.class;
@@ -155,7 +155,7 @@
final InputStream ins = message.getContent(InputStream.class);
message.removeContent(InputStream.class);
- input = new FragmentStreamReader(input, false) {
+ input = new FragmentStreamReader(input) {
boolean closed;
public boolean hasNext() throws XMLStreamException {
boolean b = super.hasNext();
Modified:
cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/rest/RestClientServerHttpBindingTest.java
Wed Oct 14 19:31:47 2009
@@ -19,8 +19,8 @@
package org.apache.cxf.systest.rest;
-import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.StringWriter;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
@@ -75,12 +75,13 @@
InputStream is =
getClass().getResourceAsStream("resources/CustomerJohnReq.xml");
Source result = dispatcher.invoke(new StreamSource(is));
String tempstring = source2String(result);
- assertTrue("Result should start with Customer",
tempstring.startsWith("<ns4:Customer"));
- assertTrue("Result should have CustomerID",
tempstring.lastIndexOf(">123456<") > 0);
+ assertTrue("Result should start with Customer: " + tempstring,
+ tempstring.startsWith("<ns4:Customer"));
+ assertTrue("Result should have CustomerID: " + tempstring,
tempstring.lastIndexOf(">123456<") > 0);
}
private String source2String(Source source) throws Exception {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ StringWriter bos = new StringWriter(1000);
StreamResult sr = new StreamResult(bos);
Transformer trans = TransformerFactory.newInstance().newTransformer();
Properties oprops = new Properties();
Modified: cxf/branches/2.2.x-fixes/systests/ws-specs/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/ws-specs/pom.xml?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/ws-specs/pom.xml (original)
+++ cxf/branches/2.2.x-fixes/systests/ws-specs/pom.xml Wed Oct 14 19:31:47 2009
@@ -69,6 +69,58 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-codegen-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>generate-wssec10-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+
<testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
+ <wsdlOptions>
+ <wsdlOption>
+
<wsdl>${basedir}/src/test/resources/wsdl_systest_wsspec/wssec10/WsSecurity10.wsdl</wsdl>
+ </wsdlOption>
+ </wsdlOptions>
+ </configuration>
+ <goals>
+ <goal>wsdl2java</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>generate-wssec11-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+
<testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
+ <wsdlOptions>
+ <wsdlOption>
+
<wsdl>${basedir}/src/test/resources/wsdl_systest_wsspec/wssec11/WsSecurity11.wsdl</wsdl>
+ </wsdlOption>
+ </wsdlOptions>
+ </configuration>
+ <goals>
+ <goal>wsdl2java</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>generate-wssc-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+
<testSourceRoot>${basedir}/target/generated/src/test/java</testSourceRoot>
+ <wsdlOptions>
+ <wsdlOption>
+
<wsdl>${basedir}/src/test/resources/wsdl_systest_wsspec/wssc/WSSecureConversation.wsdl</wsdl>
+ </wsdlOption>
+ </wsdlOptions>
+ </configuration>
+ <goals>
+ <goal>wsdl2java</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
Modified:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_wsdl/Server.java
Wed Oct 14 19:31:47 2009
@@ -25,7 +25,6 @@
import javax.annotation.Resource;
import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Endpoint;
@@ -41,6 +40,7 @@
import org.w3c.dom.Element;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.helpers.XPathUtils;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -93,9 +93,13 @@
public Source invoke(Source obj) {
//CHECK the incoming
- DOMSource ds = (DOMSource)obj;
+ Element el;
+ try {
+ el = ((Document)XMLUtils.fromSource(obj)).getDocumentElement();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
- Element el = ((Document)ds.getNode()).getDocumentElement();
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", "http://apache.org/cxf/systest/ws/addr_feature/");
XPathUtils xp = new XPathUtils(ns);
@@ -120,9 +124,13 @@
public Source invoke(Source obj) {
//CHECK the incoming
- DOMSource ds = (DOMSource)obj;
- Element el = ((Document)ds.getNode()).getDocumentElement();
+ Element el;
+ try {
+ el = ((Document)XMLUtils.fromSource(obj)).getDocumentElement();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", "http://apache.org/cxf/systest/ws/addr_feature/");
XPathUtils xp = new XPathUtils(ns);
Modified:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java?rev=825231&r1=825230&r2=825231&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
Wed Oct 14 19:31:47 2009
@@ -27,7 +27,6 @@
import javax.jws.WebService;
import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Endpoint;
import javax.xml.ws.Provider;
@@ -36,11 +35,12 @@
import javax.xml.xpath.XPathConstants;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.helpers.XPathUtils;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.interceptor.LoggingInInterceptor;
@@ -99,9 +99,17 @@
public static class GreeterProvider implements Provider<Source> {
public Source invoke(Source obj) {
- DOMSource ds = (DOMSource)obj;
+
+ Node el;
+ try {
+ el = XMLUtils.fromSource(obj);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ if (el instanceof Document) {
+ el = ((Document)el).getDocumentElement();
+ }
- Element el = ((Document)ds.getNode()).getDocumentElement();
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", "http://cxf.apache.org/greeter_control/types");
XPathUtils xp = new XPathUtils(ns);
Added:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java?rev=825231&view=auto
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
(added)
+++
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
Wed Oct 14 19:31:47 2009
@@ -0,0 +1,355 @@
+/**
+ * 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.security;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jws.WebService;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceProvider;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.policytest.doubleit.DoubleItPortType;
+import org.apache.cxf.policytest.doubleit.DoubleItService;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.security.SecurityConstants;
+import org.apache.ws.security.WSPasswordCallback;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+public class SecurityPolicyTest extends AbstractBusClientServerTestBase {
+ public static final String POLICY_ADDRESS =
"http://localhost:9010/SecPolTest";
+ public static final String POLICY_HTTPS_ADDRESS =
"https://localhost:9009/SecPolTest";
+ public static final String POLICY_ENCSIGN_ADDRESS =
"http://localhost:9010/SecPolTestEncryptThenSign";
+ public static final String POLICY_SIGNENC_ADDRESS =
"http://localhost:9010/SecPolTestSignThenEncrypt";
+ public static final String POLICY_SIGNENC_PROVIDER_ADDRESS
+ = "http://localhost:9010/SecPolTestSignThenEncryptProvider";
+ public static final String POLICY_SIGN_ADDRESS =
"http://localhost:9010/SecPolTestSign";
+ public static final String POLICY_XPATH_ADDRESS =
"http://localhost:9010/SecPolTestXPath";
+
+
+ public static class ServerPasswordCallback implements CallbackHandler {
+ public void handle(Callback[] callbacks) throws IOException,
+ UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+
+ if (pc.getIdentifier().equals("bob")) {
+ // set the password on the callback. This will be compared to
the
+ // password which was sent from the client.
+ pc.setPassword("pwd");
+ }
+ }
+ }
+
+
+
+ @BeforeClass
+ public static void init() throws Exception {
+
+
createStaticBus(SecurityPolicyTest.class.getResource("https_config.xml").toString())
+ .getExtension(PolicyEngine.class).setEnabled(true);
+ getStaticBus().getOutInterceptors().add(new LoggingOutInterceptor());
+ EndpointImpl ep = (EndpointImpl)Endpoint.publish(POLICY_HTTPS_ADDRESS,
+ new DoubleItImplHttps());
+
ep.getServer().getEndpoint().getEndpointInfo().setProperty(SecurityConstants.CALLBACK_HANDLER,
+ new
ServerPasswordCallback());
+ Endpoint.publish(POLICY_ADDRESS,
+ new DoubleItImpl());
+
+ ep = (EndpointImpl)Endpoint.publish(POLICY_ENCSIGN_ADDRESS,
+ new DoubleItImplEncryptThenSign());
+
+ EndpointInfo ei = ep.getServer().getEndpoint().getEndpointInfo();
+ ei.setProperty(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
+ ei.setProperty(SecurityConstants.SIGNATURE_PROPERTIES,
+
SecurityPolicyTest.class.getResource("bob.properties").toString());
+ ei.setProperty(SecurityConstants.ENCRYPT_PROPERTIES,
+
SecurityPolicyTest.class.getResource("alice.properties").toString());
+
+ ep = (EndpointImpl)Endpoint.publish(POLICY_SIGNENC_ADDRESS,
+ new DoubleItImplSignThenEncrypt());
+
+ ei = ep.getServer().getEndpoint().getEndpointInfo();
+ ei.setProperty(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
+ ei.setProperty(SecurityConstants.SIGNATURE_PROPERTIES,
+
SecurityPolicyTest.class.getResource("bob.properties").toString());
+ ei.setProperty(SecurityConstants.ENCRYPT_PROPERTIES,
+
SecurityPolicyTest.class.getResource("alice.properties").toString());
+
+ ep = (EndpointImpl)Endpoint.publish(POLICY_SIGN_ADDRESS,
+ new DoubleItImplSign());
+ ei = ep.getServer().getEndpoint().getEndpointInfo();
+ ei.setProperty(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
+ ei.setProperty(SecurityConstants.SIGNATURE_PROPERTIES,
+
SecurityPolicyTest.class.getResource("bob.properties").toString());
+ ei.setProperty(SecurityConstants.ENCRYPT_PROPERTIES,
+
SecurityPolicyTest.class.getResource("alice.properties").toString());
+
+ ep = (EndpointImpl)Endpoint.publish(POLICY_XPATH_ADDRESS,
+ new DoubleItImplXPath());
+ ei = ep.getServer().getEndpoint().getEndpointInfo();
+ ei.setProperty(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
+ ei.setProperty(SecurityConstants.SIGNATURE_PROPERTIES,
+
SecurityPolicyTest.class.getResource("alice.properties").toString());
+ ei.setProperty(SecurityConstants.ENCRYPT_PROPERTIES,
+
SecurityPolicyTest.class.getResource("bob.properties").toString());
+
+ ep = (EndpointImpl)Endpoint.publish(POLICY_SIGNENC_PROVIDER_ADDRESS,
+ new DoubleItProvider());
+
+ ei = ep.getServer().getEndpoint().getEndpointInfo();
+ ei.setProperty(SecurityConstants.CALLBACK_HANDLER, new
KeystorePasswordCallback());
+ ei.setProperty(SecurityConstants.SIGNATURE_PROPERTIES,
+
SecurityPolicyTest.class.getResource("bob.properties").toString());
+ ei.setProperty(SecurityConstants.ENCRYPT_PROPERTIES,
+
SecurityPolicyTest.class.getResource("alice.properties").toString());
+ }
+
+ @Test
+ public void testPolicy() throws Exception {
+ DoubleItService service = new DoubleItService();
+ DoubleItPortType pt;
+
+ pt = service.getDoubleItPortXPath();
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
+ new
KeystorePasswordCallback());
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+
getClass().getResource("alice.properties"));
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
+
getClass().getResource("bob.properties"));
+ assertEquals(BigInteger.valueOf(10),
pt.doubleIt(BigInteger.valueOf(5)));
+
+
+ pt = service.getDoubleItPortEncryptThenSign();
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
+ new
KeystorePasswordCallback());
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+
getClass().getResource("alice.properties"));
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
+
getClass().getResource("bob.properties"));
+ pt.doubleIt(BigInteger.valueOf(5));
+
+ pt = service.getDoubleItPortSign();
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
+ new
KeystorePasswordCallback());
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+
getClass().getResource("alice.properties"));
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
+
getClass().getResource("bob.properties"));
+ pt.doubleIt(BigInteger.valueOf(5));
+
+
+ pt = service.getDoubleItPortSignThenEncrypt();
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
+ new
KeystorePasswordCallback());
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+
getClass().getResource("alice.properties"));
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
+
getClass().getResource("bob.properties"));
+ pt.doubleIt(BigInteger.valueOf(5));
+
+
((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+
POLICY_SIGNENC_PROVIDER_ADDRESS);
+ int x = pt.doubleIt(BigInteger.valueOf(5)).intValue();
+ assertEquals(10, x);
+
+ pt = service.getDoubleItPortHttps();
+ try {
+ pt.doubleIt(BigInteger.valueOf(25));
+ } catch (Exception ex) {
+ String msg = ex.getMessage();
+ if (!msg.contains("sername")) {
+ throw ex;
+ }
+ }
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.USERNAME,
"bob");
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME,
"bob");
+
((BindingProvider)pt).getRequestContext().put(SecurityConstants.PASSWORD,
"pwd");
+ pt.doubleIt(BigInteger.valueOf(25));
+
+ try {
+ pt = service.getDoubleItPortHttp();
+ pt.doubleIt(BigInteger.valueOf(25));
+ fail("https policy should have triggered");
+ } catch (Exception ex) {
+ String msg = ex.getMessage();
+ if (!msg.contains("HttpsToken")) {
+ throw ex;
+ }
+ }
+
+
+ }
+
+ @Test
+ public void testDispatchClient() throws Exception {
+ DoubleItService service = new DoubleItService();
+ Dispatch<Source> disp =
service.createDispatch(DoubleItService.DoubleItPortEncryptThenSign,
+ Source.class,
+ Mode.PAYLOAD);
+
+ disp.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
+ new KeystorePasswordCallback());
+ disp.getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
+
getClass().getResource("alice.properties"));
+ disp.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
+ getClass().getResource("bob.properties"));
+
+ String req = "<ns2:DoubleIt
xmlns:ns2=\"http://cxf.apache.org/policytest/DoubleIt\">"
+ + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
+ Source source = new StreamSource(new StringReader(req));
+ source = disp.invoke(source);
+
+ Node nd = XMLUtils.fromSource(source);
+ if (nd instanceof Document) {
+ nd = ((Document)nd).getDocumentElement();
+ }
+ Map<String, String> ns = new HashMap<String, String>();
+ ns.put("ns2", "http://cxf.apache.org/policytest/DoubleIt");
+ XPathUtils xp = new XPathUtils(ns);
+ Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", nd,
XPathConstants.STRING);
+ assertEquals(XMLUtils.toString(nd), "50", o);
+ }
+
+
+
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortHttp",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImpl implements DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortHttps",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImplHttps implements DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortEncryptThenSign",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImplEncryptThenSign implements
DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortSignThenEncrypt",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImplSignThenEncrypt implements
DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortSign",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImplSign implements DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+ @WebService(targetNamespace = "http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortXPath",
+ serviceName = "DoubleItService",
+ endpointInterface =
"org.apache.cxf.policytest.doubleit.DoubleItPortType",
+ wsdlLocation = "classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ public static class DoubleItImplXPath implements DoubleItPortType {
+ /** {...@inheritdoc}*/
+ public BigInteger doubleIt(BigInteger numberToDouble) {
+ return numberToDouble.multiply(new BigInteger("2"));
+ }
+ }
+ @WebServiceProvider(targetNamespace =
"http://cxf.apache.org/policytest/DoubleIt",
+ portName = "DoubleItPortSignThenEncrypt",
+ serviceName = "DoubleItService",
+ wsdlLocation =
"classpath:/wsdl_systest_wsspec/DoubleIt.wsdl")
+ @ServiceMode(value = Mode.PAYLOAD)
+ public static class DoubleItProvider implements Provider<Source> {
+
+ public Source invoke(Source obj) {
+ //CHECK the incoming
+
+ Node el;
+ try {
+ el = XMLUtils.fromSource(obj);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ if (el instanceof Document) {
+ el = ((Document)el).getDocumentElement();
+ }
+ Map<String, String> ns = new HashMap<String, String>();
+ ns.put("ns2", "http://cxf.apache.org/policytest/DoubleIt");
+ XPathUtils xp = new XPathUtils(ns);
+ String o = (String)xp.getValue("//ns2:DoubleIt/numberToDouble",
el, XPathConstants.STRING);
+ int i = Integer.parseInt(o);
+
+ String req = "<ns2:DoubleItResponse
xmlns:ns2=\"http://cxf.apache.org/policytest/DoubleIt\">"
+ + "<doubledNumber>" + Integer.toString(i * 2) +
"</doubledNumber></ns2:DoubleItResponse>";
+ return new StreamSource(new StringReader(req));
+ }
+
+ }
+}
Propchange:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/branches/2.2.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/security/SecurityPolicyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date