[jbossws-commits] JBossWS SVN: r16943 - in stack/cxf/trunk/modules/testsuite/cxf-tests: src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Oct 24 10:56:40 EDT 2012


Author: alessio.soldano at jboss.com
Date: 2012-10-24 10:56:40 -0400 (Wed, 24 Oct 2012)
New Revision: 16943

Added:
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceIface.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceImpl.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/JavaFirstPolicy.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/UsernameTestCase.java
   stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/WEB-INF/web.xml
Log:
[AS7-5827] Adding sample demonstrating proper javafirst ws-security policy usage


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-10-23 13:51:08 UTC (rev 16942)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-samples-jars-jaxws.xml	2012-10-24 14:56:40 UTC (rev 16943)
@@ -433,6 +433,7 @@
        webxml="${tests.output.dir}/test-resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/WEB-INF/web.xml">
        <classes dir="${tests.output.dir}/test-classes">
           <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/Service*.class"/>
+          <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstService*.class"/>
           <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/jaxws/Say*.class"/>
           <include name="org/jboss/test/ws/jaxws/samples/wsse/policy/basic/ServerUsernamePasswordCallback.class"/>
        </classes>
@@ -440,8 +441,11 @@
           <include name="jaxws-endpoint-config.xml"/>
           <include name="wsdl/*"/>
        </webinf>
+       <zipfileset dir="${tests.output.dir}/test-resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport" prefix="WEB-INF/classes">
+          <include name="JavaFirstPolicy.xml" />
+       </zipfileset>
        <manifest>
-         <attribute name="Dependencies" value="org.apache.ws.security"/>
+         <attribute name="Dependencies" value="org.apache.cxf,org.apache.ws.security"/>
        </manifest>
     </war>
 

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceIface.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceIface.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceIface.java	2012-10-24 14:56:40 UTC (rev 16943)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.wsse.policy.basic;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+import org.apache.cxf.annotations.Policy;
+
+ at WebService
+(
+   targetNamespace = "http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy"
+)
+ at Policy(placement = Policy.Placement.BINDING, uri = "JavaFirstPolicy.xml")
+public interface JavaFirstServiceIface
+{
+   @WebMethod
+   String sayHello();
+}

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceImpl.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceImpl.java	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/JavaFirstServiceImpl.java	2012-10-24 14:56:40 UTC (rev 16943)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.wsse.policy.basic;
+
+import javax.jws.WebService;
+
+import org.jboss.ws.api.annotation.EndpointConfig;
+
+ at WebService
+(
+   portName = "JavaFirstSecurityServicePort",
+   serviceName = "JavaFirstSecurityService",
+   targetNamespace = "http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy",
+   endpointInterface = "org.jboss.test.ws.jaxws.samples.wsse.policy.basic.JavaFirstServiceIface"
+)
+ at EndpointConfig(configFile = "WEB-INF/jaxws-endpoint-config.xml", configName = "Custom WS-Security Endpoint")
+public class JavaFirstServiceImpl implements JavaFirstServiceIface
+{
+   public String sayHello()
+   {
+      return "Secure Hello World!";
+   }
+}

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/UsernameTestCase.java
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/UsernameTestCase.java	2012-10-23 13:51:08 UTC (rev 16942)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/samples/wsse/policy/basic/UsernameTestCase.java	2012-10-24 14:56:40 UTC (rev 16943)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
  * as indicated by the @author tags. See the copyright.txt file in the
  * distribution for a full listing of individual contributors.
  *
@@ -41,7 +41,8 @@
  */
 public final class UsernameTestCase extends JBossWSTest
 {
-   private final String serviceURL = "http://" + getServerHost() + ":8080/jaxws-samples-wsse-policy-username-unsecure-transport";
+   private final String serviceURL = "http://" + getServerHost() + ":8080/jaxws-samples-wsse-policy-username-unsecure-transport/service";
+   private final String javaFirstServiceURL = "http://" + getServerHost() + ":8080/jaxws-samples-wsse-policy-username-unsecure-transport/javafirst-service";
 
    public static Test suite()
    {
@@ -54,7 +55,7 @@
       URL wsdlURL = new URL(serviceURL + "?wsdl");
       Service service = Service.create(wsdlURL, serviceName);
       ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
-      setupWsse(proxy, "kermit");
+      setupWsse((BindingProvider)proxy, "kermit");
       assertEquals("Secure Hello World!", proxy.sayHello());
    }
 
@@ -64,7 +65,7 @@
       URL wsdlURL = new URL(serviceURL + "?wsdl");
       Service service = Service.create(wsdlURL, serviceName);
       ServiceIface proxy = (ServiceIface)service.getPort(ServiceIface.class);
-      setupWsse(proxy, "snoopy");
+      setupWsse((BindingProvider)proxy, "snoopy");
       try
       {
          proxy.sayHello();
@@ -76,9 +77,37 @@
       }
    }
 
-   private void setupWsse(ServiceIface proxy, String username)
+   public void testJavaFirst() throws Exception
    {
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.USERNAME, username);
-      ((BindingProvider)proxy).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "org.jboss.test.ws.jaxws.samples.wsse.policy.basic.UsernamePasswordCallback");
+      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "JavaFirstSecurityService");
+      URL wsdlURL = new URL(javaFirstServiceURL + "?wsdl");
+      Service service = Service.create(wsdlURL, serviceName);
+      JavaFirstServiceIface proxy = (JavaFirstServiceIface)service.getPort(JavaFirstServiceIface.class);
+      setupWsse((BindingProvider)proxy, "kermit");
+      assertEquals("Secure Hello World!", proxy.sayHello());
    }
+
+   public void testJavaFirstWrongPassword() throws Exception
+   {
+      QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "JavaFirstSecurityService");
+      URL wsdlURL = new URL(javaFirstServiceURL + "?wsdl");
+      Service service = Service.create(wsdlURL, serviceName);
+      JavaFirstServiceIface proxy = (JavaFirstServiceIface)service.getPort(JavaFirstServiceIface.class);
+      setupWsse((BindingProvider)proxy, "snoopy");
+      try
+      {
+         proxy.sayHello();
+         fail("User snoopy shouldn't be authenticated.");
+      }
+      catch (Exception e)
+      {
+         //OK
+      }
+   }
+
+   private void setupWsse(BindingProvider proxy, String username)
+   {
+      proxy.getRequestContext().put(SecurityConstants.USERNAME, username);
+      proxy.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "org.jboss.test.ws.jaxws.samples.wsse.policy.basic.UsernamePasswordCallback");
+   }
 }

Added: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/JavaFirstPolicy.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/JavaFirstPolicy.xml	                        (rev 0)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/JavaFirstPolicy.xml	2012-10-24 14:56:40 UTC (rev 16943)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<wsp:Policy wsu:Id="JavaFirstSecurityServiceUsernameUnsecureTransportPolicy"
+    xmlns:wsp="http://www.w3.org/ns/ws-policy"
+    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
+    <wsp:ExactlyOne>
+        <wsp:All>
+            <sp:SupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <wsp:Policy>
+                    <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
+                        <wsp:Policy>
+                            <sp:WssUsernameToken10/>
+                        </wsp:Policy>
+                    </sp:UsernameToken>
+                </wsp:Policy>
+            </sp:SupportingTokens>
+        </wsp:All>
+    </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file

Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/WEB-INF/web.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/WEB-INF/web.xml	2012-10-23 13:51:08 UTC (rev 16942)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/samples/wsse/policy/basic/username-unsecure-transport/WEB-INF/web.xml	2012-10-24 14:56:40 UTC (rev 16943)
@@ -8,8 +8,16 @@
       <servlet-name>TestService</servlet-name>
       <servlet-class>org.jboss.test.ws.jaxws.samples.wsse.policy.basic.ServiceImpl</servlet-class>
    </servlet>
+   <servlet>
+      <servlet-name>JavaFirstTestService</servlet-name>
+      <servlet-class>org.jboss.test.ws.jaxws.samples.wsse.policy.basic.JavaFirstServiceImpl</servlet-class>
+   </servlet>
    <servlet-mapping>
       <servlet-name>TestService</servlet-name>
-      <url-pattern>/*</url-pattern>
+      <url-pattern>/service</url-pattern>
    </servlet-mapping>
+   <servlet-mapping>
+      <servlet-name>JavaFirstTestService</servlet-name>
+      <url-pattern>/javafirst-service</url-pattern>
+   </servlet-mapping>
 </web-app>



More information about the jbossws-commits mailing list