Author: jaz
Date: Tue Apr 24 11:51:59 2007 New Revision: 532041 URL: http://svn.apache.org/viewvc?view=rev&rev=532041 Log: fixed bugs in truststore loading; added method to load the keystore from the configuration Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/component/ComponentConfig.java ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/SSLUtil.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/component/ComponentConfig.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/component/ComponentConfig.java?view=diff&rev=532041&r1=532040&r2=532041 ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/component/ComponentConfig.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/component/ComponentConfig.java Tue Apr 24 11:51:59 2007 @@ -28,14 +28,12 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.security.KeyStore; import javax.xml.parsers.ParserConfigurationException; import javolution.util.FastList; import javolution.util.FastMap; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilURL; -import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.*; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -644,8 +642,7 @@ } } - public static class KeystoreInfo extends ResourceInfo { - public ComponentConfig componentConfig; + public static class KeystoreInfo extends ResourceInfo { public String name; public String type; public String password; @@ -659,6 +656,18 @@ this.password = element.getAttribute("password"); this.isCertStore = "true".equalsIgnoreCase(element.getAttribute("is-certstore")); this.isTrustStore = "true".equalsIgnoreCase(element.getAttribute("is-truststore")); + } + + public KeyStore getKeyStore() { + ComponentResourceHandler rh = this.createResourceHandler(); + if (rh != null) { + try { + return KeyStoreUtil.getStore(rh.getURL(), this.getPassword(), this.getType()); + } catch (Exception e) { + Debug.logWarning(e, module); + } + } + return null; } public String getName() { Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/SSLUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/SSLUtil.java?view=diff&rev=532041&r1=532040&r2=532041 ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/SSLUtil.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/SSLUtil.java Tue Apr 24 11:51:59 2007 @@ -81,11 +81,16 @@ public static KeyManager[] getKeyManagers(String alias) throws IOException, GeneralSecurityException, GenericConfigException { Iterator i = ComponentConfig.getAllKeystoreInfos().iterator(); List keyMgrs = FastList.newInstance(); + while (i.hasNext()) { ComponentConfig.KeystoreInfo ksi = (ComponentConfig.KeystoreInfo) i.next(); if (ksi.isCertStore()) { - KeyStore ks = KeyStoreUtil.getComponentKeyStore(ksi.componentConfig.getComponentName(), ksi.getName()); - keyMgrs.addAll(Arrays.asList(getKeyManagers(ks, ksi.getPassword(), alias))); + KeyStore ks = ksi.getKeyStore(); + if (ks != null) { + keyMgrs.addAll(Arrays.asList(getKeyManagers(ks, ksi.getPassword(), alias))); + } else { + throw new IOException("Unable to load keystore: " + ksi.createResourceHandler().getFullLocation()); + } } } @@ -104,9 +109,13 @@ Iterator i = ComponentConfig.getAllKeystoreInfos().iterator(); while (i.hasNext()) { ComponentConfig.KeystoreInfo ksi = (ComponentConfig.KeystoreInfo) i.next(); - if (ksi.isCertStore()) { - KeyStore ks = KeyStoreUtil.getComponentKeyStore(ksi.componentConfig.getComponentName(), ksi.getName()); - trustMgrs.addAll(Arrays.asList(getTrustManagers(ks))); + if (ksi.isTrustStore()) { + KeyStore ks = ksi.getKeyStore(); + if (ks != null) { + trustMgrs.addAll(Arrays.asList(getTrustManagers(ks))); + } else { + throw new IOException("Unable to load keystore: " + ksi.createResourceHandler().getFullLocation()); + } } } |
Free forum by Nabble | Edit this page |