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 2013/10/18 13:35:28 UTC
svn commit: r1533400 - in /cxf/trunk:
rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/
rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/
systests/ws-security/src/test/java/org/apache/cxf/systest/w...
Author: coheigea
Date: Fri Oct 18 11:35:27 2013
New Revision: 1533400
URL: http://svn.apache.org/r1533400
Log:
Added streaming SPNEGO tests
Added:
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxServer.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxSpnegoTokenTest.java
cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/spnego/stax-server.xml
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoContextTokenInInterceptor.java
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/kerberos/StaxKerberosTokenTest.java
Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoContextTokenInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoContextTokenInInterceptor.java?rev=1533400&r1=1533399&r2=1533400&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoContextTokenInInterceptor.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoContextTokenInInterceptor.java Fri Oct 18 11:35:27 2013
@@ -26,9 +26,9 @@ import java.util.logging.Logger;
import javax.security.auth.callback.CallbackHandler;
import org.w3c.dom.Element;
-
import org.apache.cxf.binding.soap.SoapBindingConstants;
import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.helpers.DOMUtils;
@@ -47,6 +47,7 @@ import org.apache.cxf.ws.security.tokens
import org.apache.cxf.ws.security.tokenstore.TokenStore;
import org.apache.cxf.ws.security.trust.STSUtils;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
+import org.apache.cxf.ws.security.wss4j.WSS4JStaxInInterceptor;
import org.apache.neethi.All;
import org.apache.neethi.Assertion;
import org.apache.neethi.ExactlyOne;
@@ -63,7 +64,8 @@ class SpnegoContextTokenInInterceptor ex
static final Logger LOG = LogUtils.getL7dLogger(SpnegoContextTokenInInterceptor.class);
public SpnegoContextTokenInInterceptor() {
- super(Phase.PRE_PROTOCOL);
+ super(Phase.PRE_STREAM);
+ getBefore().add(WSS4JStaxInInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) throws Fault {
@@ -83,6 +85,9 @@ class SpnegoContextTokenInInterceptor ex
return;
}
String s = (String)message.get(SoapBindingConstants.SOAP_ACTION);
+ if (s == null) {
+ s = SoapActionInInterceptor.getSoapAction(message);
+ }
AddressingProperties inProps = (AddressingProperties)message
.getContextualProperty(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND);
if (inProps != null && s == null) {
Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java?rev=1533400&r1=1533399&r2=1533400&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/policyhandlers/StaxSymmetricBindingHandler.java Fri Oct 18 11:35:27 2013
@@ -440,7 +440,8 @@ public class StaxSymmetricBindingHandler
config.put(ConfigurationConstants.ENC_KEY_ID, "KerberosSHA1");
config.put(ConfigurationConstants.DERIVED_TOKEN_KEY_ID, "KerberosSHA1");
} else if ((recToken.getToken() instanceof IssuedToken
- || recToken.getToken() instanceof SecureConversationToken) && !isRequestor()) {
+ || recToken.getToken() instanceof SecureConversationToken
+ || recToken.getToken() instanceof SpnegoContextToken) && !isRequestor()) {
config.put(ConfigurationConstants.ENC_KEY_ID, "DirectReference");
} else {
config.put(ConfigurationConstants.ENC_KEY_ID, "EncryptedKeySHA1");
Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/kerberos/StaxKerberosTokenTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/kerberos/StaxKerberosTokenTest.java?rev=1533400&r1=1533399&r2=1533400&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/kerberos/StaxKerberosTokenTest.java (original)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/kerberos/StaxKerberosTokenTest.java Fri Oct 18 11:35:27 2013
@@ -313,9 +313,9 @@ public class StaxKerberosTokenTest exten
// DOM
kerberosPort.doubleIt(25);
- // TODO Streaming
- // SecurityTestUtil.enableStreaming(kerberosPort);
- // kerberosPort.doubleIt(25);
+ // Streaming
+ SecurityTestUtil.enableStreaming(kerberosPort);
+ kerberosPort.doubleIt(25);
((java.io.Closeable)kerberosPort).close();
bus.shutdown(true);
@@ -411,7 +411,7 @@ public class StaxKerberosTokenTest exten
((java.io.Closeable)kerberosPort).close();
bus.shutdown(true);
}
- /*
+
@org.junit.Test
public void testKerberosOverSymmetricEndorsingEncrypted() throws Exception {
@@ -469,5 +469,5 @@ public class StaxKerberosTokenTest exten
((java.io.Closeable)kerberosPort).close();
bus.shutdown(true);
}
- */
+
}
Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxServer.java?rev=1533400&view=auto
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxServer.java (added)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxServer.java Fri Oct 18 11:35:27 2013
@@ -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.spnego;
+
+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 StaxServer extends AbstractBusTestServerBase {
+
+ public StaxServer() {
+
+ }
+
+ protected void run() {
+ URL busFile = StaxServer.class.getResource("stax-server.xml");
+ Bus busLocal = new SpringBusFactory().createBus(busFile);
+ BusFactory.setDefaultBus(busLocal);
+ setBus(busLocal);
+
+ try {
+ new StaxServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxSpnegoTokenTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxSpnegoTokenTest.java?rev=1533400&view=auto
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxSpnegoTokenTest.java (added)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/spnego/StaxSpnegoTokenTest.java Fri Oct 18 11:35:27 2013
@@ -0,0 +1,174 @@
+/**
+ * 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.spnego;
+
+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 set of tests for Spnego Tokens. The tests are @Ignore'd, as they require a running KDC. To run the
+ * tests, set up a KDC of realm "WS.APACHE.ORG", with principal "alice" and service principal
+ * "bob/service.ws.apache.org". Create keytabs for both principals in "/etc/alice.keytab" and
+ * "/etc/bob.keytab" (this can all be edited in src/test/resource/kerberos.jaas". Then disable the
+ * @Ignore annotations and run the tests with:
+ *
+ * mvn test -Pnochecks -Dtest=StaxSpnegoTokenTest
+ * -Djava.security.auth.login.config=src/test/resources/kerberos.jaas
+ *
+ * It tests both DOM + StAX clients against the StAX server
+ */
+@org.junit.Ignore
+public class StaxSpnegoTokenTest extends AbstractBusClientServerTestBase {
+ static final String PORT = allocatePort(StaxServer.class);
+
+ private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
+ private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
+
+ private static boolean unrestrictedPoliciesInstalled =
+ SecurityTestUtil.checkUnrestrictedPoliciesInstalled();
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ if (unrestrictedPoliciesInstalled) {
+ assertTrue(
+ "Server failed to launch",
+ // run the server in the same process
+ // set this to false to fork
+ launchServer(StaxServer.class, true)
+ );
+ }
+ }
+
+ @org.junit.AfterClass
+ public static void cleanup() throws Exception {
+ if (unrestrictedPoliciesInstalled) {
+ SecurityTestUtil.cleanup();
+ stopAllServers();
+ }
+ }
+
+ @org.junit.Test
+ public void testSpnegoOverSymmetric() throws Exception {
+
+ if (!unrestrictedPoliciesInstalled) {
+ return;
+ }
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = StaxSpnegoTokenTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = StaxSpnegoTokenTest.class.getResource("DoubleItSpnego.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItSpnegoSymmetricPort");
+ DoubleItPortType spnegoPort =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(spnegoPort, PORT);
+
+ // DOM
+ spnegoPort.doubleIt(25);
+
+ // Streaming
+ SecurityTestUtil.enableStreaming(spnegoPort);
+ spnegoPort.doubleIt(25);
+
+ ((java.io.Closeable)spnegoPort).close();
+ bus.shutdown(true);
+ }
+
+ // TODO See WSS-480
+ @org.junit.Test
+ @org.junit.Ignore
+ public void testSpnegoOverSymmetricDerived() throws Exception {
+
+ if (!unrestrictedPoliciesInstalled) {
+ return;
+ }
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = StaxSpnegoTokenTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = StaxSpnegoTokenTest.class.getResource("DoubleItSpnego.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItSpnegoSymmetricDerivedPort");
+ DoubleItPortType spnegoPort =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(spnegoPort, PORT);
+
+ // DOM
+ // spnegoPort.doubleIt(25);
+
+ // TODO Hanging, see WSS-480 Streaming
+ // SecurityTestUtil.enableStreaming(spnegoPort);
+ // spnegoPort.doubleIt(25);
+
+ ((java.io.Closeable)spnegoPort).close();
+ bus.shutdown(true);
+ }
+
+ @org.junit.Test
+ public void testSpnegoOverSymmetricEncryptBeforeSigning() throws Exception {
+
+ if (!unrestrictedPoliciesInstalled) {
+ return;
+ }
+
+ SpringBusFactory bf = new SpringBusFactory();
+ URL busFile = StaxSpnegoTokenTest.class.getResource("client.xml");
+
+ Bus bus = bf.createBus(busFile.toString());
+ SpringBusFactory.setDefaultBus(bus);
+ SpringBusFactory.setThreadDefaultBus(bus);
+
+ URL wsdl = StaxSpnegoTokenTest.class.getResource("DoubleItSpnego.wsdl");
+ Service service = Service.create(wsdl, SERVICE_QNAME);
+ QName portQName = new QName(NAMESPACE, "DoubleItSpnegoSymmetricEncryptBeforeSigningPort");
+ DoubleItPortType spnegoPort =
+ service.getPort(portQName, DoubleItPortType.class);
+ updateAddressPort(spnegoPort, PORT);
+
+ // DOM
+ spnegoPort.doubleIt(25);
+
+ // Streaming
+ SecurityTestUtil.enableStreaming(spnegoPort);
+ spnegoPort.doubleIt(25);
+
+ ((java.io.Closeable)spnegoPort).close();
+ bus.shutdown(true);
+ }
+
+}
Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/spnego/stax-server.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/spnego/stax-server.xml?rev=1533400&view=auto
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/spnego/stax-server.xml (added)
+++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/spnego/stax-server.xml Fri Oct 18 11:35:27 2013
@@ -0,0 +1,95 @@
+<?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:interop="http://WSSec/wssec10"
+ 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.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>
+
+ <jaxws:endpoint
+ id="SpnegoOverSymmetric"
+ address="http://localhost:${testutil.ports.StaxServer}/DoubleItSpnegoSymmetric"
+ serviceName="s:DoubleItService"
+ endpointName="s:DoubleItSpnegoSymmetricPort"
+ xmlns:s="http://www.example.org/contract/DoubleIt"
+ implementor="org.apache.cxf.systest.ws.common.DoubleItImpl"
+ wsdlLocation="org/apache/cxf/systest/ws/spnego/DoubleItSpnego.wsdl">
+
+ <jaxws:properties>
+ <entry key="ws-security.kerberos.jaas.context" value="bob" />
+ <entry key="ws-security.enable.streaming" value="true"/>
+ </jaxws:properties>
+
+ </jaxws:endpoint>
+
+ <jaxws:endpoint
+ id="SpnegoOverSymmetricDerived"
+ address="http://localhost:${testutil.ports.StaxServer}/DoubleItSpnegoSymmetricDerived"
+ serviceName="s:DoubleItService"
+ endpointName="s:DoubleItSpnegoSymmetricDerivedPort"
+ xmlns:s="http://www.example.org/contract/DoubleIt"
+ implementor="org.apache.cxf.systest.ws.common.DoubleItImpl"
+ wsdlLocation="org/apache/cxf/systest/ws/spnego/DoubleItSpnego.wsdl">
+
+ <jaxws:properties>
+ <entry key="ws-security.kerberos.jaas.context" value="bob" />
+ <entry key="ws-security.enable.streaming" value="true"/>
+ </jaxws:properties>
+
+ </jaxws:endpoint>
+
+ <jaxws:endpoint
+ id="SpnegoOverSymmetricEncryptBeforeSigning"
+ address="http://localhost:${testutil.ports.StaxServer}/DoubleItSpnegoSymmetricEncryptBeforeSigning"
+ serviceName="s:DoubleItService"
+ endpointName="s:DoubleItSpnegoSymmetricEncryptBeforeSigningPort"
+ xmlns:s="http://www.example.org/contract/DoubleIt"
+ implementor="org.apache.cxf.systest.ws.common.DoubleItImpl"
+ wsdlLocation="org/apache/cxf/systest/ws/spnego/DoubleItSpnego.wsdl">
+
+ <jaxws:properties>
+ <entry key="ws-security.kerberos.jaas.context" value="bob" />
+ <entry key="ws-security.enable.streaming" value="true"/>
+ </jaxws:properties>
+
+ </jaxws:endpoint>
+
+</beans>