[jbossws-commits] JBossWS SVN: r4375 - in stack/native/trunk/src/test: resources/jaxws/samples/wssecurity and 4 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Aug 15 10:45:18 EDT 2007


Author: mageshbk at jboss.com
Date: 2007-08-15 10:45:18 -0400 (Wed, 15 Aug 2007)
New Revision: 4375

Added:
   stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java
   stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java
   stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-web.xml
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-wsse-server.xml
   stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/web.xml
Log:
[JBWS-1766] UsernameToken ignores BindingProvider.USERNAME_PROPERTY - added TestCase - Merged from branches\native-2.0


Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java	                        (rev 0)
+++ stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.wssecurity;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.ws.core.StubExt;
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * Test WS-Security for Username Token
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ * @since 15-Aug-2007
+ * @version $Revision$
+ */
+public class SimpleUsernameTestCase extends JBossWSTest
+{
+   /** Construct the test case with a given name
+    */
+
+   /** Deploy the test */
+   public static Test suite() throws Exception
+   {
+      return new JBossWSTestSetup(SimpleUsernameTestCase.class, "jaxws-samples-wssecurity-username.war");
+   }
+
+   /**
+    * Test SOAP Envelope for Username Token
+    */
+   public void testUsernameToken() throws Exception
+   {
+      UsernameEndpoint username = getPort();
+
+      String retObj = username.getUsernameToken();
+      assertTrue(retObj.indexOf("UsernameToken") > 0);
+   }
+
+   private UsernameEndpoint getPort() throws Exception
+   {
+      URL wsdlURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl").toURL();
+      URL securityURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml").toURL();
+      QName serviceName = new QName("http://org.jboss.ws/samples/wssecurity", "UsernameService");
+
+      Service service = Service.create(wsdlURL, serviceName);
+      
+      UsernameEndpoint port = (UsernameEndpoint)service.getPort(UsernameEndpoint.class);
+      ((StubExt)port).setSecurityConfig(securityURL.toExternalForm());
+      ((StubExt)port).setConfigName("Standard WSSecurity Client");
+
+      Map<String, Object> reqContext = ((BindingProvider)port).getRequestContext();
+	   reqContext.put(BindingProvider.USERNAME_PROPERTY, "kermit");
+      reqContext.put(BindingProvider.PASSWORD_PROPERTY, "thefrog");
+      // If these below parameters are set it appears in the log, but the test fails as another
+      // request for the getHeader() returns empty <env:Header></env:Header>
+      //reqContext.put("javax.xml.rpc.security.auth.username", "kermit");
+      //reqContext.put("javax.xml.rpc.security.auth.password", "thefrog");
+      reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + getServerHost() + ":8080/jaxws-samples-wssecurity-username");
+
+      return port;
+   }
+}
\ No newline at end of file


Property changes on: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java	                        (rev 0)
+++ stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.wssecurity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.annotation.Resource;
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.annotation.EndpointConfig;
+import org.jboss.ws.extensions.security.Constants;
+import org.jboss.ws.extensions.security.Util;
+import org.jboss.ws.core.soap.SOAPElementImpl;
+import org.jboss.ws.core.soap.SOAPEnvelopeImpl;
+import org.jboss.ws.core.soap.SOAPHeaderImpl;
+import org.w3c.dom.Element;
+
+/**
+ * The SEI implementation used by the SimpleUsernameTestCase
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ * @since 15-Aug-2007
+ * @version $Revision$ 
+ */
+ at WebService(name = "UsernameEndpoint", serviceName = "UsernameService", targetNamespace = "http://org.jboss.ws/samples/wssecurity")
+ at EndpointConfig(configName = "Standard WSSecurity Endpoint")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public class UsernameBean
+{
+   private Logger log = Logger.getLogger(UsernameBean.class);
+   
+   @Resource
+   WebServiceContext wsCtx;
+
+   @WebMethod
+   public String getUsernameToken()
+   {
+      String retObj = "";
+      try
+      {       
+         MessageContext jaxwsContext = (MessageContext)wsCtx.getMessageContext();
+         SOAPMessage soapMessage = ((SOAPMessageContext)jaxwsContext).getMessage();
+         ByteArrayOutputStream stream = new ByteArrayOutputStream();
+         soapMessage.writeTo(stream);
+         log.info(stream.toString());
+         
+         SOAPPart soapPart = soapMessage.getSOAPPart();
+         SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+         StringWriter strw = new StringWriter();
+         ((SOAPEnvelopeImpl)soapEnvelope).writeElement(strw);
+         log.info(strw.toString());
+
+         SOAPHeader soapHeader = soapEnvelope.getHeader();
+         strw = new StringWriter();
+         ((SOAPHeaderImpl)soapHeader).writeElement(strw);
+         retObj = strw.toString();
+         log.info(retObj);
+
+         QName secQName = new QName(Constants.WSSE_NS, "Security");
+         Element secHeaderElement = Util.findElement(soapHeader, secQName);
+         log.info(secHeaderElement);
+      }
+      catch (SOAPException se)
+      {
+         log.error(se.getMessage());
+      }
+      catch (IOException ioe)
+      {
+         log.error(ioe.getMessage());
+      }
+      return retObj;
+   }
+}


Property changes on: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java	                        (rev 0)
+++ stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,31 @@
+
+package org.jboss.test.ws.jaxws.samples.wssecurity;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.Style;
+
+/**
+ * The SEI
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ * @since 15-Aug-2007
+ * @version $Revision$ 
+ */
+ at WebService(name = "UsernameEndpoint", targetNamespace = "http://org.jboss.ws/samples/wssecurity")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public interface UsernameEndpoint {
+
+    /**
+     * 
+     * @return
+     *     returns java.lang.String
+     */
+    @WebMethod
+    @WebResult(partName = "return")
+    public String getUsernameToken();
+
+}


Property changes on: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml	                        (rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.jboss.com/ws-security/config http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
+  <config>
+      <username/>
+  </config>
+</jboss-ws-security>
\ No newline at end of file


Property changes on: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl	                        (rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,30 @@
+<definitions name='UsernameService' targetNamespace='http://org.jboss.ws/samples/wssecurity' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://org.jboss.ws/samples/wssecurity' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
+ <types/>
+ <message name='UsernameEndpoint_getUsernameToken'></message>
+ <message name='UsernameEndpoint_getUsernameTokenResponse'>
+  <part name='return' type='xsd:string'/>
+ </message>
+ <portType name='UsernameEndpoint'>
+  <operation name='getUsernameToken'>
+   <input message='tns:UsernameEndpoint_getUsernameToken'/>   
+   <output message='tns:UsernameEndpoint_getUsernameTokenResponse'/>
+  </operation>
+ </portType>
+ <binding name='UsernameEndpointBinding' type='tns:UsernameEndpoint'>
+  <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
+  <operation name='getUsernameToken'>
+   <soap:operation soapAction=''/>
+   <input>
+    <soap:body namespace='http://org.jboss.ws/samples/wssecurity' use='literal'/>
+   </input>
+   <output>
+    <soap:body namespace='http://org.jboss.ws/samples/wssecurity' use='literal'/>
+   </output>
+  </operation>
+ </binding>
+ <service name='UsernameService'>
+  <port binding='tns:UsernameEndpointBinding' name='UsernameEndpointPort'>
+   <soap:address location='REPLACE_WITH_ACTUAL_URL'/>
+  </port>
+ </service>
+</definitions>
\ No newline at end of file


Property changes on: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-web.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-web.xml	                        (rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-web.xml	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jboss-web>
+  <security-domain>java:/jaas/JBossWS</security-domain>
+</jboss-web>
\ No newline at end of file


Property changes on: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-web.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-wsse-server.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-wsse-server.xml	                        (rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-wsse-server.xml	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.jboss.com/ws-security/config http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
+</jboss-ws-security>
\ No newline at end of file


Property changes on: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/jboss-wsse-server.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/web.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/web.xml	                        (rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/web.xml	2007-08-15 14:45:18 UTC (rev 4375)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+  version="2.4">
+
+  <servlet>
+    <servlet-name>UsernameService</servlet-name>
+    <servlet-class>org.jboss.test.ws.jaxws.samples.wssecurity.UsernameBean</servlet-class>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>UsernameService</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+
+  <security-constraint>
+     <web-resource-collection>
+       <web-resource-name>UsernameService</web-resource-name>
+       <url-pattern>/*</url-pattern>
+       <http-method>GET</http-method>
+       <http-method>POST</http-method>
+     </web-resource-collection>
+     <auth-constraint>
+       <role-name>friend</role-name>
+     </auth-constraint>
+   </security-constraint>
+
+   <login-config>
+      <auth-method>BASIC</auth-method>
+      <realm-name>JBossWS</realm-name>
+   </login-config>
+
+   <security-role>
+      <role-name>friend</role-name>
+   </security-role>
+
+</web-app>
+


Property changes on: stack/native/trunk/src/test/resources/jaxws/samples/wssecurity/simple-username/WEB-INF/web.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbossws-commits mailing list