[jboss-svn-commits] JBL Code SVN: r21424 - in labs/jbossesb/workspace/dbevenius/security/product: rosetta/src/org/jboss/soa/esb/services/security/auth and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 11 03:14:42 EDT 2008


Author: beve
Date: 2008-08-11 03:14:42 -0400 (Mon, 11 Aug 2008)
New Revision: 21424

Added:
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityToken.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/UsernameToken.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractor.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityTokenTest.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractorUnitTest.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/cert-example.xml
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-userpass-example.xml
Modified:
   labs/jbossesb/workspace/dbevenius/security/product/.classpath
   labs/jbossesb/workspace/dbevenius/security/product/ivy.xml
   labs/jbossesb/workspace/dbevenius/security/product/ivysettings.xml
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/build.xml
Log:
Added WSSecurityInfoExtractor. This uses Smooks to extract the security related informaiton from UsernameToken and BinarySecurityToken


Modified: labs/jbossesb/workspace/dbevenius/security/product/.classpath
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/.classpath	2008-08-11 05:36:19 UTC (rev 21423)
+++ labs/jbossesb/workspace/dbevenius/security/product/.classpath	2008-08-11 07:14:42 UTC (rev 21424)
@@ -105,5 +105,21 @@
 	<classpathentry kind="lib" path="ftp/lib/mina-filter-ssl-1.0.2.jar"/>
 	<classpathentry kind="lib" path="ftp/lib/slf4j-api-1.3.0.jar"/>
 	<classpathentry kind="lib" path="ftp/lib/slf4j-log4j12-1.3.0.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/antlr-2.7.2.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/freemarker-2.3.9.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/groovy-all-1.0.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/milyn-commons-1.0.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/milyn-smooks-core-1.0.1.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/milyn-smooks-javabean-1.0.1.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/mvel-1.3.3-java1.5.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/nekohtml-0.9.5.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/ognl-2.6.9.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/opencsv-1.8.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/stringtemplate-2.2.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/xalan-2.7.0.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/xbean-2.2.0.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/xml-apis-1.0.b2.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/xmlbeans-jsr173-api-2.0-dev.jar"/>
+	<classpathentry kind="lib" path="services/smooks/lib/ext/xpp3_min-1.1.3.4.O.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: labs/jbossesb/workspace/dbevenius/security/product/ivy.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/ivy.xml	2008-08-11 05:36:19 UTC (rev 21423)
+++ labs/jbossesb/workspace/dbevenius/security/product/ivy.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -60,5 +60,10 @@
         <dependency org="com.thoughtworks.xstream" name="xstream" rev="1.2.2"/>
         <dependency org="apache-bsf" name="bsf" rev="2.3.0"/>
         <dependency org="beanshell" name="bsh" rev="1.3.0"/>
+	
+		<!-- Smooks dependencies -->
+        <dependency org="milyn" name="milyn-smooks-core" 		rev="1.0.1"/>
+        <dependency org="milyn" name="milyn-commons" 			rev="1.0"/>
+        <dependency org="milyn" name="milyn-smooks-javabean" 	rev="1.0.1"/>
     </dependencies>
 </ivy-module>

Modified: labs/jbossesb/workspace/dbevenius/security/product/ivysettings.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/ivysettings.xml	2008-08-11 05:36:19 UTC (rev 21423)
+++ labs/jbossesb/workspace/dbevenius/security/product/ivysettings.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -6,6 +6,9 @@
                 <artifact pattern="http://repository.jboss.org/maven2/[organisation]/[artifact]/[revision]/[artifact]-[revision].[ext]"/>
             </url>
             <ibiblio name="ibiblio" m2compatible="true" />
+            <url name="milyn" m2compatible="true">
+                <artifact pattern="http://dist.codehaus.org/[organisation]/[artifact]/[revision]/[artifact]-[revision].[ext]"/>
+            </url>
         </chain>
     </resolvers>
-</ivysettings>
\ No newline at end of file
+</ivysettings>

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityToken.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityToken.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityToken.java	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,134 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.IOException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+
+import sun.misc.BASE64Decoder;
+
+/**
+ * Represents a WS-Security BinarySecurityToken.
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class BinarySecurityToken
+{
+	private String encodingType;
+	private String valueType;
+	private Certificate cert;
+	
+	public String getEncodingType()
+	{
+		return encodingType;
+	}
+	
+	public void setEncodingType(String encodingType)
+	{
+		this.encodingType = stripNSAlias(encodingType);
+	}
+	
+	public String getValueType()
+	{
+		return valueType;
+	}
+	
+	public void setValueType(String valueType)
+	{
+		this.valueType = stripNSAlias(valueType);
+	}
+	
+	public Certificate getKey()
+	{
+		return cert;
+	}
+	
+	private String stripNSAlias(String value)
+	{
+		if ( value != null )
+		{
+			value = value.substring( value.indexOf(':') + 1 );
+		}
+		return value;
+	}
+	
+	private enum EncodingType { Base64Binary, HexBinary }
+	private enum ValueType 
+	{ 
+		X509v3( "X509" ), 
+		Kerberosv5TGT( "" ), 
+		Kerberosv5ST ( "" );
+		
+		private String certType;
+		
+		private ValueType(final String certType )
+		{
+			this.certType = certType;
+		}
+		
+		public String getCertType()
+		{
+			return certType;
+		}
+	}
+	
+	public void setKey(final String key)
+	{
+		try
+		{
+			byte[] keyBytes = null;
+			if ( encodingType.equalsIgnoreCase( EncodingType.Base64Binary.toString() ) )
+			{
+    			BASE64Decoder decoder = new BASE64Decoder();
+    			keyBytes = decoder.decodeBuffer(key);
+			}
+			else
+			{
+				keyBytes = key.getBytes();
+			}
+				
+			CertificateFactory factory = CertificateFactory.getInstance( certificateMatch( valueType ) );
+			cert = factory.generateCertificate( new ByteArrayInputStream( keyBytes ));
+		} 
+		catch (CertificateException e)
+		{
+			throw new IllegalStateException("Could not create certificate: ", e);
+		} 
+		catch (IOException e)
+		{
+			throw new IllegalStateException("Could not create certificate: ", e);
+		} 
+	}
+	
+	private String certificateMatch(final String valueType)
+	{
+		if ( valueType.startsWith("X509") )
+			return "X.509";
+		
+		return valueType;
+	}
+	
+}

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/UsernameToken.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/UsernameToken.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/UsernameToken.java	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+/**
+ * Placeholder for security information form a ws request.
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class UsernameToken
+{
+	private String userName;
+	private char[] password;
+	
+	public char[] getPassword()
+	{
+		return password;
+	}
+	
+	public void setPassword(String password)
+	{
+		this.password = password.toCharArray();
+	}
+	
+	public String getUserName()
+	{
+		return userName;
+	}
+	
+	public void setUserName(String userName)
+	{
+		this.userName = userName;
+	}
+	
+
+}

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractor.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractor.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractor.java	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,85 @@
+/*
+ * 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.IOException;
+import java.io.StringReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.transform.stream.StreamSource;
+
+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.jboss.soa.esb.util.ClassUtil;
+import org.milyn.Smooks;
+import org.milyn.payload.JavaResult;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class WSSecurityInfoExtractor implements SecurityInfoExtractor<String>
+{
+	private Smooks smooks;
+	
+	public WSSecurityInfoExtractor() throws IOException, SAXException
+	{
+		createSmooks("smooks-config.xml");
+	}
+
+	public WSSecurityInfoExtractor(final String configFile) throws IOException, SAXException
+	{
+		createSmooks(configFile);
+	}
+	
+	public AuthenticationRequest extractSecurityInfo(final String soap)
+	{
+		final JavaResult javaResult = new JavaResult();
+		smooks.filter(new StreamSource(new StringReader(soap)), javaResult);
+		
+		UsernameToken token = (UsernameToken) javaResult.getBean("userNameToken");
+		User user = null;
+		Set<Object> credentials = new HashSet<Object>();
+		if ( token != null )
+		{
+    		user = new User(token.getUserName());
+        	credentials.add(token.getPassword());
+		}
+		
+		BinarySecurityToken binaryToken = (BinarySecurityToken) javaResult.getBean("binarySecurityToken");
+		if ( binaryToken != null )
+		{
+    		credentials.add(binaryToken.getKey());
+		}
+		return new AuthenticationRequestImpl.Builder(user, credentials ).bulid();
+	}
+
+	private void createSmooks(final String configFile) throws IOException, SAXException
+	{
+		this.smooks = new Smooks( ClassUtil.getResourceAsStream(configFile, getClass()));
+	}
+	
+}

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
+
+    <resource-config selector="Envelope/Header/Security/UsernameToken">
+        <resource>org.milyn.javabean.BeanPopulator</resource>
+        <param name="beanId">userNameToken</param>
+        <param name="beanClass">org.jboss.soa.esb.services.security.auth.ws.UsernameToken</param>
+        <param name="bindings">
+            <binding property="userName" selector="Username" default="" />
+            <binding property="password" selector="Password" />
+        </param>
+    </resource-config>
+    
+    <resource-config selector="Envelope/Header/Security/BinarySecurityToken">
+        <resource>org.milyn.javabean.BeanPopulator</resource>
+        <param name="beanId">binarySecurityToken</param>
+        <param name="beanClass">org.jboss.soa.esb.services.security.auth.ws.BinarySecurityToken</param>
+        <param name="bindings">
+            <binding property="encodingType" selector="BinarySecurityToken @EncodingType" />
+            <binding property="valueType" selector="BinarySecurityToken @ValueType" />
+            <binding property="key" selector="BinarySecurityToken" />
+        </param>
+    </resource-config>
+
+</smooks-resource-list>

Modified: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/build.xml	2008-08-11 05:36:19 UTC (rev 21423)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/build.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -102,6 +102,10 @@
         <copy todir="${org.jboss.esb.test.persistdb.dir}">
             <fileset dir="resources/etc/" includes="persistUnitTestDB*"/>
         </copy>
+		<copy todir="${org.jboss.esb.tests.classes.dir}" >
+            <fileset dir="${org.jboss.esb.module.tests.src.dir}" includes="**/*.xml" />
+        </copy>
+
 		<copy file="${org.jboss.esb.root.dir}/etc/schemas/xml/jbossesb-1.0.1.xsd" todir="${org.jboss.esb.tests.classes.dir}"/>
 
 

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityTokenTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityTokenTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/BinarySecurityTokenTest.java	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,90 @@
+/*
+ * 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.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import junit.framework.JUnit4TestAdapter;
+
+/**
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class BinarySecurityTokenTest
+{
+	private String expectedEncoding = "Base64Binary";
+	private String expectedValueType = "X509v3";
+	private BinarySecurityToken token = new BinarySecurityToken();
+	
+	@Test
+	public void setEncodingTypeWithNSPrefix()
+	{
+		token.setEncodingType("wsse:" + expectedEncoding);
+		assertEquals( expectedEncoding, token.getEncodingType() );
+	}
+	
+	@Test
+	public void setEncodingType()
+	{
+		token.setEncodingType(expectedEncoding);
+		assertEquals( expectedEncoding, token.getEncodingType() );
+	}
+	
+	@Test
+	public void setEncodingTypeNull()
+	{
+		token.setEncodingType(null);
+		assertNull(token.getEncodingType());
+	}
+	
+	@Test
+	public void setKey() throws ConfigurationException, SAXException, IOException, ParserConfigurationException
+	{
+		token.setEncodingType(expectedEncoding);
+		token.setValueType(expectedValueType);
+		token.setKey(getExampleCert());
+		System.out.println(token.getKey());
+	}
+	
+	private String getExampleCert() throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		InputStream inputStream = ClassUtil.getResourceAsStream("cert-example.xml", getClass() );
+		return new String(StreamUtils.readStream(inputStream));
+	}
+
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter(BinarySecurityTokenTest.class);
+	}
+
+}

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractorUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractorUnitTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/WSSecurityInfoExtractorUnitTest.java	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,90 @@
+/*
+ * 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.io.InputStream;
+import javax.xml.parsers.ParserConfigurationException;
+import junit.framework.JUnit4TestAdapter;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Unit test for {@link WSSecurityInfoExtractor}
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class WSSecurityInfoExtractorUnitTest
+{
+	@Test
+	public void extractUserPassSecurityInfo() throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		WSSecurityInfoExtractor extractor = new WSSecurityInfoExtractor();
+		String soap = createUserPassSoapString();
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		assertNotNull(authRequest);
+		assertEquals( "Clark", authRequest.getPrincipal().getName());
+	}
+	
+	@Test
+	public void extractKeySecurityInfo() throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		WSSecurityInfoExtractor extractor = new WSSecurityInfoExtractor();
+		String soap = createKeySoapString();
+		AuthenticationRequest authRequest = extractor.extractSecurityInfo(soap);
+		assertNotNull(authRequest);
+		assertTrue( authRequest.getCredentials().size() > 0 );
+		Object cert = authRequest.getCredentials().iterator().next();
+		assertTrue( cert instanceof java.security.cert.X509Certificate);
+	}
+	
+	private String createUserPassSoapString() throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		return getStringFromFile("soap-userpass-example.xml");
+	}
+	
+	private String createKeySoapString() throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		return getStringFromFile("soap-keys-example.xml");
+	}
+	
+	private String getStringFromFile(final String fileName ) throws SAXException, IOException, ParserConfigurationException, ConfigurationException
+	{
+		InputStream inputStream = ClassUtil.getResourceAsStream(fileName, getClass() );
+		return new String(StreamUtils.readStream(inputStream));
+	}
+
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter(WSSecurityInfoExtractorUnitTest.class);
+	}
+
+}

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/cert-example.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/cert-example.xml	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/cert-example.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -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/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/smooks-config.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
+
+    <resource-config selector="Envelope/Header/Security/UsernameToken">
+        <resource>org.milyn.javabean.BeanPopulator</resource>
+        <param name="beanId">userNameToken</param>
+        <param name="beanClass">org.jboss.soa.esb.services.security.auth.ws.UsernameToken</param>
+        <param name="bindings">
+            <binding property="userName" selector="Username" default="" />
+            <binding property="password" selector="Password" />
+        </param>
+    </resource-config>
+    
+    <resource-config selector="Envelope/Header/Security/BinarySecurityToken">
+        <resource>org.milyn.javabean.BeanPopulator</resource>
+        <param name="beanId">binarySecurityToken</param>
+        <param name="beanClass">org.jboss.soa.esb.services.security.auth.ws.BinarySecurityToken</param>
+        <param name="bindings">
+            <binding property="encodingType" selector="BinarySecurityToken @EncodingType" />
+            <binding property="valueType" selector="BinarySecurityToken @ValueType" />
+            <binding property="key" selector="BinarySecurityToken" />
+        </param>
+    </resource-config>
+
+</smooks-resource-list>

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-keys-example.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,22 @@
+<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">MIICQjCCAasCBEif0tUwDQYJKoZIhvcNAQEEBQAwaDELMAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0
+b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYDVQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVK
+Qm9zczEPMA0GA1UEAxMGRGFuaWVsMB4XDTA4MDgxMTA1NDkwOVoXDTA4MTEwOTA1NDkwOVowaDEL
+MAkGA1UEBhMCU0UxEjAQBgNVBAgTCVN0b2NraG9sbTESMBAGA1UEBxMJU3RvY2tob2xtMRAwDgYD
+VQQKEwdSZWQgSGF0MQ4wDAYDVQQLEwVKQm9zczEPMA0GA1UEAxMGRGFuaWVsMIGfMA0GCSqGSIb3
+DQEBAQUAA4GNADCBiQKBgQCdSh96Xyt4LeZbXz9pk4eaHrj2sGFmI9lkLQiW/DbF9ETXFvWYCS4N
+lsONmPx63KSbzJZQZRlJSAW2y6hQO18G9NMFQpn2W/jtPSw61kH3dXDQ+kZ2UMk9K93nt4XLvGm6
+dMQAGZAjzpz4lzhcYrDJI4NMw5LpeljDawkradtuiwIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAHi2
+S1zC8jIqncSeMRwOvPOEQIcsZJELYFUCiTwPrAg5hNkp/oewm6uCkgqmry09+3+ZXg2KLQ+RgeuV
+8yfeBvk7TFjtOWeHWnBOaxKiAyLibxGchVfMPl847MZ2w4d6vu776cqb1NKghAE53dn9AzUHIWwx
+OizXyDaDiBMj5xgs</wsse:BinarySecurityToken>
+        </wsse:Security>
+    </soap:Header>
+    <soap:Body>
+    </soap:Body>
+</soap:Envelope> 
+

Added: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-userpass-example.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-userpass-example.xml	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap-userpass-example.xml	2008-08-11 07:14:42 UTC (rev 21424)
@@ -0,0 +1,18 @@
+<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:UsernameToken>
+        <wsse:Username>Clark</wsse:Username>
+        <wsse:Password>griswald</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soap:Header>
+
+  <soap:Body>
+  </soap:Body>
+
+</soap:Envelope> 
+




More information about the jboss-svn-commits mailing list