You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2010/10/15 13:04:01 UTC
svn commit: r1022884 - in /cxf/trunk:
rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/
systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/
systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/
Author: sergeyb
Date: Fri Oct 15 11:04:01 2010
New Revision: 1022884
URL: http://svn.apache.org/viewvc?rev=1022884&view=rev
Log:
[CXF-3063] : Support for existing custom AbstractUsernameTokenAuthenticating subclasses
Added:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java (with props)
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java (with props)
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java (with props)
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml (with props)
Modified:
cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractUsernameTokenAuthenticatingInterceptor.java
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationTest.java
Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractUsernameTokenAuthenticatingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractUsernameTokenAuthenticatingInterceptor.java?rev=1022884&r1=1022883&r2=1022884&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractUsernameTokenAuthenticatingInterceptor.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/AbstractUsernameTokenAuthenticatingInterceptor.java Fri Oct 15 11:04:01 2010
@@ -29,7 +29,11 @@ import javax.security.auth.callback.Call
import javax.security.auth.callback.CallbackHandler;
import javax.xml.namespace.QName;
+import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.security.SecurityToken;
+import org.apache.cxf.common.security.UsernameToken;
+import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.security.DefaultSecurityContext;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
@@ -68,11 +72,12 @@ public abstract class AbstractUsernameTo
private boolean supportDigestPasswords;
public AbstractUsernameTokenAuthenticatingInterceptor() {
- super();
+ this(new HashMap<String, Object>());
}
public AbstractUsernameTokenAuthenticatingInterceptor(Map<String, Object> properties) {
super(properties);
+ getAfter().add(PolicyBasedWSS4JInInterceptor.class.getName());
}
public void setSupportDigestPasswords(boolean support) {
@@ -84,6 +89,23 @@ public abstract class AbstractUsernameTo
}
@Override
+ public void handleMessage(SoapMessage msg) throws Fault {
+ SecurityToken token = msg.get(SecurityToken.class);
+ SecurityContext context = msg.get(SecurityContext.class);
+ if (token == null || context == null || context.getUserPrincipal() == null) {
+ super.handleMessage(msg);
+ return;
+ }
+ UsernameToken ut = (UsernameToken)token;
+
+ Subject subject = createSubject(ut.getName(), ut.getPassword(), ut.isHashed(),
+ ut.getNonce(), ut.getCreatedTime());
+
+ SecurityContext sc = doCreateSecurityContext(context.getUserPrincipal(), subject);
+ msg.put(SecurityContext.class, sc);
+ }
+
+ @Override
protected SecurityContext createSecurityContext(final Principal p) {
Message msg = PhaseInterceptorChain.getCurrentMessage();
if (msg == null) {
Added: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java?rev=1022884&view=auto
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java (added)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java Fri Oct 15 11:04:01 2010
@@ -0,0 +1,118 @@
+/**
+ * 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.wssec10;
+
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.systest.ws.wssec10.server.AuthorizedServer2;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import wssec.wssec10.IPingService;
+import wssec.wssec10.PingService;
+
+
+/**
+ *
+ */
+public class WSSecurity10UsernameAuthorizationLegacyTest extends AbstractBusClientServerTestBase {
+ static final String SSL_PORT = allocatePort(AuthorizedServer2.class, 1);
+ static final String PORT = allocatePort(AuthorizedServer2.class);
+
+ private static final String INPUT = "foo";
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+
+ assertTrue(
+ "Server failed to launch",
+ // run the server in the same process
+ // set this to false to fork
+ launchServer(AuthorizedServer2.class, true)
+ );
+ }
+
+ @Test
+ public void testClientServerComplexPolicyAuthorized() {
+
+ IPingService port = getComplexPolicyPort(
+ "org/apache/cxf/systest/ws/wssec10/client/client_restricted.xml");
+
+ final String output = port.echo(INPUT);
+ assertEquals(INPUT, output);
+ }
+
+ @Test
+ public void testClientServerComplexPolicyUnauthorized() {
+
+ IPingService port = getComplexPolicyPort(
+ "org/apache/cxf/systest/ws/wssec10/client/client_restricted_unauthorized.xml");
+
+ try {
+ port.echo(INPUT);
+ fail("Frank is unauthorized");
+ } catch (Exception ex) {
+ assertEquals("Unauthorized", ex.getMessage());
+ }
+ }
+
+ private static IPingService getComplexPolicyPort(String configName) {
+ Bus bus = new SpringBusFactory().createBus(configName);
+
+ BusFactory.setDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
+ PingService svc = new PingService(getWsdlLocation("UserNameOverTransport"));
+ final IPingService port =
+ svc.getPort(
+ new QName(
+ "http://WSSec/wssec10",
+ "UserNameOverTransport" + "_IPingService"
+ ),
+ IPingService.class
+ );
+ return port;
+ }
+
+
+ private static URL getWsdlLocation(String portPrefix) {
+ try {
+ if ("UserNameOverTransport".equals(portPrefix)) {
+ return new URL("https://localhost:" + SSL_PORT + "/" + portPrefix + "?wsdl");
+ } else if ("MutualCertificate10SignEncrypt".equals(portPrefix)) {
+ return new URL("http://localhost:" + PORT + "/" + portPrefix + "?wsdl");
+ } else if ("MutualCertificate10SignEncryptRsa15TripleDes".equals(portPrefix)) {
+ return new URL("http://localhost:" + PORT + "/" + portPrefix + "?wsdl");
+ }
+ } catch (MalformedURLException mue) {
+ return null;
+ }
+ return null;
+ }
+
+}
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationLegacyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationTest.java?rev=1022884&r1=1022883&r2=1022884&view=diff
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationTest.java (original)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/WSSecurity10UsernameAuthorizationTest.java Fri Oct 15 11:04:01 2010
@@ -28,12 +28,8 @@ import javax.xml.namespace.QName;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.systest.ws.wssec10.server.AuthorizedServer;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-import org.apache.cxf.transport.http.HTTPConduit;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.junit.BeforeClass;
import org.junit.Test;
Added: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java?rev=1022884&view=auto
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java (added)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java Fri Oct 15 11:04:01 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.wssec10.server;
+
+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 AuthorizedServer2 extends AbstractBusTestServerBase {
+ static final String PORT = allocatePort(AuthorizedServer2.class);
+
+ private static String configFileName =
+ "org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml";
+
+ public AuthorizedServer2() throws Exception {
+
+ }
+
+ protected void run() {
+ Bus busLocal = new SpringBusFactory().createBus(configFileName);
+ BusFactory.setDefaultBus(busLocal);
+ setBus(busLocal);
+ }
+
+ public static void main(String args[]) throws Exception {
+ new AuthorizedServer2();
+ new SpringBusFactory().createBus(configFileName);
+ System.out.println("Server ready...");
+
+ Thread.sleep(60 * 60 * 1000);
+ System.out.println("Server exiting");
+ System.exit(0);
+ }
+}
+
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/AuthorizedServer2.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java?rev=1022884&view=auto
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java (added)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java Fri Oct 15 11:04:01 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.wssec10.server;
+
+import javax.security.auth.Subject;
+
+import org.apache.cxf.common.security.SimpleGroup;
+import org.apache.cxf.common.security.SimplePrincipal;
+import org.apache.cxf.ws.security.wss4j.AbstractUsernameTokenAuthenticatingInterceptor;
+
+public class SimpleSubjectCreatingInterceptor extends AbstractUsernameTokenAuthenticatingInterceptor {
+
+ @Override
+ protected Subject createSubject(String name,
+ String password,
+ boolean isDigest,
+ String nonce,
+ String created) throws SecurityException {
+ Subject subject = new Subject();
+
+ // delegate to the external security system if possible
+ String roleName = "Alice".equals(name) ? "developers" : "pms";
+ subject.getPrincipals().add(new SimplePrincipal(name));
+ subject.getPrincipals().add(new SimpleGroup(roleName, name));
+ subject.setReadOnly();
+ return subject;
+ }
+
+}
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/SimpleSubjectCreatingInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml?rev=1022884&view=auto
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml (added)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml Fri Oct 15 11:04:01 2010
@@ -0,0 +1,114 @@
+<?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:security="http://schemas.iona.com/soa/security-config"
+ 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
+ http://schemas.iona.com/soa/security-config http://schemas.iona.com/soa/security-config.xsd
+ ">
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <!-- -->
+ <!-- Any services listening on port 9001 must use the following -->
+ <!-- Transport Layer Security (TLS) settings -->
+ <!-- -->
+ <httpj:engine-factory id="tls-settings">
+ <httpj:engine port="${testutil.ports.AuthorizedServer2.1}">
+ <httpj:tlsServerParameters>
+ <sec:keyManagers keyPassword="password">
+ <sec:keyStore type="jks" password="password" resource="org/apache/cxf/systest/ws/wssec10/certs/restricted/bob.jks"/>
+ </sec:keyManagers>
+ <sec:trustManagers>
+ <sec:keyStore type="jks" password="password" resource="org/apache/cxf/systest/ws/wssec10/certs/restricted/alice.jks"/>
+ </sec:trustManagers>
+
+ <!--
+ <sec:cipherSuitesFilter>
+ <sec:include>.*_EXPORT_.*</sec:include>
+ <sec:include>.*_EXPORT1024_.*</sec:include>
+ <sec:include>.*_WITH_DES_.*</sec:include>
+ <sec:include>.*_WITH_NULL_.*</sec:include>
+ <sec:exclude>.*_DH_anon_.*</sec:exclude>
+ </sec:cipherSuitesFilter>
+ <sec:clientAuthentication want="true" required="true"/>
+ -->
+ </httpj:tlsServerParameters>
+ </httpj:engine>
+ </httpj:engine-factory>
+
+ <cxf:bus>
+ <cxf:features>
+ <p:policies/>
+ <cxf:logging/>
+ </cxf:features>
+
+ </cxf:bus>
+
+
+ <bean id="simpleUTInterceptor" class="org.apache.cxf.systest.ws.wssec10.server.SimpleSubjectCreatingInterceptor"/>
+ <bean id="authorizationInterceptor" class="org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor">
+ <property name="methodRolesMap">
+ <map>
+ <entry key="echo" value="developers"/>
+ </map>
+ </property>
+ </bean>
+
+
+ <!-- -->
+ <!-- Scenario 3.1 -->
+ <!-- -->
+ <jaxws:endpoint
+ id="UserNameOverTransport"
+ address="https://localhost:${testutil.ports.AuthorizedServer2.1}/UserNameOverTransport"
+ serviceName="interop:PingService"
+ endpointName="interop:UserNameOverTransport_IPingService"
+ implementor="org.apache.cxf.systest.ws.wssec10.server.UserNameOverTransportRestricted"
+ depends-on="tls-settings">
+
+ <jaxws:properties>
+ <entry key="ws-security.username" value="Alice"/>
+ <entry key="ws-security.callback-handler" value="org.apache.cxf.systest.ws.wssec10.server.UTPasswordCallback"/>
+ <!-- new property -->
+ <entry key="ws-security.ut.no-callbacks" value="true"/>
+ </jaxws:properties>
+
+ <jaxws:inInterceptors>
+ <ref bean="simpleUTInterceptor"/>
+ <ref bean="authorizationInterceptor"/>
+ </jaxws:inInterceptors>
+
+ </jaxws:endpoint>
+
+</beans>
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/wssec10/server/server_restricted_authorized_2.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml