ws-wss4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r781006 - /webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java
Date Tue, 02 Jun 2009 11:29:54 GMT
Author: coheigea
Date: Tue Jun  2 11:29:54 2009
New Revision: 781006

URL: http://svn.apache.org/viewvc?rev=781006&view=rev
Log:
[WSS-195] - Backmerged this fix to the 1_5_x-fixes branch.

Modified:
    webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java

Modified: webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java?rev=781006&r1=781005&r2=781006&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java
(original)
+++ webservices/wss4j/branches/1_5_x-fixes/src/org/apache/ws/security/components/crypto/CryptoBase.java
Tue Jun  2 11:29:54 2009
@@ -194,15 +194,38 @@
         }
         boolean b = keystore.isKeyEntry(alias);
         if (!b) {
-            log.error("Cannot find key for alias: " + alias);
-            throw new Exception("Cannot find key for alias: " + alias);
+            String msg = "Cannot find key for alias: [" + alias + "]";
+            String logMsg = createKeyStoreErrorMessage(keystore);
+            log.error(msg + logMsg);
+            throw new Exception(msg);
         }
         Key keyTmp = keystore.getKey(alias, password.toCharArray());
         if (!(keyTmp instanceof PrivateKey)) {
-            throw new Exception("Key is not a private key, alias: " + alias);
+            String msg = "Key is not a private key, alias: [" + alias + "]";
+            String logMsg = createKeyStoreErrorMessage(keystore);
+            log.error(msg + logMsg);
+            throw new Exception(msg);
         }
         return (PrivateKey) keyTmp;
     }
+    
+    protected static String createKeyStoreErrorMessage(KeyStore keystore) throws KeyStoreException
{
+        Enumeration aliases = keystore.aliases();
+        StringBuilder sb = new StringBuilder(keystore.size() * 7);
+        boolean firstAlias = true;
+        while (aliases.hasMoreElements()) {
+            if (!firstAlias) {
+                sb.append(", ");
+            }
+            sb.append(aliases.nextElement());
+            firstAlias = false;
+        }
+        String msg = " in keystore of type [" + keystore.getType()
+            + "] from provider [" + keystore.getProvider()
+            + "] with size [" + keystore.size() + "] and aliases: {"
+            + sb.toString() + "}";
+        return msg;
+    }
 
     protected Vector splitAndTrim(String inString) {
         X509NameTokenizer nmTokens = new X509NameTokenizer(inString);



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org


Mime
View raw message