[jboss-svn-commits] JBL Code SVN: r21641 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product: install/conf and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 20 09:05:59 EDT 2008


Author: beve
Date: 2008-08-20 09:05:59 -0400 (Wed, 20 Aug 2008)
New Revision: 21641

Added:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jaas.login
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-common.jar
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-core.jar
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractor.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/BaseWebServiceUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/cert-example.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-keys-example.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-userpass-example.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractorUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSTestUtil.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/error-soap-message.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/soap-userpass-message.xml
Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/build-distr.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jbossesb-properties.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBServiceContractPublisher.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/http/JbrHttpSecurityInfoExtractor.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/security/JaasSecurityServiceUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/build.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/jboss-esb.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/readme.txt
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SOAPTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SendEsbMessage.java
Log:
Work for JBESB-1948 "Integrate security with BaseWebService"


Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/build-distr.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/build-distr.xml	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/build-distr.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -80,6 +80,7 @@
                 <include name="jbossesb-properties.xml"/>
                 <include name="esb.juddi.xml"/>
                 <include name="actionArtifactMap.properties"/>
+                <include name="jaas.login"/>
             </fileset>
             <fileset dir="${installation.files.dir}/jUDDI-registry">
                 <include name="juddi-ds.xml"/>

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jaas.login
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jaas.login	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jaas.login	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1 @@
+// Plase login module configs here 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jbossesb-properties.xml	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/install/conf/jbossesb-properties.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -37,6 +37,11 @@
         <property name="org.jboss.soa.esb.loadbalancer.policy" value="org.jboss.soa.esb.listeners.ha.RoundRobin"/>
         <property name="jboss.esb.invm.scope.default" value="NONE"/>
     </properties>
+    <properties name="security">
+        <property name="org.jboss.soa.esb.services.security.implementationClass" value="org.jboss.internal.soa.esb.services.security.JaasSecurityService"/>
+        <property name="org.jboss.soa.esb.services.security.callbackHandler" value="org.jboss.internal.soa.esb.services.security.UserPassCallbackHandler"/>
+		<property name="org.jboss.soa.esb.services.security.configUrl" value="/jaas.login"/>
+    </properties>
     <properties name="registry">
     	<property name="org.jboss.soa.esb.registry.queryManagerURI" value="org.apache.juddi.registry.local.InquiryService#inquire"/>
     	<property name="org.jboss.soa.esb.registry.lifeCycleManagerURI" value="org.apache.juddi.registry.local.PublishService#publish"/>

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-common.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-common.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-core.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/lib/ext/jbossws-core.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -48,6 +48,9 @@
 import org.jboss.soa.esb.message.Fault;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.security.SecurityService;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.auth.ws.WSSecuritySoapExtractor;
 import org.w3c.dom.Document;
 
 import com.arjuna.common.util.propertyservice.PropertyManager;
@@ -66,10 +69,13 @@
     
     protected final ServiceInvoker serviceInvoker ;
     
+    private WSSecuritySoapExtractor securityExtractor;
+    
     protected BaseWebService(final String category, final String name)
         throws MessageDeliverException
     {
         serviceInvoker = new ServiceInvoker(category, name) ;
+        securityExtractor = new WSSecuritySoapExtractor();
     }
     
     public Object invoke(final Object obj)
@@ -109,6 +115,9 @@
                 throw new SOAPException("Could not find SOAPElement in SOAPBody") ;
             }
             
+            //	extract security information from SOAP and set on esb message
+            extractSecurityInfo(request, esbReq);
+            
             final Message esbRes = deliverMessage(esbReq) ;
             if (esbRes != null)
             {
@@ -199,6 +208,15 @@
         return faultMsg ;
     }
     
+    private void extractSecurityInfo(final SOAPMessage from, final Message to)
+	{
+    	final AuthenticationRequest authRequest = securityExtractor.extractSecurityInfo(from);
+    	if ( authRequest != null )
+    	{
+    		to.getProperties().setProperty( SecurityService.AUTH_REQUEST, authRequest );
+    	}
+	}
+    
     protected abstract Message deliverMessage(final Message request)
         throws Exception ;
     

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBServiceContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBServiceContractPublisher.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBServiceContractPublisher.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -1,3 +1,23 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.internal.soa.esb.webservice;
 
 import java.net.URI;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestImpl.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestImpl.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -23,9 +23,12 @@
 import java.io.Serializable;
 import java.security.Principal;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.jboss.soa.esb.services.security.principals.User;
+
 /**
  * AuthenticationRequestImpl is indended to transport security related information
  * needed to authenticate a caller.
@@ -68,17 +71,19 @@
 	
 	public static class Builder
 	{
-		// required
     	private Principal principal;
-    	private Set<?> credentials;
-    	
-    	// optional
+    	private Set<Object> credentials = new HashSet<Object>();
     	private Map<String,Object> properties = new HashMap<String,Object>();
     	
-    	public Builder(final Principal principal, final Set<?> credentials)
+    	public Builder() {}
+    	
+    	public Builder(final Principal principal, final Set<Object> credentials)
     	{
     		this.principal = principal;
-    		this.credentials = credentials;
+    		if ( credentials != null )
+    		{
+        		this.credentials.addAll(credentials);
+    		}
     	}
     	
     	public Builder property( final String name, final Object value)
@@ -87,6 +92,18 @@
     		return this;
     	}
     	
+    	public Builder username( final String username )
+    	{
+    		principal = new User( username );
+    		return this;
+    	}
+    	
+    	public Builder password( final char[] password )
+    	{
+    		credentials.add(password);
+    		return this;
+    	}
+    	
     	public AuthenticationRequest bulid()
     	{
     		return new AuthenticationRequestImpl(this);

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/http/JbrHttpSecurityInfoExtractor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/http/JbrHttpSecurityInfoExtractor.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/http/JbrHttpSecurityInfoExtractor.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -49,7 +49,7 @@
 		if ( username != null )
 		{
 			User user = new User((String)username);
-			Set<char[]> credentials = new HashSet<char[]>();
+			Set<Object> credentials = new HashSet<Object>();
 			
 			String passwd = (String) request.get(PASSWORD_KEY);
 			if ( passwd != null )

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractor.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractor.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.soa.esb.services.security.auth.ws;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequestImpl;
+import org.jboss.soa.esb.services.security.auth.SecurityInfoExtractor;
+import org.jboss.soa.esb.services.security.principals.User;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * WSSecurityInfoExtractor extracts security related information from
+ * a SOAP security header. 
+ * </p>
+ * 
+ * If the security element contains a 'UsernameToken' element this will be
+ * extraced into a principal with the username and a credential being the
+ * password represented as a character array. 
+ * <br>
+ * If the security element contains a 'BinarySecurityToken' element this informaiton
+ * will be extracted into a credential which will be the content, or value, of
+ * the BinarySecurityToken element.
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class WSSecuritySoapExtractor implements SecurityInfoExtractor<SOAPMessage>
+{
+	/**
+	 * Security element localname
+	 */
+	public static final String WSSE_LN = "Security";
+	
+	/**
+	 * SOAP Message Security 1.0 NameSpace URL
+	 */
+	public static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
+	
+	private Logger log = Logger.getLogger(WSSecuritySoapExtractor.class);
+	
+	/**
+	 * Extracts UsernameToken element is one exists and creates
+	 * a Principal with the username and sets a Credential using
+	 * the password. The type of the Credential is a character array.
+	 * If the SOAP message contains a BinarySecurityToken this will be
+	 * extracted and added as a Credential.
+	 * <p>
+	 * Note that this method i restrictive in reporting errors within the soap
+	 * message. This is instead reflected in missing values in the returned
+	 * AuthenticationRequest. This is done on purpose as not to give away
+	 * any information about missing information. The SecuritySerivce impl
+	 * should decide what information it wants a caller to recieve.
+	 * 
+	 * @param soap - the soap message represented as a String
+	 * @return {@link AuthenticationRequest}
+	 */
+	public AuthenticationRequest extractSecurityInfo(final SOAPMessage soap)
+	{
+		if ( soap == null )
+		{
+			return null;
+		}
+		
+		User user = null;
+		Set<Object> credentials = new HashSet<Object>();
+		
+		try
+		{
+			final SOAPHeaderElement securityHeader = getSecurityHeader( soap.getSOAPPart().getEnvelope() );
+			if ( securityHeader == null )
+			{
+				return null;
+			}	
+			Iterator childElements = securityHeader.getChildElements();
+			while ( childElements.hasNext() )
+			{
+    			final Node securityNode = (Node) childElements.next();
+    			if ( securityNode.getNodeType() == Node.ELEMENT_NODE )
+    			{
+    				final String localName = securityNode.getLocalName();
+        			if ( "BinarySecurityToken".equalsIgnoreCase( localName ) )
+        			{
+        				//	create a BinarySecurityToken (does some filtering and checking)
+        				final BinarySecurityToken binaryToken = createBinarySecurityToken(securityNode);
+        				// 	add the key(cert) as a credential
+                		credentials.add(binaryToken.getKey());
+        			}
+        			else if ( "UsernameToken".equalsIgnoreCase(localName) )
+        			{
+        				UsernameToken usernameToken = createUsernameToken(securityNode);
+        				final String userName = usernameToken.getUserName();
+        				if ( userName != null )
+        				{
+            				user = new User(usernameToken.getUserName());
+        				}	
+        				char[] passwd = usernameToken.getPassword();
+        				if ( passwd != null )
+        				{
+    						credentials.add(passwd);
+        				}
+        			}
+    			}
+			}
+			// build the AuthenticationRequest. 
+    		return new AuthenticationRequestImpl.Builder(user, credentials ).bulid();
+		} 
+		catch (final SOAPException e)
+		{
+			log.error("Caught a SOAPException while trying to extract security information: ", e);
+			throw new SecurityException("Could not extract security info from SOAPMessage");
+		}
+	}
+	
+	private SOAPHeaderElement getSecurityHeader( final SOAPEnvelope env ) throws SOAPException 
+	{
+		final SOAPHeader soapHeader = env.getHeader();
+		if ( soapHeader == null)
+			return null;
+			
+		Iterator<?> headerElements = soapHeader.examineAllHeaderElements();
+		while ( headerElements.hasNext() ) 
+		{
+			final SOAPHeaderElement header = (SOAPHeaderElement) headerElements.next();
+			final Name name = header.getElementName();
+
+			if (name.getLocalName().equalsIgnoreCase(WSSE_LN) && name.getURI().equalsIgnoreCase(WSSE_NS) )
+			{
+				return header;
+			}
+		}
+		return null;
+	}
+	
+	private BinarySecurityToken createBinarySecurityToken( final Node node )
+	{
+		final NamedNodeMap attributes = node.getAttributes();;
+		
+		//	get the EncodingType
+		final Node encodingTypeNode = attributes.getNamedItem("EncodingType");
+		final String encodingType = encodingTypeNode.getNodeValue();
+		
+		//	get the ValueType
+		final Node valueTypeNode = attributes.getNamedItem("ValueType");
+		final String valueType = valueTypeNode.getNodeValue();
+		
+		//	get the certificate
+		final String certString = node.getFirstChild().getNodeValue();
+		
+		//	create a BinarySecurityToken (does some filtering and checking for us
+		final BinarySecurityToken binaryToken = new BinarySecurityToken();
+		binaryToken.setEncodingType(encodingType);
+		binaryToken.setValueType(valueType);
+		binaryToken.setKey(certString);
+		return binaryToken;
+	}
+	
+	private UsernameToken createUsernameToken (final Node node)
+	{
+		final NodeList usernameElements = node.getChildNodes();
+		int nrOfElements = usernameElements.getLength();
+		final UsernameToken usernameToken = new UsernameToken();
+		for ( int i = 0 ; i < nrOfElements ; i ++ )
+		{
+			final Node element = usernameElements.item(i);
+			final String elLocalName = element.getLocalName();
+			if ( "Username".equalsIgnoreCase( elLocalName ) )
+			{
+				usernameToken.setUserName(element.getFirstChild().getNodeValue());
+			}
+			else if ( "Password".equalsIgnoreCase( elLocalName ) )
+			{
+				usernameToken.setPassword(element.getFirstChild().getNodeValue());
+			}
+		}
+		return usernameToken;
+	}
+
+}

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/security/JaasSecurityServiceUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/security/JaasSecurityServiceUnitTest.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/security/JaasSecurityServiceUnitTest.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -20,9 +20,9 @@
  */
 package org.jboss.internal.soa.esb.services.security;
 
-import static org.junit.Assert.*;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.net.URL;
 import java.security.Principal;
@@ -33,7 +33,6 @@
 
 import junit.framework.JUnit4TestAdapter;
 
-import org.antlr.stringtemplate.test.FailedAssertionException;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.services.security.SecurityConfig;
@@ -70,7 +69,7 @@
 		final String password = "testPassword";
 		SecurityConfig configInfo = SecurityConfig.createSecurityInfo(null, null, "UserPassLogin", "org.jboss.internal.soa.esb.services.security.UserPassCallbackHandler", null);
 		TestPrincipal principal = new TestPrincipal(userName);
-		Set<String> credentials = new HashSet<String>();
+		Set<Object> credentials = new HashSet<Object>();
 		credentials.add(password);
 		
 		AuthenticationRequest authRequest = new AuthenticationRequestImpl.Builder(principal, credentials).bulid();

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/BaseWebServiceUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/BaseWebServiceUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/BaseWebServiceUnitTest.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.internal.soa.esb.webservice;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.cert.X509Certificate;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.security.SecurityService;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.auth.ws.WSTestUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Unittest for {@link BaseWebService}
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class BaseWebServiceUnitTest
+{
+	private static String serviceCategory = "cat";
+	private static String serviceName = "name";
+	private static MockCourier mockCourier;
+	
+	@Test
+	public void invokeWithBinarySecurityTokenHeader() throws ParserConfigurationException, SAXException, IOException, SOAPException, MessageDeliverException
+	{
+		SOAPMessage soap = WSTestUtil.createMessage("soap-keys-example.xml", BaseWebServiceUnitTest.class);
+		MockBaseWebService service = new MockBaseWebService(serviceCategory, serviceName);
+		service.invoke(soap);
+		
+		Message esbMessage = service.getEsbMessage();
+		AuthenticationRequest authRequest = (AuthenticationRequest) esbMessage.getProperties().getProperty( SecurityService.AUTH_REQUEST );
+		assertNotNull( authRequest );
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof X509Certificate );
+	}
+	
+	@Test
+	public void invokeWithUsernameTokenHeader() throws ParserConfigurationException, SAXException, IOException, SOAPException, MessageDeliverException
+	{
+		SOAPMessage soap = WSTestUtil.createMessage("soap-userpass-example.xml", BaseWebServiceUnitTest.class);
+		MockBaseWebService service = new MockBaseWebService(serviceCategory, serviceName);
+		service.invoke(soap);
+		
+		Message esbMessage = service.getEsbMessage();
+		AuthenticationRequest authRequest = (AuthenticationRequest) esbMessage.getProperties().getProperty( SecurityService.AUTH_REQUEST );
+		assertNotNull( authRequest );
+		assertEquals("Clark", authRequest.getPrincipal().getName());
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof char[] );
+	}
+	
+	@BeforeClass
+	public static void setup() throws ConfigurationException, URISyntaxException
+	{
+        MockCourierFactory.install();
+		MockRegistry.install();
+        EPR epr = new EPR(new URI("test1"));
+		mockCourier = new MockCourier(true);
+		MockRegistry.register(serviceCategory, serviceName, epr, mockCourier);
+	}
+	
+	@AfterClass
+	public static void tearDown()
+	{
+		MockRegistry.uninstall();
+        MockCourierFactory.uninstall();
+	}
+	
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter(BaseWebServiceUnitTest.class);
+	}
+
+	private class MockBaseWebService extends BaseWebService
+	{
+		private Message esbMessage;
+		
+		public Message getEsbMessage()
+		{
+			return esbMessage;
+		}
+	
+		protected MockBaseWebService(String category, String name) throws MessageDeliverException
+		{
+			super(category, name);
+		}
+	
+		@Override
+		protected Message deliverMessage(Message request) throws Exception
+		{
+			this.esbMessage = request;
+			
+			return request;
+		}
+	}
+}

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/cert-example.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/cert-example.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/cert-example.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,11 @@
+MIICQjCCAasCBEif0tUwDQYJKoZIhvcNAQEEBQAwaDELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0
+b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVK
+Qm9zczEPMA0GA1UEAxMGRGFuaWVsMB4XDTA4MDgxMTA1NDkwOVoXDTA4MTEwOTA1NDkwOVowaDEL
+MAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYD
+VQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVKQm9zczEPMA0GA1UEAxMGRGFuaWVsMIGfMA0GCSqGSIb3
+DQEBAQUAA4GNADCBiQKBgQCdSh96Xyt4LeZbXz9pk4eaHrj2sGFmI9lkLQiW/DbF9ETXFvWYCS4N
+lsONmPx63KSbzJZQZRlJSAW2y6hQO18G9NMFQpn2W/jtPSw61kH3dXDQ+kZ2UMk9K93nt4XLvGm6
+dMQAGZAjzpz4lzhcYrDJI4NMw5LpeljDawkradtuiwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAHi2
+S1zC8jIqncSeMRwOvPOEQIcsZJELYFUCiTwPrAg5hNkp/oewm6uCkgqmry09+3+ZXg2KLQ+RgeuV
+8yfeBvk7TFjtOWeHWnBOaxKiAyLibxGchVfMPl847MZ2w4d6vu776cqb1NKghAE53dn9AzUHIWwx
+OizXyDaDiBMj5xgs

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-keys-example.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-keys-example.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-keys-example.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,21 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+    <soap:Header>
+        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+            <wsse:BinarySecurityToken EncodingType="wsse:Base64Binary" ValueType="wsse:X509v3">MIICVDCCAb0CBEii4NgwDQYJKoZIhvcNAQEEBQAwcTELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0
+b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVK
+Qm9zczEYMBYGA1UEAxMPRGFuaWVsIEJldmVuaXVzMB4XDTA4MDgxMzEzMjU0NFoXDTM1MTIyOTEz
+MjU0NFowcTELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0b2NraG9sbTESMBAGA1UEBxMJU3RvY2to
+b2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVKQm9zczEYMBYGA1UEAxMPRGFuaWVsIEJl
+dmVuaXVzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJRSE6wHkF5DK6DkHTMPnP4dNZXeon
+cCP7Ufn5hjXWLdsq9dAEbuiRLAE4HoNxxqgCHdoKjMO9N1/CIn5dmWw4DBWLp8OHx8Wnyp0MYmCz
+B31jHJpuXkkRq50vRYtKN0NIOyw7eF+XWf4u0dXNgFtXHuUxhAyEm/kTxO1SNVUTwwIDAQABMA0G
+CSqGSIb3DQEBBAUAA4GBADCzl0gXAY0xysdHkKNdwaBDzlibLPz2zmaHcit841qVn05p/I1gsbUV
+vEPh6i/Dj57vdE+X66sPbI36uZiqyWqEr6wvCJDtaTbhSLmckk7ioXwLvdKEQ150MPBsjWRRnFGN
+tZhrQfjo0q8seLh0kgconbfN4pHllfNkJPcdSBvi</wsse:BinarySecurityToken>
+        </wsse:Security>
+    </soap:Header>
+    <soap:Body>
+    	<dummyBody>hello</dummyBody>
+    </soap:Body>
+</soap:Envelope> 
+

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-userpass-example.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-userpass-example.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/soap-userpass-example.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,19 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
+			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+			xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+					
+  <soap:Header>
+    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+      <wsse:UsernameToken>
+        <wsse:Username>Clark</wsse:Username>
+        <wsse:Password>griswald</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+
+  <soap:Body>
+  	<dummyBody>some content...</dummyBody>
+  </soap:Body>
+
+</soap:Envelope> 
+

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestUnitTest.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/AuthenticationRequestUnitTest.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -44,6 +44,16 @@
 		assertEquals( principal, request.getPrincipal());
 	}
 	
+	@Test
+	public void build()
+	{
+		final String username = "Donald";
+		final String password = "Duck123";
+		AuthenticationRequest request = new AuthenticationRequestImpl.Builder().username(username).password(password.toCharArray()).bulid();
+		assertEquals( username, request.getPrincipal().getName() );
+		assertTrue( request.getCredentials().size() == 1 );
+	}
+	
 	public static junit.framework.Test suite()
 	{
 		return new JUnit4TestAdapter(AuthenticationRequestUnitTest.class);

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractorUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractorUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecuritySoapExtractorUnitTest.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.soa.esb.services.security.auth.ws;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Unit test for {@link WSSecuritySoapExtractor}
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class WSSecuritySoapExtractorUnitTest
+{
+	@Test
+	public void extractSecurityInfoBinarySecurityToken() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		SOAPMessage soap = WSTestUtil.createWithBinarySecurityToken("wsse:Base64Binary", "wsse:X509v3", WSTestUtil.getStringFromFile("cert-example.xml", getClass()));
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof X509Certificate );
+	}
+	
+	@Test
+	public void extractSecurityInfoBinarySecurityTokenNoNSPrifix() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		//	create the SAOPMessage with out namespace prefixes for ValueType and EncodingType
+		SOAPMessage soap = WSTestUtil.createWithBinarySecurityToken("Base64Binary", "X509v3", WSTestUtil.getStringFromFile("cert-example.xml", getClass()));
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof X509Certificate );
+	}
+	
+	@Test
+	public void extractSecurityInfoBinarySecurityTokenFromFile() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		SOAPMessage soap = WSTestUtil.createMessage("soap-keys-example.xml", getClass());
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof X509Certificate );
+	}
+	
+	@Test
+	public void extractSecurityInfoUsernameToken() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		final String username = "Bubbles";
+		final String password = "228833dkd0";
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		SOAPMessage soap = WSTestUtil.createWithUsernameToken(username, password);
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertEquals(username, authRequest.getPrincipal().getName());
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof char[] );
+	}
+	
+	@Test
+	public void extractSecurityInfoUsernameTokenNoUsername() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		final String password = "228833dkd0";
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		SOAPMessage soap = WSTestUtil.createWithUsernameToken(null, password);
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertEquals(null, authRequest.getPrincipal() );
+		assertTrue(authRequest.getCredentials().size() == 1 );
+		assertTrue(authRequest.getCredentials().iterator().next() instanceof char[] );
+	}
+	
+	@Test
+	public void extractSecurityInfoUsernameTokenNoPassword() throws SAXException, IOException, ParserConfigurationException, ConfigurationException, SOAPException
+	{
+		final String username = "Bubbles";
+		WSSecuritySoapExtractor extractor = new WSSecuritySoapExtractor();
+		SOAPMessage soap = WSTestUtil.createWithUsernameToken(username, null);
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		
+		assertNotNull(authRequest);
+		assertEquals(username, authRequest.getPrincipal().getName());
+		assertTrue(authRequest.getCredentials().size() == 0 );
+	}
+	
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter(WSSecuritySoapExtractorUnitTest.class);
+	}
+	
+}

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSTestUtil.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSTestUtil.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSTestUtil.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.soa.esb.services.security.auth.ws;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.transform.dom.DOMSource;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * This class contains methods for creating SOAPMessages with 
+ * different headers, for example Security headers.
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class WSTestUtil
+{
+	private WSTestUtil() { }
+	
+	/**
+	 * Creates a SOAPMessage with a BinarySecurityToken header.
+	 * </p>
+	 * <pre>{@code
+	 * <soap:Header>
+	 *  <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
+	 *   <wsse:BinarySecurityToken EncodingType="encodingType" ValueType="valueTyep">cert
+	 * </wsse:Security>
+	 * }</pre>
+	 * <br><br>
+	 * Example usage:
+	 * <pre>{@code
+	 *  SOAPMessage soap = WSTestUtil.createWithBinarySecurityToken("Base64Binary", "X509v3", WSTestUtil.getStringFromFile("cert-example.xml", getClass()));
+	 * }</pre>
+	 * 
+	 * @param encodingType - The encoding type( Base64Binary, HexBinary)
+	 * @param valueType	- the type of key ( they key is the value of the BinarySecurityToken element )
+	 * @param cert - the cert represented as a string
+	 * @return SOAPMessage - populated with the BinarySecurityToken security header
+	 * @throws SOAPException - if something goes wrong.
+	 */
+	public static SOAPMessage createWithBinarySecurityToken(final String encodingType, final String valueType, final String cert) throws SOAPException
+	{
+		SOAPMessage soapMessage = createMessage();
+	    SOAPPart soapPart = soapMessage.getSOAPPart();
+	    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+	    SOAPHeader soapHeader = soapEnvelope.getHeader();
+	    
+	    Name security = soapEnvelope.createName(WSSecuritySoapExtractor.WSSE_LN, "wsse", WSSecuritySoapExtractor.WSSE_NS);
+	    SOAPHeaderElement headerElement = soapHeader.addHeaderElement( security );
+	    
+	    createBinaryHeaderElement(soapEnvelope, headerElement, encodingType, valueType, cert );
+
+	    return soapMessage;
+	}
+	
+	/**
+	 * Creates a SOAPMessage with a UsernameToken header.
+	 * <p/>
+	 * <br>
+	 * <pre>{@code
+	 * <soap:Header>
+	 *     <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
+	 *         <wsse:UsernameToken>
+	 *             <wsse:Username>Clark</wsse:Username>
+	 *             <wsse:Password>griswald</wsse:Password>
+	 *         </wsse:UsernameToken>
+	 *     </wsse:Security>
+	 * </soap:Header>
+	 * 
+	 * }</pre>
+	 * <br><br>
+	 * Example usage:
+	 * <pre>{@code
+	 *  SOAPMessage soap = WSTestUtil.createWithUsernameToken(username, password);
+	 * }</pre>
+	 * 
+	 * @param username 
+	 * @param password	
+	 * @return SOAPMessage - populated with the UsernameToken security header
+	 * @throws SOAPException - if something goes wrong.
+	 */
+	public static SOAPMessage createWithUsernameToken(final String username, final String password) throws SOAPException
+	{
+		SOAPMessage soapMessage = createMessage();
+	    SOAPPart soapPart = soapMessage.getSOAPPart();
+	    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+	    SOAPHeader soapHeader = soapEnvelope.getHeader();
+	    
+	    Name security = soapEnvelope.createName(WSSecuritySoapExtractor.WSSE_LN, "wsse", WSSecuritySoapExtractor.WSSE_NS);
+	    SOAPHeaderElement headerElement = soapHeader.addHeaderElement( security );
+	    
+	    createUsernameTokenHeaderElement(soapEnvelope, headerElement, username, password );
+
+	    return soapMessage;
+	}
+	
+	public static SOAPMessage createMessage() throws SOAPException
+	{
+		SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
+	    return soapMessage;
+	}
+	
+	public static String getStringFromFile(final String fileName, final Class<?> clazz )
+	{
+		InputStream inputStream = ClassUtil.getResourceAsStream(fileName, clazz );
+		return new String(StreamUtils.readStream(inputStream));
+	}
+	
+	public static void dumpSoap(final SOAPMessage soap )
+	{
+		final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+		try
+		{
+			soap.writeTo(bout);
+			System.out.println(new String(bout.toByteArray()));
+		} 
+		catch (final SOAPException e1)
+		{
+			e1.printStackTrace();
+		} 
+		catch (final IOException e1)
+		{
+			e1.printStackTrace();
+		}
+	}
+	
+	/**
+	 * Creates a SOAPMessage from the contents of the passed in filename.
+	 * 
+	 * @param fileName - the file containing the soap envelope.
+	 * @param clazz - the class used to search from ( think getClass().getResource...).
+	 * @return SOAPMessage - a SOAPMessage populated from the contents of the file.
+	 * 
+	 * @throws ParserConfigurationException
+	 * @throws SAXException
+	 * @throws IOException
+	 * @throws SOAPException
+	 */
+	public static SOAPMessage createMessage( final String fileName, final Class<?> clazz ) throws ParserConfigurationException, SAXException, IOException, SOAPException
+	{
+		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+		dbFactory.setNamespaceAware(true);
+		DocumentBuilder builder = dbFactory.newDocumentBuilder();
+		Document document = builder.parse( ClassUtil.getResource(fileName, clazz).getFile());
+		DOMSource domSource = new DOMSource(document);
+		
+		SOAPMessage message = createMessage();
+		SOAPPart soapPart = message.getSOAPPart();
+		soapPart.setContent(domSource);
+		return message;
+	}
+	
+	public static SOAPMessage createMessage( final String fileName ) throws ParserConfigurationException, SAXException, IOException, SOAPException
+	{
+		return createMessage(fileName, WSTestUtil.class );
+	}
+
+	private static SOAPElement createBinaryHeaderElement(
+			final SOAPEnvelope soapEnvelope,
+			final SOAPHeaderElement headerElement,
+			final String encodingType,
+			final String valueType,
+			final String cert) throws SOAPException
+	{
+		//	create the BinarySecurityToken element
+		Name binarySecurityTokenName = soapEnvelope.createName("BinarySecurityToken", "wsse", WSSecuritySoapExtractor.WSSE_NS);
+	    SOAPElement binarySecurityTokenElement = headerElement.addChildElement(binarySecurityTokenName);
+	    
+	    //	add the EncodingType attribute
+	    binarySecurityTokenElement.addAttribute(soapEnvelope.createName("EncodingType"), encodingType); 
+	    //	add the ValueType attribute
+	    binarySecurityTokenElement.addAttribute(soapEnvelope.createName("ValueType"), valueType);
+	    //	add the certificate as a text node
+	    binarySecurityTokenElement.addTextNode(cert);
+	    return binarySecurityTokenElement;
+	}
+	
+	private static SOAPElement createUsernameTokenHeaderElement(
+			final SOAPEnvelope soapEnvelope,
+			final SOAPHeaderElement headerElement,
+			final String username,
+			final String password) throws SOAPException
+	{
+		//	create the UsernameToken element
+		Name usernameTokenName = soapEnvelope.createName("UsernameToken", "wsse", WSSecuritySoapExtractor.WSSE_NS);
+	    SOAPElement usernameTokenElement = headerElement.addChildElement(usernameTokenName);
+	    
+	    //	create and add the Username sub element
+	    if ( username != null )
+	    {
+    		Name usernameName = soapEnvelope.createName("Username", "wsse", WSSecuritySoapExtractor.WSSE_NS);
+    	    SOAPElement usernameNode = usernameTokenElement.addChildElement(usernameName);
+    	    usernameNode.addTextNode(username);
+	    }
+	    
+	    //	create and add the password sub element
+	    if ( password != null )
+	    {
+    		Name passwordName = soapEnvelope.createName("password", "wsse", WSSecuritySoapExtractor.WSSE_NS);
+    	    SOAPElement passwordNode = usernameTokenElement.addChildElement(passwordName);
+    	    passwordNode.addTextNode(password);
+	    }
+		
+	    return usernameTokenElement;
+	}
+
+
+}

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -1,22 +1,19 @@
-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
-			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-			xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-    <soap:Header>
-        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
-            <wsse:BinarySecurityToken EncodingType="wsse:Base64Binary" ValueType="wsse:X509v3">MIICVDCCAb0CBEii4NgwDQYJKoZIhvcNAQEEBQAwcTELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0
+<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
+	<env:Header>
+		<wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
+			<wsse:BinarySecurityToken EncodingType='wsse:Base64Binary' ValueType='wsse:X509v3'>MIICQjCCAasCBEif0tUwDQYJKoZIhvcNAQEEBQAwaDELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0
 b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVK
-Qm9zczEYMBYGA1UEAxMPRGFuaWVsIEJldmVuaXVzMB4XDTA4MDgxMzEzMjU0NFoXDTM1MTIyOTEz
-MjU0NFowcTELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0b2NraG9sbTESMBAGA1UEBxMJU3RvY2to
-b2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVKQm9zczEYMBYGA1UEAxMPRGFuaWVsIEJl
-dmVuaXVzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJRSE6wHkF5DK6DkHTMPnP4dNZXeon
-cCP7Ufn5hjXWLdsq9dAEbuiRLAE4HoNxxqgCHdoKjMO9N1/CIn5dmWw4DBWLp8OHx8Wnyp0MYmCz
-B31jHJpuXkkRq50vRYtKN0NIOyw7eF+XWf4u0dXNgFtXHuUxhAyEm/kTxO1SNVUTwwIDAQABMA0G
-CSqGSIb3DQEBBAUAA4GBADCzl0gXAY0xysdHkKNdwaBDzlibLPz2zmaHcit841qVn05p/I1gsbUV
-vEPh6i/Dj57vdE+X66sPbI36uZiqyWqEr6wvCJDtaTbhSLmckk7ioXwLvdKEQ150MPBsjWRRnFGN
-tZhrQfjo0q8seLh0kgconbfN4pHllfNkJPcdSBvi</wsse:BinarySecurityToken>
-        </wsse:Security>
-    </soap:Header>
-    <soap:Body>
-    </soap:Body>
-</soap:Envelope> 
-
+Qm9zczEPMA0GA1UEAxMGRGFuaWVsMB4XDTA4MDgxMTA1NDkwOVoXDTA4MTEwOTA1NDkwOVowaDEL
+MAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYD
+VQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVKQm9zczEPMA0GA1UEAxMGRGFuaWVsMIGfMA0GCSqGSIb3
+DQEBAQUAA4GNADCBiQKBgQCdSh96Xyt4LeZbXz9pk4eaHrj2sGFmI9lkLQiW/DbF9ETXFvWYCS4N
+lsONmPx63KSbzJZQZRlJSAW2y6hQO18G9NMFQpn2W/jtPSw61kH3dXDQ+kZ2UMk9K93nt4XLvGm6
+dMQAGZAjzpz4lzhcYrDJI4NMw5LpeljDawkradtuiwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAHi2
+S1zC8jIqncSeMRwOvPOEQIcsZJELYFUCiTwPrAg5hNkp/oewm6uCkgqmry09+3+ZXg2KLQ+RgeuV
+8yfeBvk7TFjtOWeHWnBOaxKiAyLibxGchVfMPl847MZ2w4d6vu776cqb1NKghAE53dn9AzUHIWwx
+OizXyDaDiBMj5xgs
+</wsse:BinarySecurityToken>
+		</wsse:Security>
+	</env:Header>
+	<env:Body></env:Body>
+</env:Envelope>
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/build.xml	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/build.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -13,15 +13,15 @@
 	<target name="runtest" depends="compile"  description="sends soap message to published web service">
 		<echo>Send soap message to published web service and receive reponse</echo>
 		<java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.publishAsWebservice.test.SOAPTest" failonerror="true">
-		      <arg value="HelloWorld"/>	
-                      <classpath refid="exec-classpath"/>
+		      <arg value="soap-userpass-message.xml"/>	
+			  <classpath refid="exec-classpath"/>
 		</java>
                 <echo/>
                 <echo/>
 		<echo>Send soap message to published web service and receive soap fault message</echo>
 		<java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.publishAsWebservice.test.SOAPTest" failonerror="true">
-		      <arg value="Error"/>	
-                      <classpath refid="exec-classpath"/>
+		      <arg value="error-soap-message.xml"/>	
+			  <classpath refid="exec-classpath"/>
 		</java>
 	</target> 
 	
@@ -31,6 +31,8 @@
 			<arg value="ESBServiceSample"/> <!--  service category -->
 			<arg value="HelloWorldPubService"/>  <!--  service name -->
 			<arg value="HelloWorld"/> <!--  Message text -->
+			<arg value="esbuser"/> <!--  username text -->
+			<arg value="esbpassword"/> <!--  password text -->
 			<classpath refid="exec-classpath"/>
 		</java>
 		<echo>Send esb message to esb service and get error</echo>
@@ -38,6 +40,8 @@
 			<arg value="ESBServiceSample"/> <!--  service category -->
 			<arg value="HelloWorldPubService"/>  <!--  service name -->
 			<arg value="Error"/> <!--  Message text -->
+			<arg value="esbuser"/> <!--  username text -->
+			<arg value="esbpassword"/> <!--  password text -->
 			<classpath refid="exec-classpath"/>
 		</java>
 

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/error-soap-message.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/error-soap-message.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/error-soap-message.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,19 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
+			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+			xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+			xmlns:say="http://www.jboss.org/sayHi">
+					
+  <soap:Header>
+    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+      <wsse:UsernameToken>
+        <wsse:Username>esbuser</wsse:Username>
+        <wsse:Password>esbpassword</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+
+  <soap:Body>
+      <say:sayHi><say:Error>Error</say:Error></say:sayHi>
+  </soap:Body>
+
+</soap:Envelope> 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/jboss-esb.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/jboss-esb.xml	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/jboss-esb.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -19,17 +19,16 @@
         	category="ESBServiceSample" 
         	name="HelloWorldPubService" 
         	description="Hello world ESB Service">
+			<security moduleName="messaging" />
+
             <listeners>
                 <jms-listener name="helloWorld"
                               busidref="quickstartEsbChannel"
                               maxThreads="1"
                 />
             </listeners>
-            <actions  inXsd="/request.xsd" outXsd="/response.xsd" faultXsd="/fault.xsd">
-                   <action name="action" 
-                   	class="org.jboss.soa.esb.samples.quickstart.publishAsWebservice.MyJMSListenerAction" 
-                   	process="displayMessage" 
-                   	/>  
+            <actions  inXsd="/request.xsd" outXsd="/response.xsd" faultXsd="/fault.xsd" webservice="security">
+                   <action name="action" class="org.jboss.soa.esb.samples.quickstart.publishAsWebservice.MyJMSListenerAction" process="displayMessage"/>  
             </actions>
         </service>
       </services>

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/readme.txt
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/readme.txt	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/readme.txt	2008-08-20 13:05:59 UTC (rev 21641)
@@ -1,18 +1,83 @@
-Overview:
-=========
-  The purpose of the publish_as_webservice quickstart sample is to demonstrate how to 
-  publish a esb service as a web service. 
+Overview:
 
-Running this quickstart:
-========================
-  Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
-  and a more detailed descripton of the different ways to run the quickstarts.
+=========
 
-To Run '.esb' archive mode:
-===========================
-  1. In a command terminal window in this folder ("Window1"), type 'ant deploy'.
-  2. Open another command terminal window in this folder ("Window2"), type
-     'ant runtest'.
-  3. Open another command terminal window in this folder ("Window2"), type
-     'ant sendesb'.
-  4. In this folder ("Window1"), type 'ant undeploy'.
+  The purpose of the publish_as_webservice quickstart sample is to demonstrate how to 
+  publish a esb service as a web service. 
+
+  This quickstart also demonstrates web service security using a UsernameToken in the 
+  SOAP header.
+
+
+
+Running this quickstart:
+
+========================
+
+  Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
+
+  and a more detailed descripton of the different ways to run the quickstarts.
+
+
+
+To Run '.esb' archive mode:
+
+===========================
+
+  1. In a command terminal window in this folder ("Window1"), type 'ant deploy'.
+
+  2. Open another command terminal window in this folder ("Window2"), type
+
+     'ant runtest'.
+
+  3. Open another command terminal window in this folder ("Window2"), type
+
+     'ant sendesb'.
+
+  4. In this folder ("Window1"), type 'ant undeploy'.
+
+
+Things to look for in this quickstart:
+
+======================================
+
+  1. soap-userpass-message.xml
+	 This is the SOAP Envelope that is sent to the Web Service. 
+ 	 Take a look at the header:
+		<soap:Header>
+			<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+				<wsse:UsernameToken>
+					<wsse:Username>esbuser</wsse:Username>
+					<wsse:Password>esbpassword</wsse:Password>
+				</wsse:UsernameToken>
+			</wsse:Security>
+		</soap:Header>
+	 The above is using the UsernameToken element to specify a username and password.
+	 Try changing the username or password to se what happens. Notice the response you
+	 get when incorrect username or password is specified.
+
+  2. jboss-esb.xml
+	 First we'll take a look at the service security configuration:
+	 <service category="ESBServiceSample" name="HelloWorldPubService" description="Hello world ESB Service">
+		<security moduleName="messaging" />
+	    ...
+	 </service>
+	 This is simply specifying that we want to use the 'messaging' login module. This is defined in conf/login-config.xml
+	 of the jbossesb-server. You can see that this definition point to two files: 
+	 * conf/props/messaging-users.properties - username and password are specified here 
+	 * conf/props/messaging-roles.properties 
+	 Also notice how the the actions element contains additional attributes:
+	 <actions  inXsd="/request.xsd" outXsd="/response.xsd" faultXsd="/fault.xsd" webservice="security">
+
+  3. runtest ant target
+	 This target will call the SOAPTest client twice, first call will be with a valid SOAP message
+	 and the second call will generate a SOAPFault to be retured. 
+
+  4. sendesb ant target
+	 This target will call the SendEsbMessage twice. The first call will be with a valid message body content
+	 and the second will generate a FaultMessageException.
+	 In this case the username and password are being passed to the SendEsbMessage's main method. The username 
+	 and password are set in build.xml. 
+	 
+
+		

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/soap-userpass-message.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/soap-userpass-message.xml	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/soap-userpass-message.xml	2008-08-20 13:05:59 UTC (rev 21641)
@@ -0,0 +1,19 @@
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
+			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+			xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+			xmlns:say="http://www.jboss.org/sayHi">
+					
+  <soap:Header>
+    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+      <wsse:UsernameToken>
+        <wsse:Username>esbuser</wsse:Username>
+        <wsse:Password>esbpassword</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+
+  <soap:Body>
+      <say:sayHi><say:HelloWorld>HelloWorld</say:HelloWorld></say:sayHi>"
+  </soap:Body>
+
+</soap:Envelope> 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SOAPTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SOAPTest.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SOAPTest.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -20,23 +20,25 @@
  */
 package org.jboss.soa.esb.samples.quickstart.publishAsWebservice.test;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.ConfigurationException;
 
 public class SOAPTest  {
-	public static void main(String args[]) {
+
+	public static void main(String args[]) throws ConfigurationException, UnsupportedEncodingException {
  
-		String request = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:say=\"http://www.jboss.org/sayHi\">"
-                                + "<soapenv:Header/> <soapenv:Body> <say:sayHi> <say:arg0>" + args[0] + "</say:arg0></say:sayHi>"
-                                + "</soapenv:Body> </soapenv:Envelope>";
+		final String soap = StreamUtils.getResourceAsString(args[0], "UTF-8");
 		HttpClient client = new HttpClient();
 		PostMethod postMethod = new PostMethod(
 				"http://127.0.0.1:8080/Quickstart_publish_as_webservice/ESBServiceSample/HelloWorldPubService?wsdl");
 
-		StringRequestEntity requestEntity = new StringRequestEntity(request);
+		StringRequestEntity requestEntity = new StringRequestEntity(soap);
 		postMethod.setRequestEntity(requestEntity);
 		try {
 			client.executeMethod(postMethod);

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SendEsbMessage.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SendEsbMessage.java	2008-08-20 11:26:07 UTC (rev 21640)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/publish_as_webservice/src/org/jboss/soa/esb/samples/quickstart/publishAsWebservice/test/SendEsbMessage.java	2008-08-20 13:05:59 UTC (rev 21641)
@@ -22,8 +22,14 @@
 
 package org.jboss.soa.esb.samples.quickstart.publishAsWebservice.test;
 
+import java.util.Set;
+import java.util.HashSet;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequestImpl;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.security.SecurityService;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.principals.User;
 import org.jboss.soa.esb.client.ServiceInvoker;
 import org.jboss.soa.esb.couriers.FaultMessageException;
 
@@ -32,6 +38,8 @@
  * <p/> arg0 - service category
  * <br/>arg1 - service name
  * <br/>arg2 - Text of message to send
+ * <br/>arg3 - username
+ * <br/>arg4 - password
  * 
  * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
  * @since Version 4.0
@@ -44,12 +52,18 @@
 //      Setting the ConnectionFactory such that it will use scout
         System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.ConnectionFactoryImpl");
         
-        if (args.length < 3)
+        if (args.length < 5)
         {
-            System.out.println("Usage SendEsbMessage <category> <name> <text to send>");
+            System.out.println("Usage SendEsbMessage <category> <name> <text to send> <username> <password>");
         }
+        Message esbMessage = MessageFactory.getInstance().getMessage();
         
-        Message esbMessage = MessageFactory.getInstance().getMessage();
+		//	create an AuthenticationRequest
+		AuthenticationRequest authRequest = new AuthenticationRequestImpl.Builder().username(args[3]).password(args[4].toCharArray()).bulid();
+		
+		// 	set the authentication request on the message
+		esbMessage.getProperties().setProperty( SecurityService.AUTH_REQUEST, authRequest );
+		
         final String message = "<say:sayHi xmlns:say=\"http://www.jboss.org/sayHi\"><say:arg0>" + args[2] + "</say:arg0></say:sayHi>" ;
         esbMessage.getBody().add(message);
         




More information about the jboss-svn-commits mailing list