You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by co...@apache.org on 2009/06/02 13:24:54 UTC

svn commit: r781003 - /webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java

Author: coheigea
Date: Tue Jun  2 11:24:54 2009
New Revision: 781003

URL: http://svn.apache.org/viewvc?rev=781003&view=rev
Log:
[WSS-195] - More detailed exception thrown from CryptoBase.getPrivateKey()
 - Thanks to Aleksander for the patch, I applied it after some minor changes.

Modified:
    webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java?rev=781003&r1=781002&r2=781003&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoBase.java Tue Jun  2 11:24:54 2009
@@ -211,15 +211,38 @@
             throw new Exception("The keystore is null");
         }
         if (alias == null || !keystore.isKeyEntry(alias)) {
-            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 List 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