[jboss-svn-commits] JBossWS SVN: r786 - in trunk/src: main/java/org/jboss/ws/wsse test/ant test/java/org/jboss/test/ws/samples/wssecurity test/java/org/jboss/test/ws/wsse test/resources/samples/wssecurity test/resources/samples/wssecurity/store-pass-encrypt test/resources/samples/wssecurity/store-pass-encrypt/META-INF test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF test/resources/wsse test/resources/wsse/store-pass-encrypt-class-cmd
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Aug 19 03:59:43 EDT 2006
Author: mageshbk
Date: 2006-08-19 03:59:15 -0400 (Sat, 19 Aug 2006)
New Revision: 786
Added:
trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
trunk/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
trunk/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
trunk/src/test/resources/samples/wssecurity/keystore.password
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/
trunk/src/test/resources/wsse/keystore.password
trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd/
Removed:
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/
Modified:
trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java
trunk/src/test/ant/build-jars.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/application-client.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/jboss-client.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/jboss-wsse-client.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/jboss-web.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/web.xml
trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/jboss-wsse-server.xml
trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd/jboss-wsse-client.xml
trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd/jboss-wsse-server.xml
Log:
Updated SecurityStore to accept encrypted password using {EXT} and {CLASS} methods and Added test case to test updated SecurityStore using {EXT} and {CLASS} methods
Modified: trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java 2006-08-19 07:59:15 UTC (rev 786)
@@ -21,9 +21,13 @@
*/
package org.jboss.ws.wsse;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
import java.net.URL;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
@@ -40,9 +44,17 @@
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
+import java.util.StringTokenizer;
import org.jboss.logging.Logger;
+/**
+ * <code>SecurityStore</code> holds and loads the keystore and truststore required for encyption and signing.
+ *
+ * @author <a href="mailto:jason.greene at jboss.com">Jason T. Greene</a>
+ * @author <a href="mailto:jason.greene at jboss.com">Magesh Kumar B</a>
+ * @version $Revision$
+ */
public class SecurityStore
{
private static Logger log = Logger.getLogger(SecurityStore.class);
@@ -97,6 +109,25 @@
if (storeType == null)
storeType = "jks";
+ if( storePassword.charAt(0) == '{' )
+ {
+ StringTokenizer tokenizer = new StringTokenizer(storePassword, "{}");
+ String keyStorePasswordCmdType = tokenizer.nextToken();
+ String keyStorePasswordCmd = tokenizer.nextToken();
+ if( keyStorePasswordCmdType.equals("EXT") )
+ {
+ storePassword = execPasswordCmd(keyStorePasswordCmd);
+ }
+ else if( keyStorePasswordCmdType.equals("CLASS") )
+ {
+ storePassword = invokePasswordClass(keyStorePasswordCmd);
+ }
+ else
+ {
+ throw new WSSecurityException("Unknown keyStorePasswordCmdType: "+keyStorePasswordCmdType);
+ }
+ }
+ keyStorePassword = storePassword;
try
{
if (storeURL == null)
@@ -112,7 +143,7 @@
log.debug("loadStore: " + storeURL);
InputStream stream = storeURL.openStream();
KeyStore keyStore = KeyStore.getInstance(storeType);
- keyStore.load(stream, storePassword.toCharArray());
+ keyStore.load(stream, keyStorePassword.toCharArray());
return keyStore;
}
@@ -121,6 +152,75 @@
throw new WSSecurityException("Problems loading " + type + ": " + e.getMessage(), e);
}
}
+ private String execPasswordCmd(String keyStorePasswordCmd) throws WSSecurityException
+ {
+ log.debug("Executing command: "+keyStorePasswordCmd);
+ try
+ {
+ Runtime rt = Runtime.getRuntime();
+ Process p = rt.exec(keyStorePasswordCmd);
+ InputStream stdin = p.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stdin));
+ String password = reader.readLine();
+ stdin.close();
+ int exitCode = p.waitFor();
+ log.debug("Command exited with: "+exitCode);
+ return password;
+ }
+ catch (Exception e)
+ {
+ throw new WSSecurityException("Problems executing password command: " + keyStorePasswordCmd, e);
+ }
+ }
+ private String invokePasswordClass(String keyStorePasswordCmd) throws WSSecurityException
+ {
+ String password = null;
+ String classname = keyStorePasswordCmd;
+ String ctorArg = null;
+ int colon = keyStorePasswordCmd.indexOf(':');
+ if( colon > 0 )
+ {
+ classname = keyStorePasswordCmd.substring(0, colon);
+ ctorArg = keyStorePasswordCmd.substring(colon+1);
+ }
+ log.debug("Loading class: "+classname+", ctorArg="+ctorArg);
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class c = loader.loadClass(classname);
+ Object instance = null;
+ if( ctorArg != null )
+ {
+ Class[] sig = {String.class};
+ Constructor ctor = c.getConstructor(sig);
+ Object[] args = {ctorArg};
+ instance = ctor.newInstance(args);
+ }
+ else
+ {
+ instance = c.newInstance();
+ }
+ try
+ {
+ log.debug("Checking for toCharArray");
+ Class[] sig = {};
+ Method toCharArray = c.getMethod("toCharArray", sig);
+ Object[] args = {};
+ log.debug("Invoking toCharArray");
+ password = new String((char[]) toCharArray.invoke(instance, args));
+ }
+ catch(NoSuchMethodException e)
+ {
+ log.debug("No toCharArray found, invoking toString");
+ password = instance.toString();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WSSecurityException("Problems loading or invoking Password class : " + classname, e);
+ }
+ return password;
+ }
public static byte[] getSubjectKeyIdentifier(X509Certificate cert)
{
Modified: trunk/src/test/ant/build-jars.xml
===================================================================
--- trunk/src/test/ant/build-jars.xml 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/test/ant/build-jars.xml 2006-08-19 07:59:15 UTC (rev 786)
@@ -1693,6 +1693,47 @@
</metainf>
</jar>
+ <!-- jbossws-samples-store-pass-encrypt.war -->
+ <replace file="${build.test.dir}/resources/samples/wssecurity/store-pass-encrypt/jboss-wsse-server.xml" token="${buildpath}" value="${build.test.dir}"/>
+ <war warfile="${build.test.dir}/libs/jbossws-samples-store-pass-encrypt.war" webxml="${build.test.dir}/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/web.xml">
+ <classes dir="${build.test.dir}/classes">
+ <include name="org/jboss/test/ws/samples/wssecurity/Hello.class"/>
+ <include name="org/jboss/test/ws/samples/wssecurity/HelloJavaBean.class"/>
+ <include name="org/jboss/test/ws/samples/wssecurity/PasswordUtil.class"/>
+ <include name="org/jboss/test/ws/samples/wssecurity/UserType.class"/>
+ </classes>
+ <webinf dir="${build.test.dir}/resources/samples/wssecurity/WEB-INF">
+ <include name="jaxrpc-mapping.xml"/>
+ <include name="webservices.xml"/>
+ <include name="wsdl/**"/>
+ </webinf>
+ <webinf dir="${build.test.dir}/resources/samples/wssecurity/store-pass-encrypt">
+ <include name="jboss-wsse-server.xml"/>
+ </webinf>
+ <webinf dir="${build.test.dir}/resources/samples/wssecurity/store-pass-encrypt/WEB-INF">
+ <include name="jboss-web.xml"/>
+ </webinf>
+ <webinf dir="${build.test.dir}/resources/samples/wssecurity">
+ <include name="wsse.keystore"/>
+ <include name="wsse.truststore"/>
+ </webinf>
+ </war>
+ <jar jarfile="${build.test.dir}/libs/jbossws-samples-store-pass-encrypt-client.jar">
+ <fileset dir="${build.test.dir}/classes">
+ <include name="org/jboss/test/ws/samples/wssecurity/Hello.class"/>
+ <include name="org/jboss/test/ws/samples/wssecurity/UserType.class"/>
+ </fileset>
+ <metainf dir="${build.test.dir}/resources/samples/wssecurity/store-pass-encrypt/META-INF">
+ <include name="application-client.xml"/>
+ <include name="jboss-client.xml"/>
+ <include name="jboss-wsse-client.xml"/>
+ </metainf>
+ <metainf dir="${build.test.dir}/resources/samples/wssecurity/WEB-INF">
+ <include name="wsdl/**"/>
+ <include name="jaxrpc-mapping.xml"/>
+ </metainf>
+ </jar>
+
<!-- jbossws-wsse-account-signup.war -->
<war warfile="${build.test.dir}/libs/jbossws-wsse-account-signup.war" webxml="${build.test.dir}/resources/wsse/account-signup/WEB-INF/web.xml">
<classes dir="${build.test.dir}/classes">
@@ -1854,6 +1895,49 @@
</metainf>
</jar>
+ <!-- jbossws-wsse-store-pass-encrypt-class-cmd.war -->
+ <replace file="${build.test.dir}/resources/wsse/store-pass-encrypt-class-cmd/jboss-wsse-server.xml" token="${buildpath}" value="${build.test.dir}"/>
+ <war warfile="${build.test.dir}/libs/jbossws-wsse-store-pass-encrypt-class-cmd.war" webxml="${build.test.dir}/resources/wsse/rpc/WEB-INF/web.xml">
+ <classes dir="${build.test.dir}/classes">
+ <include name="org/jboss/test/ws/wsse/Hello.class"/>
+ <include name="org/jboss/test/ws/wsse/HelloJavaBean.class"/>
+ <include name="org/jboss/test/ws/wsse/PasswordUtil.class"/>
+ <include name="org/jboss/test/ws/wsse/UserType.class"/>
+ </classes>
+ <webinf dir="${build.test.dir}/resources/wsse/rpc/WEB-INF">
+ <include name="jaxrpc-mapping.xml"/>
+ <include name="jboss-web.xml"/>
+ <include name="webservices.xml"/>
+ <include name="wsdl/**"/>
+ </webinf>
+ <webinf dir="${build.test.dir}/resources/wsse/store-pass-encrypt-class-cmd">
+ <include name="jboss-wsse-server.xml"/>
+ </webinf>
+ <webinf dir="${build.test.dir}/resources/wsse">
+ <include name="wsse.keystore"/>
+ <include name="wsse.truststore"/>
+ </webinf>
+ </war>
+
+ <!-- jboss-wsse-store-pass-encrypt-class-cmd-client.jar -->
+ <jar jarfile="${build.test.dir}/libs/jbossws-wsse-store-pass-encrypt-class-cmd-client.jar">
+ <fileset dir="${build.test.dir}/classes">
+ <include name="org/jboss/test/ws/wsse/Hello.class"/>
+ <include name="org/jboss/test/ws/wsse/UserType.class"/>
+ </fileset>
+ <metainf dir="${build.test.dir}/resources/wsse/rpc/META-INF">
+ <include name="application-client.xml"/>
+ <include name="jboss-client.xml"/>
+ </metainf>
+ <metainf dir="${build.test.dir}/resources/wsse/store-pass-encrypt-class-cmd">
+ <include name="jboss-wsse-client.xml"/>
+ </metainf>
+ <metainf dir="${build.test.dir}/resources/wsse/rpc/WEB-INF">
+ <include name="wsdl/**"/>
+ <include name="jaxrpc-mapping.xml"/>
+ </metainf>
+ </jar>
+
<!-- jbossws-wsse-web-client.war -->
<war warfile="${build.test.dir}/libs/jbossws-wsse-web-client.war" webxml="${build.test.dir}/resources/wsse/webclient/WEB-INF/web.xml">
<classes dir="${build.test.dir}/classes">
Added: trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java 2006-08-19 07:59:15 UTC (rev 786)
@@ -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: trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/PasswordUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java 2006-08-19 07:59:15 UTC (rev 786)
@@ -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: trunk/src/test/java/org/jboss/test/ws/samples/wssecurity/StorePassEncryptTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java 2006-08-19 07:59:15 UTC (rev 786)
@@ -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: trunk/src/test/java/org/jboss/test/ws/wsse/PasswordUtil.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
===================================================================
--- trunk/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java 2006-08-19 07:11:24 UTC (rev 785)
+++ trunk/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java 2006-08-19 07:59:15 UTC (rev 786)
@@ -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: trunk/src/test/java/org/jboss/test/ws/wsse/StorePassEncryptTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/src/test/resources/samples/wssecurity/keystore.password
===================================================================
(Binary files differ)
Property changes on: trunk/src/test/resources/samples/wssecurity/keystore.password
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Copied: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt (from rev 785, branches/jbossws-1.0/src/test/resources/samples/wssecurity/store-pass-encrypt)
Copied: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF (from rev 785, branches/jbossws-1.0/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF)
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/application-client.xml
===================================================================
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/jboss-client.xml
===================================================================
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/META-INF/jboss-wsse-client.xml
===================================================================
Copied: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF (from rev 785, branches/jbossws-1.0/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF)
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/jboss-web.xml
===================================================================
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/WEB-INF/web.xml
===================================================================
Modified: trunk/src/test/resources/samples/wssecurity/store-pass-encrypt/jboss-wsse-server.xml
===================================================================
Added: trunk/src/test/resources/wsse/keystore.password
===================================================================
(Binary files differ)
Property changes on: trunk/src/test/resources/wsse/keystore.password
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Copied: trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd (from rev 785, branches/jbossws-1.0/src/test/resources/wsse/store-pass-encrypt-class-cmd)
Modified: trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd/jboss-wsse-client.xml
===================================================================
Modified: trunk/src/test/resources/wsse/store-pass-encrypt-class-cmd/jboss-wsse-server.xml
===================================================================
More information about the jboss-svn-commits
mailing list