Author: coheigea
Date: Fri Sep 26 07:42:15 2008
New Revision: 699342

URL: http://svn.apache.org/viewvc?rev=699342&view=rev
Log:
[WSS-85] - Improved exception handling
 - Replaced all printlns/printStackTraces in the source code with logging
 - Improved logging of exceptions in general, although there's more work to be 
done here
 - Improved exception propagation in the Crypto stuff.


Modified:
    webservices/wss4j/trunk/src/org/apache/ws/axis/security/WSDoAllReceiver.java
    webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CredentialException.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoFactory.java
    webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSS4JHandler.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSAddSAMLToken.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java
    
webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerFactory.java
    webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerImpl.java
    webservices/wss4j/trunk/src/org/apache/ws/security/util/Base64.java
    webservices/wss4j/trunk/src/org/apache/ws/security/util/XMLUtils.java

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/axis/security/WSDoAllReceiver.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/axis/security/WSDoAllReceiver.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/axis/security/WSDoAllReceiver.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/axis/security/WSDoAllReceiver.java 
Fri Sep 26 07:42:15 2008
@@ -118,6 +118,9 @@
                             .PrettyDocumentToString(doc));
                 }
             } catch (Exception ex) {
+                if (doDebug) {
+                    log.debug(ex.getMessage(), ex);
+                }
                 throw new AxisFault(
                         "WSDoAllReceiver: cannot convert into document", ex);
             }
@@ -159,7 +162,9 @@
                 wsResult = secEngine.processSecurityHeader(doc, actor,
                         cbHandler, reqData.getSigCrypto(), 
reqData.getDecCrypto());
             } catch (WSSecurityException ex) {
-                ex.printStackTrace();
+                if (doDebug) {
+                    log.debug(ex.getMessage(), ex);
+                }
                 throw new AxisFault(
                         "WSDoAllReceiver: security processing failed", ex);
             }
@@ -243,6 +248,9 @@
             try {
                 sHeader = sm.getSOAPEnvelope().getHeader();
             } catch (Exception ex) {
+                if (doDebug) {
+                    log.debug(ex.getMessage(), ex);
+                }
                 throw new AxisFault(
                         "WSDoAllReceiver: cannot get SOAP header after 
security processing",
                         ex);
@@ -347,6 +355,9 @@
                 log.debug("WSDoAllReceiver: exit invoke()");
             }
         } catch (WSSecurityException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             throw new AxisFault(e.getMessage(), e);
         } finally {
             reqData.clear();

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java Fri Sep 
26 07:42:15 2008
@@ -42,6 +42,8 @@
  * @author Werner Dittmann ([EMAIL PROTECTED])
  */
 public class WSSConfig {
+    
+    private static final Log log = 
LogFactory.getLog(WSSConfig.class.getName());
 
     /**
      * The default collection of actions supported by the toolkit.
@@ -83,7 +85,9 @@
                 
org.apache.ws.security.action.SignatureConfirmationAction.class.getName()
             );
         } catch (final Throwable t) {
-            t.printStackTrace();
+            if (log.isDebugEnabled()) {
+                log.debug(t.getMessage(), t);
+            }
         }
         DEFAULT_ACTIONS = java.util.Collections.unmodifiableMap(tmp);
     }
@@ -148,13 +152,13 @@
                 
org.apache.ws.security.processor.EncryptedDataProcessor.class.getName()
             );
         } catch (final Throwable t) {
-            t.printStackTrace();
+            if (log.isDebugEnabled()) {
+                log.debug(t.getMessage(), t);
+            }
         }
         DEFAULT_PROCESSORS = java.util.Collections.unmodifiableMap(tmp);
     }
 
-    private static Log log = LogFactory.getLog(WSSConfig.class.getName());
-
     protected static WSSConfig defaultConfig = null;
 
     protected boolean wsiBSPCompliant = false;
@@ -169,10 +173,10 @@
     protected boolean enableSignatureConfirmation = true;
 
     /**
-     * If set to true then the timestamp handling will throw an expcetion if 
the
+     * If set to true then the timestamp handling will throw an exception if 
the
      * timestamp contains an expires element and the semantics are expired.
      * 
-     * If set to false, not expetion will be thrown, even if the semantics are
+     * If set to false, no exception will be thrown, even if the semantics are
      * expired.
      */
     protected boolean timeStampStrict = true;
@@ -232,14 +236,14 @@
         if (!staticallyInitialized) {
             org.apache.xml.security.Init.init();
             if (addJceProviders) {
-            /*
-             * The last provider added has precedence, that is if JuiCE can be 
add
-             * then WSS4J uses this provider.
-             */
-            addJceProvider("BC",
-                    "org.bouncycastle.jce.provider.BouncyCastleProvider");
-            addJceProvider("JuiCE",
-                    "org.apache.security.juice.provider.JuiCEProviderOpenSSL");
+                /*
+                 * The last provider added has precedence, that is if JuiCE 
can be add
+                 * then WSS4J uses this provider.
+                 */
+                addJceProvider("BC",
+                        "org.bouncycastle.jce.provider.BouncyCastleProvider");
+                addJceProvider("JuiCE",
+                        
"org.apache.security.juice.provider.JuiCEProviderOpenSSL");
             }
             Transform.init();
             try {
@@ -268,7 +272,7 @@
 
     /**
      * returns a static WSConfig instance that is configured with the latest
-     * OASIS WS-Seurity settings.
+     * OASIS WS-Security settings.
      */
     public static WSSConfig getDefaultWSConfig() {
         if (defaultConfig == null) {
@@ -389,6 +393,9 @@
         try {
             return (Action) Loader.loadClass(name).newInstance();
         } catch (Throwable t) {
+            if (log.isDebugEnabled()) {
+                log.debug(t.getMessage(), t);
+            }
             throw new WSSecurityException(WSSecurityException.FAILURE,
                     "unableToLoadClass", new Object[] { name });
         }
@@ -416,6 +423,9 @@
             try {
                 return (Processor) Loader.loadClass(name).newInstance();
             } catch (Throwable t) {
+                if (log.isDebugEnabled()) {
+                    log.debug(t.getMessage(), t);
+                }
                 throw new WSSecurityException(WSSecurityException.FAILURE,
                         "unableToLoadClass", new Object[] { name });
             }
@@ -442,7 +452,7 @@
         } catch (Throwable t) {
             if (log.isDebugEnabled()) {
                 log.debug("The provider " + id + " could not be added: "
-                        + t.getMessage());
+                        + t.getMessage(), t);
             }
             return false;
         }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java
 Fri Sep 26 07:42:15 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.ws.security.components.crypto;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ws.security.util.Loader;
 
 import java.io.FileInputStream;
@@ -34,6 +36,10 @@
  * To change this template use File | Settings | File Templates.
  */
 public abstract class AbstractCrypto extends CryptoBase {
+    
+    private static final Log log = 
LogFactory.getLog(AbstractCrypto.class.getName());
+    private static final boolean doDebug = log.isDebugEnabled();
+
     protected static CertificateFactory certFact;
     protected Properties properties = null;
     
@@ -59,23 +65,14 @@
             return;
         }
         String location = 
this.properties.getProperty("org.apache.ws.security.crypto.merlin.file");
-
-
                InputStream is = null;
-
                java.net.URL url = Loader.getResource(loader, location);
-
                if(url != null) {
-
                        is =  url.openStream();
-
                } else {
-
                        is = new java.io.FileInputStream(location);
-
                }
 
-
         /**
          * If we don't find it, then look on the file system.
          */
@@ -83,7 +80,10 @@
             try {
                 is = new FileInputStream(location);
             } catch (Exception e) {
-                throw new CredentialException(3, "proxyNotFound", new 
Object[]{location});
+                if (doDebug) {
+                    log.debug(e.getMessage(), e);
+                }
+                throw new CredentialException(3, "proxyNotFound", new 
Object[]{location}, e);
             }
         }
 
@@ -133,18 +133,23 @@
             } else {
                 ks = KeyStore.getInstance(type, provider);
             }
-            
                     
             ks.load(input, (storepass == null || storepass.length() == 0) ? 
new char[0] : storepass.toCharArray());
         } catch (IOException e) {
-            e.printStackTrace();
-            throw new CredentialException(3, "ioError00", e);
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
+            throw new CredentialException(CredentialException.IO_ERROR, 
"ioError00", e);
         } catch (GeneralSecurityException e) {
-            e.printStackTrace();
-            throw new CredentialException(3, "secError00", e);
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
+            throw new CredentialException(CredentialException.SEC_ERROR, 
"secError00", e);
         } catch (Exception e) {
-            e.printStackTrace();
-            throw new CredentialException(-1, "error00", e);
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
+            throw new CredentialException(CredentialException.FAILURE, 
"error00", e);
         }
         return ks;
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CredentialException.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CredentialException.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CredentialException.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CredentialException.java
 Fri Sep 26 07:42:15 2008
@@ -32,7 +32,7 @@
     public static final int EXPIRED = 1;
     public static final int DEFECTIVE = 2;
     public static final int IO_ERROR = 3;
-    public static final int SEC_ERROR = 3;
+    public static final int SEC_ERROR = 4;
     private static ResourceBundle resources;
     private int errorCode;
 
@@ -78,8 +78,7 @@
      * @param root
      */
     public CredentialException(int errorCode, String msgId, Object[] args, 
Throwable root) {
-        super(getMessage(msgId, args) + (root == null ? "[]" : " Inner 
Exception: [" + root.getMessage() + "]"));
-        this.errorCode = -1;
+        super(getMessage(msgId, args), root);
         this.errorCode = errorCode;
     }
 
@@ -105,7 +104,7 @@
         try {
             return MessageFormat.format(resources.getString(msgId), args);
         } catch (MissingResourceException e) {
-            throw new RuntimeException("bad" + msgId);
+            throw new RuntimeException("bad" + msgId, e);
         }
     }
 }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoFactory.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoFactory.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/CryptoFactory.java
 Fri Sep 26 07:42:15 2008
@@ -33,7 +33,7 @@
  * @author Davanum Srinivas ([EMAIL PROTECTED]).
  */
 public abstract class CryptoFactory {
-    private static Log log = LogFactory.getLog(CryptoFactory.class);
+    private static final Log log = LogFactory.getLog(CryptoFactory.class);
     private static final String defaultCryptoClassName = 
"org.apache.ws.security.components.crypto.Merlin";
 
     /**
@@ -63,9 +63,9 @@
      * class name as the value of the property : 
org.apache.ws.security.crypto.provider
      * <p/>
      *
-     * @param properties      The Properties that are forwarded to the crypto 
implementaion 
+     * @param properties      The Properties that are forwarded to the crypto 
implementation 
      *                        and the Crypto impl class name.
-     *                        These properties are dependend on the crypto 
implementatin
+     *                        These properties are dependent on the crypto 
implementation
      * @return The cyrpto implementation or null if no cryptoClassName was 
defined
      */
     public static Crypto getInstance(Properties properties) {
@@ -104,7 +104,7 @@
      * @param cryptoClassName This is the crypto implementation class. No 
default is
      *                        provided here.
      * @param properties      The Properties that are forwarded to the crypto 
implementaion.
-     *                        These properties are dependend on the crypto 
implementatin
+     *                        These properties are dependent on the crypto 
implementation
      * @return The cyrpto implementation or null if no cryptoClassName was 
defined
      *
      * @deprecated            use @link{#getInstance(java.lang.String, 
java.util.Map)} instead.
@@ -127,7 +127,7 @@
      *                        These contents of the map are dependent on the 
      *                        underlying crypto implementation specified in 
the 
      *                        cryptoClassName parameter.
-     * @return The cyrpto implementation or null if no cryptoClassName was 
defined
+     * @return The crypto implementation or null if no cryptoClassName was 
defined
      */
     public static Crypto getInstance(String cryptoClassName, Map map) {
         return loadClass(cryptoClassName, map);
@@ -211,17 +211,19 @@
             crypto = (Crypto) c.newInstance(new Object[]{map,loader});
             return crypto;
         } catch (java.lang.Exception e) {
-            e.printStackTrace();
-            log.error("Unable to instantiate (1): " + cryptoClassName, e);
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to instantiate (1): " + cryptoClassName, e);
+            }
         }
         try {
             // try to instantiate the Crypto subclass
             crypto = (Crypto) cryptogenClass.newInstance();
             return crypto;
         } catch (java.lang.Exception e) {
-            e.printStackTrace();
-            log.error("Unable to instantiate (2): " + cryptoClassName, e);
-            throw new RuntimeException(cryptoClassName + " cannot create 
instance");
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to instantiate (2): " + cryptoClassName, e);
+            }
+            throw new RuntimeException(cryptoClassName + " cannot create 
instance", e);
         }
     }
     /**
@@ -250,9 +252,11 @@
             URL url = Loader.getResource(loader, propFilename);
             properties.load(url.openStream());
         } catch (Exception e) {
-            log.debug("Cannot find crypto property file: " + propFilename);
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot find crypto property file: " + propFilename, 
e);
+            }
             throw new RuntimeException("CryptoFactory: Cannot load properties: 
" +
-                    propFilename);
+                    propFilename, e);
         }
         return properties;
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSS4JHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSS4JHandler.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSS4JHandler.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSS4JHandler.java 
Fri Sep 26 07:42:15 2008
@@ -64,7 +64,7 @@
     
     private static Log log = LogFactory.getLog(WSS4JHandler.class.getName());
 
-    private boolean doDebug = log.isDebugEnabled();;
+    private static boolean doDebug = log.isDebugEnabled();
 
     static final String DEPLOYMENT = "deployment";
     static final String CLIENT_DEPLOYMENT = "client";
@@ -97,6 +97,9 @@
         try {
             return processMessage(mc, true);
         } catch (WSSecurityException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             throw new JAXRPCException(e);
         }
     }
@@ -107,6 +110,9 @@
         try {
             return processMessage(mc, false);
         } catch (WSSecurityException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             throw new JAXRPCException(e);
         }
     }
@@ -242,9 +248,9 @@
         Document doc = null;
         SOAPMessage message = ((SOAPMessageContext)mc).getMessage();
         Boolean propFormOptimization = 
(Boolean)mc.getProperty("axis.form.optimization");
-        log.debug("Form optimzation: " + propFormOptimization);
+        log.debug("Form optimization: " + propFormOptimization);
         /*
-        * If the message context property conatins a document then this is a
+        * If the message context property contains a document then this is a
         * chained handler.
         */
         SOAPPart sPart = message.getSOAPPart();
@@ -253,6 +259,9 @@
             try {
                 doc = messageToDocument(message);
             } catch (Exception e) {
+                if (doDebug) {
+                    log.debug(e.getMessage(), e);
+                }
                 throw new JAXRPCException("WSS4JHandler: cannot get SOAP 
envlope from message" + e);
             }
         }
@@ -285,6 +294,9 @@
                 try {
                     osStr = os.toString("UTF-8");
                 } catch (UnsupportedEncodingException e) {
+                    if (doDebug) {
+                        log.debug(e.getMessage(), e);
+                    }
                     osStr = os.toString();
                 }
                 log.debug("Send request:");
@@ -294,6 +306,9 @@
             try {
                 sPart.setContent(new StreamSource(new 
ByteArrayInputStream(os.toByteArray())));
             } catch (SOAPException se) {
+                if (doDebug) {
+                    log.debug(se.getMessage(), se);
+                }
                 throw new JAXRPCException("Couldn't set content on SOAPPart" + 
se.getMessage());
             }
             mc.setProperty(WSHandlerConstants.SND_SECURITY, null);
@@ -334,6 +349,9 @@
         try {
             doc = messageToDocument(message);
         } catch (Exception ex) {
+            if (doDebug) {
+                log.debug(ex.getMessage(), ex);
+            }
             throw new JAXRPCException("WSS4JHandler: cannot convert into 
document",
                     ex);
         }
@@ -375,7 +393,9 @@
                             reqData.getSigCrypto(),
                             reqData.getDecCrypto());
         } catch (WSSecurityException ex) {
-            ex.printStackTrace();
+            if (doDebug) {
+                log.debug(ex.getMessage(), ex);
+            }
             throw new JAXRPCException("WSS4JHandler: security processing 
failed",
                     ex);
         }
@@ -401,6 +421,9 @@
         try {
             sPart.setContent(new StreamSource(new 
ByteArrayInputStream(os.toByteArray())));
         } catch (SOAPException se) {
+            if (doDebug) {
+                log.debug(se.getMessage(), se);
+            }
             throw new JAXRPCException("Couldn't set content on SOAPPart" + 
se.getMessage());
         }
 
@@ -424,6 +447,9 @@
         try {
             sHeader = message.getSOAPPart().getEnvelope().getHeader();
         } catch (Exception ex) {
+            if (doDebug) {
+                log.debug(ex.getMessage(), ex);
+            }
             throw new JAXRPCException("WSS4JHandler: cannot get SOAP header 
after security processing", ex);
         }
 
@@ -530,6 +556,9 @@
             DocumentBuilder builder = dbf.newDocumentBuilder();
             return 
builder.parse(org.apache.ws.security.util.XMLUtils.sourceToInputSource(content));
         } catch (Exception ex) {
+            if (doDebug) {
+                log.debug(ex.getMessage(), ex);
+            }
             throw new JAXRPCException("messageToDocument: cannot convert 
SOAPMessage into Document", ex);
         }
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSAddSAMLToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSAddSAMLToken.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSAddSAMLToken.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSAddSAMLToken.java 
Fri Sep 26 07:42:15 2008
@@ -92,8 +92,10 @@
                     element,
                     true);
         } catch (SAMLException ex) {
-            ex.printStackTrace();
-            throw new RuntimeException(ex.toString());
+            if (log.isDebugEnabled()) {
+                log.debug(ex.getMessage(), ex);
+            }
+            throw new RuntimeException(ex.toString(), ex);
         }
         return doc;
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java
 (original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java
 Fri Sep 26 07:42:15 2008
@@ -51,7 +51,9 @@
  * @author Werner Dittmann ([EMAIL PROTECTED])
  */
 public class UsernameToken {
-    private static Log log = LogFactory.getLog(UsernameToken.class.getName());
+    private static final Log log = 
LogFactory.getLog(UsernameToken.class.getName());
+    
+    private static final boolean doDebug = log.isDebugEnabled();
 
     public static final String PASSWORD_TYPE = "passwordType";
     
@@ -85,8 +87,10 @@
     static {
         try {
             random = SecureRandom.getInstance("SHA1PRNG");
-        } catch (NoSuchAlgorithmException nsae) {
-            nsae.printStackTrace();
+        } catch (NoSuchAlgorithmException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
         }
     }
 
@@ -254,7 +258,7 @@
     /**
      * Adds and optionally creates a Salt element to this UsernameToken.
      * 
-     * If the <code>saltCalue</code> is <code>null</code> the the method
+     * If the <code>saltValue</code> is <code>null</code> the the method
      * generates a new salt. Otherwise it uses the the given value.
      * 
      * @param doc
@@ -427,7 +431,9 @@
                         WSConstants.PASSWORD_DIGEST);
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
         }
     }
 
@@ -462,7 +468,9 @@
             sha.update(b4);
             passwdDigest = Base64.encode(sha.digest());
         } catch (Exception e) {
-            e.printStackTrace();
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
         }
         return passwdDigest;
     }
@@ -593,6 +601,9 @@
                 log.debug("Key        :" + Base64.encode(key));
             }
         } catch (Exception e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             return null;
         }
         return key;
@@ -624,6 +635,9 @@
         try {
             pwBytes = password.getBytes("UTF-8");
         } catch (final java.io.UnsupportedEncodingException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             throw new WSSecurityException("Unable to convert password to 
UTF-8", e);
         }
 
@@ -635,6 +649,9 @@
         try {
             sha = MessageDigest.getInstance("SHA-1");
         } catch (NoSuchAlgorithmException e) {
+            if (doDebug) {
+                log.debug(e.getMessage(), e);
+            }
             throw new WSSecurityException(0, "noSHA1availabe");
         }
         sha.reset();
@@ -711,16 +728,6 @@
         return out;
     }
 
-    /*
-     * public static void main(String[] args) throws Exception { byte[] secret 
=
-     * Base64.decode("A4BKgeqUKi9VDwWyYPDrskwCwEQ5RIqH"); byte[] seed =
-     * 
Base64.decode("bWFzdGVyIHNlY3JldAAAAAAAAAAAAAAAAAAAAAAy+BE8DDEUf+XnAynZEVU0PUQR4QHesAbNCmt8/Ry6NqBELuBAiZV4Z0FuCT58Fi8=");
-     * int required = 48; Mac mac = Mac.getInstance("HMACSHA1"); byte[] out =
-     * UsernameToken.P_hash(secret, seed, mac, 48);
-     * System.out.println(Base64.encode(out));
-     * //UCbz0pT2DxRfx4IpY6iWRE0KCa4Fg9JKNRlrxE8AtjNjb1NEK17NI6XdrMRMOKM2 }
-     */
-
     /**
      * helper method.
      * <p/>

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerFactory.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- 
webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerFactory.java 
(original)
+++ 
webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerFactory.java 
Fri Sep 26 07:42:15 2008
@@ -33,7 +33,8 @@
  * @author Davanum Srinivas ([EMAIL PROTECTED]).
  */
 public abstract class SAMLIssuerFactory {
-    private static Log log = LogFactory.getLog(SAMLIssuerFactory.class);
+    private static final Log log = LogFactory.getLog(SAMLIssuerFactory.class);
+    private static final boolean doDebug = log.isDebugEnabled();
     private static final String defaultSAMLClassName =
             "org.apache.ws.security.saml.SAMLIssuerImpl";
 
@@ -110,8 +111,11 @@
         try {
             // instruct the class loader to load the crypto implementation
             samlIssuerClass = Loader.loadClass(samlClassName);
-        } catch (ClassNotFoundException e) {
-            throw new RuntimeException(samlClassName + " Not Found");
+        } catch (ClassNotFoundException ex) {
+            if (log.isDebugEnabled()) {
+                log.debug(ex.getMessage(), ex);
+            }
+            throw new RuntimeException(samlClassName + " Not Found", ex);
         }
         log.info("Using Crypto Engine [" + samlClassName + "]");
         try {
@@ -120,18 +124,20 @@
             samlIssuer =
                     (SAMLIssuer) c.newInstance(new Object[]{properties});
             return samlIssuer;
-        } catch (java.lang.Exception e) {
-            e.printStackTrace();
-            log.error(e);
+        } catch (java.lang.Exception ex) {
+            if (log.isDebugEnabled()) {
+                log.debug(ex.getMessage(), ex);
+            }
         }
         try {
             // try to instantiate the Crypto subclass
             samlIssuer = (SAMLIssuer) samlIssuerClass.newInstance();
             return samlIssuer;
-        } catch (java.lang.Exception e) {
-            e.printStackTrace();
-            log.error(e);
-            throw new RuntimeException(samlClassName + " cannot create 
instance");
+        } catch (java.lang.Exception ex) {
+            if (log.isDebugEnabled()) {
+                log.debug(ex.getMessage(), ex);
+            }
+            throw new RuntimeException(samlClassName + " cannot create 
instance", ex);
         }
     }
 
@@ -139,7 +145,7 @@
      * Gets the properties for SAML issuer.
      * The functions loads the property file via
      * [EMAIL PROTECTED] Loader.getResource(String)}, thus the property file
-     * should be accesible via the classpath
+     * should be accessible via the classpath
      *
      * @param propFilename the properties file to load
      * @return a <code>Properties</code> object loaded from the filename
@@ -150,8 +156,10 @@
             URL url = Loader.getResource(propFilename);
             properties.load(url.openStream());
         } catch (Exception e) {
-            log.debug("Cannot find SAML property file: " + propFilename);
-            throw new RuntimeException("SAMLIssuerFactory: Cannot load 
properties: " + propFilename);
+            if (doDebug) {
+                log.debug("Cannot find SAML property file: " + propFilename, 
e);
+            }
+            throw new RuntimeException("SAMLIssuerFactory: Cannot load 
properties: " + propFilename, e);
         }
         return properties;
     }

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerImpl.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerImpl.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/saml/SAMLIssuerImpl.java 
Fri Sep 26 07:42:15 2008
@@ -48,7 +48,8 @@
  */
 public class SAMLIssuerImpl implements SAMLIssuer {
 
-    private static Log log = LogFactory.getLog(SAMLIssuerImpl.class.getName());
+    private static final Log log = 
LogFactory.getLog(SAMLIssuerImpl.class.getName());
+    private static final boolean doDebug = log.isDebugEnabled();
 
     private SAMLAssertion sa = null;
 
@@ -76,7 +77,7 @@
         /*
          * if no properties .. just return an instance, the rest will be done
          * later or this instance is just used to handle certificate
-         * conversions in this implementatio
+         * conversions in this implementation
          */
         if (prop == null) {
             return;
@@ -120,7 +121,7 @@
          * if (senderVouches == false && userCrypto == null) { throw
          * exception("need user crypto data to insert key") }
          */
-        // Issuer must enable crypto fubctions to get the issuer's certificate
+        // Issuer must enable crypto functions to get the issuer's certificate
         String issuer =
                 properties.getProperty("org.apache.ws.security.saml.issuer");
         String name =
@@ -169,9 +170,15 @@
                     X509Data certElem = new X509Data(instanceDoc);
                     certElem.addCertificate(certs[0]);
                     ki.add(certElem);
-                } catch (WSSecurityException e) {
+                } catch (WSSecurityException ex) {
+                    if (log.isDebugEnabled()) {
+                        log.debug(ex.getMessage(), ex);
+                    }
                     return null;
-                } catch (XMLSecurityException e) {
+                } catch (XMLSecurityException ex) {
+                    if (log.isDebugEnabled()) {
+                        log.debug(ex.getMessage(), ex);
+                    }
                     return null;
                 }
                 subject.setKeyInfo(ki);
@@ -191,17 +198,23 @@
                             issuerCrypto.getPrivateKey(issuerKeyName,
                                     issuerKeyPassword);
                     sa.sign(sigAlgo, issuerPK, Arrays.asList(issuerCerts));
-                } catch (WSSecurityException e1) {
-                    e1.printStackTrace();
+                } catch (WSSecurityException ex) {
+                    if (log.isDebugEnabled()) {
+                        log.debug(ex.getMessage(), ex);
+                    }
                     return null;
-                } catch (Exception e1) {
-                    e1.printStackTrace();
+                } catch (Exception ex) {
+                    if (log.isDebugEnabled()) {
+                        log.debug(ex.getMessage(), ex);
+                    }
                     return null;
                 }
             }
         } catch (SAMLException ex) {
-            ex.printStackTrace();
-            throw new RuntimeException(ex.toString());
+            if (log.isDebugEnabled()) {
+                log.debug(ex.getMessage(), ex);
+            }
+            throw new RuntimeException(ex.toString(), ex);
         }
         return sa;
     }

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/util/Base64.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/util/Base64.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/util/Base64.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/util/Base64.java Fri Sep 
26 07:42:15 2008
@@ -64,7 +64,7 @@
 
     static private final char PAD = '=';
 
-    static private final boolean fDebug = false;
+    static private final boolean IS_DEBUG = log.isDebugEnabled();
 
     static final private byte[] base64Alphabet = new byte[BASELENGTH];
 
@@ -125,12 +125,6 @@
     }
 
     /**
-     * Encodes hex octects into Base64
-     *
-     * @param binaryData Array containing binaryData
-     * @return Encoded Base64 array
-     */
-    /**
      * Encode a byte array in Base64 format and return an optionally
      * wrapped line.
      *
@@ -167,8 +161,8 @@
         int encodedIndex = 0;
         int dataIndex = 0;
         int tripletsDone = 0;
-        if (fDebug) {
-            System.out.println("number of triplets = " + numberTriplets);
+        if (IS_DEBUG) {
+            log.debug("number of triplets = " + numberTriplets);
         }
 
         for (int line = 0; line < numberLines; line++) {
@@ -177,9 +171,8 @@
                 b2 = binaryData[dataIndex++];
                 b3 = binaryData[dataIndex++];
 
-                if (fDebug) {
-                    System.out.println("b1= " + b1 + ", b2= " + b2 + ", b3= "
-                            + b3);
+                if (IS_DEBUG) {
+                    log.debug("b1= " + b1 + ", b2= " + b2 + ", b3= " + b3);
                 }
 
                 l = (byte) (b2 & 0x0f);
@@ -193,10 +186,10 @@
                 byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6)
                         : (byte) ((b3) >> 6 ^ 0xfc);
 
-                if (fDebug) {
-                    System.out.println("val2 = " + val2);
-                    System.out.println("k4   = " + (k << 4));
-                    System.out.println("vak  = " + (val2 | (k << 4)));
+                if (IS_DEBUG) {
+                    log.debug("val2 = " + val2);
+                    log.debug("k4   = " + (k << 4));
+                    log.debug("vak  = " + (val2 | (k << 4)));
                 }
 
                 encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
@@ -218,8 +211,8 @@
             b2 = binaryData[dataIndex++];
             b3 = binaryData[dataIndex++];
 
-            if (fDebug) {
-                System.out.println("b1= " + b1 + ", b2= " + b2 + ", b3= " + 
b3);
+            if (IS_DEBUG) {
+                log.debug("b1= " + b1 + ", b2= " + b2 + ", b3= " + b3);
             }
 
             l = (byte) (b2 & 0x0f);
@@ -233,10 +226,10 @@
             byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6)
                     : (byte) ((b3) >> 6 ^ 0xfc);
 
-            if (fDebug) {
-                System.out.println("val2 = " + val2);
-                System.out.println("k4   = " + (k << 4));
-                System.out.println("vak  = " + (val2 | (k << 4)));
+            if (IS_DEBUG) {
+                log.debug("val2 = " + val2);
+                log.debug("k4   = " + (k << 4));
+                log.debug("vak  = " + (val2 | (k << 4)));
             }
 
             encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
@@ -249,9 +242,9 @@
         if (fewerThan24bits == EIGHTBIT) {
             b1 = binaryData[dataIndex];
             k = (byte) (b1 & 0x03);
-            if (fDebug) {
-                System.out.println("b1=" + b1);
-                System.out.println("b1<<2 = " + (b1 >> 2));
+            if (IS_DEBUG) {
+                log.debug("b1=" + b1);
+                log.debug("b1<<2 = " + (b1 >> 2));
             }
             byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
                     : (byte) ((b1) >> 2 ^ 0xc0);

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/util/XMLUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/util/XMLUtils.java?rev=699342&r1=699341&r2=699342&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/util/XMLUtils.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/util/XMLUtils.java Fri 
Sep 26 07:42:15 2008
@@ -1,5 +1,7 @@
 package org.apache.ws.security.util;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -17,6 +19,10 @@
 import java.io.OutputStream;
 
 public class XMLUtils {
+    
+    private static final Log log = LogFactory.getLog(XMLUtils.class.getName());
+    private static final boolean doDebug = log.isDebugEnabled();
+    
     public static String PrettyDocumentToString(Document doc) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ElementToStream(doc.getDocumentElement(), baos);
@@ -30,8 +36,10 @@
             TransformerFactory transFactory = TransformerFactory.newInstance();
             Transformer transformer = transFactory.newTransformer();
             transformer.transform(source, result);
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (Exception ex) {
+            if (doDebug) {
+                log.debug(ex.getMessage(), ex);
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to