[jboss-svn-commits] JBossWS SVN: r783 - in branches/jbossws-1.0/src/test/java/org/jboss/test/ws: samples/wssecurity wsse

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Aug 19 03:07:02 EDT 2006


Author: mageshbk
Date: 2006-08-19 03:06:54 -0400 (Sat, 19 Aug 2006)
New Revision: 783

Added:
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
Log:
Added test case to test updated SecurityStore using {EXT} and {CLASS} methods

Added: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java	2006-08-19 07:05:06 UTC (rev 782)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java	2006-08-19 07:06:54 UTC (rev 783)
@@ -0,0 +1,83 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.ws.samples.wssecurity;
+
+import java.io.RandomAccessFile;
+import java.io.ByteArrayOutputStream;
+
+import javax.crypto.spec.PBEParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.Cipher;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.SecretKey;
+
+/**
+ * This is a simple decode utility for using along with the jboss-ws-security keystore and truststore use cases
+ *
+ * @author <a href="mailto:magesh.bojan at jboss.com">Magesh Kumar B</a>
+ * @version $Revision$
+ */
+public class PasswordUtil
+{
+   public static void main(String args[])
+   {
+     if( args.length != 1 )
+      {
+         System.err.println(
+            "Read a password file and decode into plain text"
+           +"Usage: PasswordUtil password-file"
+           +"  password-file : the path to the file to write the password to"
+         );
+      }
+      try
+      {
+         System.out.println(decode(args[0]));
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   private static char[] decode(String passwordFilePath) throws Exception
+   {
+      RandomAccessFile passwordFile = new RandomAccessFile(passwordFilePath, "rws");
+      byte[] salt = new byte[8];
+      passwordFile.readFully(salt);
+      int count = passwordFile.readInt();
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      int b;
+      while( (b = passwordFile.read()) >= 0 )
+         baos.write(b);
+      passwordFile.close();
+      byte[] secret = baos.toByteArray();
+
+      PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count);
+      PBEKeySpec keySpec = new PBEKeySpec("78aac249a60a13d5e882927928043ebb".toCharArray());
+      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
+      SecretKey cipherKey = factory.generateSecret(keySpec);
+      Cipher cipher = Cipher.getInstance("PBEwithMD5andDES");
+      cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
+      byte[] decode = cipher.doFinal(secret);
+      return new String(decode, "UTF-8").toCharArray();
+   }
+}


Property changes on: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java	2006-08-19 07:05:06 UTC (rev 782)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java	2006-08-19 07:06:54 UTC (rev 783)
@@ -0,0 +1,112 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.ws.samples.wssecurity;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.Stub;
+import javax.xml.rpc.handler.HandlerInfo;
+import javax.xml.rpc.handler.HandlerRegistry;
+
+import junit.framework.Test;
+
+import org.jboss.test.ws.JBossWSTest;
+import org.jboss.test.ws.JBossWSTestSetup;
+import org.jboss.ws.jaxrpc.ServiceFactoryImpl;
+import org.jboss.ws.jaxrpc.ServiceImpl;
+import org.jboss.ws.wsse.WSSecurityHandlerOutbound;
+
+/**
+ * This test simulates simulates the usage of a jboss-ws-security keystore and truststore use cases
+ *
+ * @author <a href="mailto:magesh.bojan at jboss.com">Magesh Kumar B</a>
+ * @version $Revision$
+ */
+public class StorePassEncryptTestCase extends JBossWSTest
+{
+   /** Construct the test case with a given name
+    */
+
+   /** Deploy the test */
+   public static Test suite() throws Exception
+   {
+      return JBossWSTestSetup.newTestSetup(StorePassEncryptTestCase.class, "jbossws-samples-store-pass-encrypt.war, jbossws-samples-store-pass-encrypt-client.jar");
+   }
+
+   /**
+    * Test JSE endpoint
+    */
+   public void testEndpoint() throws Exception
+   {
+      Hello hello = getPort();
+
+      UserType in0 = new UserType("Kermit");
+      UserType retObj = hello.echoUserType(in0);
+      assertEquals(in0, retObj);
+   }
+
+   private Hello getPort() throws Exception
+   {
+      if (isTargetServerJBoss())
+      {
+         InitialContext iniCtx = getInitialContext();
+         Service service = (Service)iniCtx.lookup("java:comp/env/service/HelloService");
+         Hello port = (Hello)service.getPort(Hello.class);
+         return port;
+      }
+      else
+      {
+         try
+         {
+            ServiceFactoryImpl factory = new ServiceFactoryImpl();
+            URL wsdlURL = new File("resources/samples/wssecurity/WEB-INF/wsdl/HelloService.wsdl").toURL();
+            URL mappingURL = new File("resources/samples/wssecurity/WEB-INF/jaxrpc-mapping.xml").toURL();
+            URL securityURL = new File("resources/samples/wssecurity/store-pass-encrypt/META-INF/jboss-wsse-client.xml").toURL();
+
+            QName serviceName = new QName("http://org.jboss.ws/samples/wssecurity", "HelloService");
+            QName portName = new QName("http://org.jboss.ws/samples/wssecurity", "HelloPort");
+            ServiceImpl service = (ServiceImpl)factory.createService(wsdlURL, serviceName, mappingURL, securityURL);
+
+            HandlerRegistry registry = service.getDynamicHandlerRegistry();
+            List infos = registry.getHandlerChain(portName);
+            infos.add(new HandlerInfo(WSSecurityHandlerOutbound.class, new HashMap(), new QName[]{}));
+            registry.setHandlerChain(portName, infos);
+
+            Hello port = (Hello)service.getPort(Hello.class);
+            ((Stub)port)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://" + getServerHost() + ":8080/jbossws-samples-store-pass-encrypt");
+            return port;
+         }
+         catch (Exception e)
+         {
+            System.out.println("Exception is : " + e);
+            e.printStackTrace();
+            throw e;
+         }
+      }
+   }
+}


Property changes on: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java	2006-08-19 07:05:06 UTC (rev 782)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java	2006-08-19 07:06:54 UTC (rev 783)
@@ -0,0 +1,83 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.ws.wsse;
+
+import java.io.RandomAccessFile;
+import java.io.ByteArrayOutputStream;
+
+import javax.crypto.spec.PBEParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.Cipher;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.SecretKey;
+
+/**
+ * This is a simple decode utility for using along with the jboss-ws-security keystore and truststore use cases
+ *
+ * @author <a href="mailto:magesh.bojan at jboss.com">Magesh Kumar B</a>
+ * @version $Revision$
+ */
+public class PasswordUtil
+{
+   public static void main(String args[])
+   {
+     if( args.length != 1 )
+      {
+         System.err.println(
+            "Read a password in plain text form from a password file"
+           +"Usage: PasswordUtil password-file"
+           +"  password-file : the path to the file to write the password to"
+         );
+      }
+      try
+      {
+         System.out.println(decode(args[0]));
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   private static char[] decode(String passwordFilePath) throws Exception
+   {
+      RandomAccessFile passwordFile = new RandomAccessFile(passwordFilePath, "rws");
+      byte[] salt = new byte[8];
+      passwordFile.readFully(salt);
+      int count = passwordFile.readInt();
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      int b;
+      while( (b = passwordFile.read()) >= 0 )
+         baos.write(b);
+      passwordFile.close();
+      byte[] secret = baos.toByteArray();
+
+      PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count);
+      PBEKeySpec keySpec = new PBEKeySpec("78aac249a60a13d5e882927928043ebb".toCharArray());
+      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
+      SecretKey cipherKey = factory.generateSecret(keySpec);
+      Cipher cipher = Cipher.getInstance("PBEwithMD5andDES");
+      cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
+      byte[] decode = cipher.doFinal(secret);
+      return new String(decode, "UTF-8").toCharArray();
+   }
+}


Property changes on: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java	2006-08-19 07:05:06 UTC (rev 782)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java	2006-08-19 07:06:54 UTC (rev 783)
@@ -0,0 +1,62 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.ws.wsse;
+
+import javax.naming.InitialContext;
+import javax.xml.rpc.Service;
+
+import junit.framework.Test;
+
+import org.jboss.test.ws.JBossWSTest;
+import org.jboss.test.ws.JBossWSTestSetup;
+
+/**
+ * This test simulates simulates the usage of a jboss-ws-security keystore and truststore use cases
+ *
+ * @author <a href="mailto:magesh.bojan at jboss.com">Magesh Kumar B</a>
+ * @version $Revision$
+ */
+public class StorePassEncryptTestCase extends JBossWSTest
+{
+   /** Construct the test case with a given name
+    */
+
+   /** Deploy the test */
+   public static Test suite() throws Exception
+   {
+      return JBossWSTestSetup.newTestSetup(StorePassEncryptTestCase.class, "jbossws-wsse-store-pass-encrypt-class-cmd.war, jbossws-wsse-store-pass-encrypt-class-cmd-client.jar");
+   }
+
+   /**
+    * Test JSE endpoint
+    */
+   public void testEndpoint() throws Exception
+   {
+      InitialContext iniCtx = getInitialContext();
+      Service service = (Service)iniCtx.lookup("java:comp/env/service/HelloService");
+      Hello hello = (Hello)service.getPort(Hello.class);
+
+      UserType in0 = new UserType("Kermit");
+      UserType retObj = hello.echoUserType(in0);
+      assertEquals(in0, retObj);
+   }
+}


Property changes on: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-svn-commits mailing list