[jboss-svn-commits] JBossWS SVN: r797 - trunk/src/main/java/org/jboss/ws/wsse
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Aug 20 16:41:54 EDT 2006
Author: darran.lofthouse at jboss.com
Date: 2006-08-20 16:41:52 -0400 (Sun, 20 Aug 2006)
New Revision: 797
Modified:
trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java
Log:
JBWS-1097 - Remerged changes and remove redeuntant URL creation.
Modified: trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java 2006-08-20 20:34:34 UTC (rev 796)
+++ trunk/src/main/java/org/jboss/ws/wsse/SecurityStore.java 2006-08-20 20:41:52 UTC (rev 797)
@@ -1,24 +1,24 @@
/*
-* 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.
-*/
+ * 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.ws.wsse;
import java.io.BufferedReader;
@@ -69,7 +69,7 @@
public SecurityStore() throws WSSecurityException
{
- this (null, null, null, null, null, null);
+ this(null, null, null, null, null, null);
}
public SecurityStore(URL keyStoreURL, String keyStoreType, String keyStorePassword) throws WSSecurityException
@@ -78,7 +78,8 @@
loadTrustStore(keyStoreURL, keyStoreType, keyStorePassword);
}
- public SecurityStore(URL keyStoreURL, String keyStoreType, String keyStorePassword, URL trustStoreURL, String trustStoreType, String trustStorePassword) throws WSSecurityException
+ public SecurityStore(URL keyStoreURL, String keyStoreType, String keyStorePassword, URL trustStoreURL, String trustStoreType, String trustStorePassword)
+ throws WSSecurityException
{
loadKeyStore(keyStoreURL, keyStoreType, keyStorePassword);
loadTrustStore(trustStoreURL, trustStoreType, trustStorePassword);
@@ -104,6 +105,25 @@
private KeyStore loadStore(String property, String type, URL storeURL, String storeType, String storePassword) throws WSSecurityException
{
+ if (storeURL == null)
+ {
+ String defaultStore = System.getProperty(property);
+ if (defaultStore == null)
+ {
+ return null;
+ }
+
+ File storeFile = new File(defaultStore);
+ try
+ {
+ storeURL = storeFile.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new WSSecurityException("Problems loading " + type + ": " + e.getMessage(), e);
+ }
+ }
+
if (storeType == null)
storeType = System.getProperty(property + "Type");
if (storeType == null)
@@ -112,16 +132,6 @@
storePassword = getPassword(storePassword);
try
{
- if (storeURL == null)
- {
- String defaultStore = System.getProperty(property);
- if (defaultStore == null)
- throw new WSSecurityException(type + " url not specified");
-
- File storeFile = new File(defaultStore);
- storeURL = storeFile.toURL();
- }
-
log.debug("loadStore: " + storeURL);
InputStream stream = storeURL.openStream();
KeyStore keyStore = KeyStore.getInstance(storeType);
@@ -141,22 +151,22 @@
*/
private String getPassword(String password) throws WSSecurityException
{
- if( password.charAt(0) == '{' )
+ if (password.charAt(0) == '{')
{
StringTokenizer tokenizer = new StringTokenizer(password, "{}");
String keyStorePasswordCmdType = tokenizer.nextToken();
String keyStorePasswordCmd = tokenizer.nextToken();
- if( keyStorePasswordCmdType.equals("EXT") )
+ if (keyStorePasswordCmdType.equals("EXT"))
{
password = execPasswordCmd(keyStorePasswordCmd);
}
- else if( keyStorePasswordCmdType.equals("CLASS") )
+ else if (keyStorePasswordCmdType.equals("CLASS"))
{
password = invokePasswordClass(keyStorePasswordCmd);
}
else
{
- throw new WSSecurityException("Unknown keyStorePasswordCmdType: "+keyStorePasswordCmdType);
+ throw new WSSecurityException("Unknown keyStorePasswordCmdType: " + keyStorePasswordCmdType);
}
}
@@ -165,7 +175,7 @@
private String execPasswordCmd(String keyStorePasswordCmd) throws WSSecurityException
{
- log.debug("Executing command: "+keyStorePasswordCmd);
+ log.debug("Executing command: " + keyStorePasswordCmd);
try
{
Runtime rt = Runtime.getRuntime();
@@ -175,7 +185,7 @@
String password = reader.readLine();
stdin.close();
int exitCode = p.waitFor();
- log.debug("Command exited with: "+exitCode);
+ log.debug("Command exited with: " + exitCode);
return password;
}
catch (Exception e)
@@ -183,28 +193,29 @@
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 )
+ if (colon > 0)
{
classname = keyStorePasswordCmd.substring(0, colon);
- ctorArg = keyStorePasswordCmd.substring(colon+1);
+ ctorArg = keyStorePasswordCmd.substring(colon + 1);
}
- log.debug("Loading class: "+classname+", ctorArg="+ctorArg);
+ log.debug("Loading class: " + classname + ", ctorArg=" + ctorArg);
try
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class c = loader.loadClass(classname);
Object instance = null;
- if( ctorArg != null )
+ if (ctorArg != null)
{
- Class[] sig = {String.class};
+ Class[] sig = { String.class };
Constructor ctor = c.getConstructor(sig);
- Object[] args = {ctorArg};
+ Object[] args = { ctorArg };
instance = ctor.newInstance(args);
}
else
@@ -218,9 +229,9 @@
Method toCharArray = c.getMethod("toCharArray", sig);
Object[] args = {};
log.debug("Invoking toCharArray");
- password = new String((char[]) toCharArray.invoke(instance, args));
+ password = new String((char[])toCharArray.invoke(instance, args));
}
- catch(NoSuchMethodException e)
+ catch (NoSuchMethodException e)
{
log.debug("No toCharArray found, invoking toString");
password = instance.toString();
@@ -255,11 +266,11 @@
{
throw new WSSecurityException("KeyStore not set.");
}
-
+
X509Certificate cert;
try
{
- cert = (X509Certificate) keyStore.getCertificate(alias);
+ cert = (X509Certificate)keyStore.getCertificate(alias);
}
catch (Exception e)
{
@@ -269,7 +280,6 @@
if (cert == null)
throw new WSSecurityException("Certificate (" + alias + ") not in keystore");
-
return cert;
}
@@ -282,24 +292,24 @@
{
throw new WSSecurityException("KeyStore not set.");
}
-
+
try
{
Enumeration i = keyStore.aliases();
while (i.hasMoreElements())
{
- String alias = (String) i.nextElement();
+ String alias = (String)i.nextElement();
Certificate cert = keyStore.getCertificate(alias);
- if (! (cert instanceof X509Certificate))
+ if (!(cert instanceof X509Certificate))
continue;
- byte[] subjectKeyIdentifier = getSubjectKeyIdentifier((X509Certificate) cert);
+ byte[] subjectKeyIdentifier = getSubjectKeyIdentifier((X509Certificate)cert);
if (subjectKeyIdentifier == null)
continue;
if (Arrays.equals(identifier, subjectKeyIdentifier))
- return (X509Certificate) cert;
+ return (X509Certificate)cert;
}
}
catch (KeyStoreException e)
@@ -316,21 +326,21 @@
{
throw new WSSecurityException("KeyStore not set.");
}
-
+
try
{
Enumeration i = keyStore.aliases();
while (i.hasMoreElements())
{
- String alias = (String) i.nextElement();
+ String alias = (String)i.nextElement();
Certificate cert = keyStore.getCertificate(alias);
- if (! (cert instanceof X509Certificate))
+ if (!(cert instanceof X509Certificate))
continue;
- X509Certificate x509 = (X509Certificate) cert;
+ X509Certificate x509 = (X509Certificate)cert;
if (issuer.equals(x509.getIssuerDN().toString()) && serial.equals(x509.getSerialNumber().toString()))
- return x509;
+ return x509;
}
}
catch (KeyStoreException e)
@@ -347,11 +357,11 @@
{
throw new WSSecurityException("KeyStore not set.");
}
-
+
PrivateKey key;
try
{
- key = (PrivateKey) keyStore.getKey(alias, getPassword(keyStorePassword).toCharArray());
+ key = (PrivateKey)keyStore.getKey(alias, getPassword(keyStorePassword).toCharArray());
}
catch (Exception e)
{
@@ -370,7 +380,7 @@
{
throw new WSSecurityException("KeyStore not set.");
}
-
+
try
{
String alias = keyStore.getCertificateAlias(cert);
@@ -398,7 +408,7 @@
{
throw new WSSecurityException("TrustStore not set.");
}
-
+
// Check for the exact entry in the truststore first, then fallback to a CA check
try
{
More information about the jboss-svn-commits
mailing list