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 2008/10/16 18:22:14 UTC

svn commit: r705273 - in /webservices/wss4j/trunk: src/org/apache/ws/security/components/crypto/AbstractCrypto.java test/nofile.properties test/wssec/TestWSSecurityNew.java

Author: coheigea
Date: Thu Oct 16 09:22:12 2008
New Revision: 705273

URL: http://svn.apache.org/viewvc?rev=705273&view=rev
Log:
[WSS-149] - Applied patch (thanks!)
 - I also fixed a bug in the patch when is.close() is called on a null inputstream.
 - I added a basic unit test as well.
 - Albert, can you test this and let me know if it's ok, so that I can close the JIRA?

Added:
    webservices/wss4j/trunk/test/nofile.properties   (with props)
Modified:
    webservices/wss4j/trunk/src/org/apache/ws/security/components/crypto/AbstractCrypto.java
    webservices/wss4j/trunk/test/wssec/TestWSSecurityNew.java

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=705273&r1=705272&r2=705273&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 Thu Oct 16 09:22:12 2008
@@ -49,7 +49,7 @@
      * @param properties
      */
     public AbstractCrypto(Properties properties) throws CredentialException, IOException {
-        this(properties,AbstractCrypto.class.getClassLoader());
+        this(properties, AbstractCrypto.class.getClassLoader());
     }
 
     /**
@@ -66,26 +66,28 @@
         }
         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.
-         */
-        if (is == null) {
-            try {
-                is = new FileInputStream(location);
-            } catch (Exception e) {
-                if (doDebug) {
-                    log.debug(e.getMessage(), e);
+        if (location != 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.
+             */
+            if (is == null) {
+                try {
+                    is = new FileInputStream(location);
+                } catch (Exception e) {
+                    if (doDebug) {
+                        log.debug(e.getMessage(), e);
+                    }
+                    throw new CredentialException(
+                        CredentialException.IO_ERROR, "proxyNotFound", new Object[]{location}, e
+                    );
                 }
-                throw new CredentialException(
-                    CredentialException.IO_ERROR, "proxyNotFound", new Object[]{location}, e
-                );
             }
         }
 
@@ -94,11 +96,13 @@
          */
         try {
             String provider = properties.getProperty("org.apache.ws.security.crypto.merlin.keystore.provider");
-            String passwd = properties.getProperty("org.apache.ws.security.crypto.merlin.keystore.password","security");
+            String passwd = properties.getProperty("org.apache.ws.security.crypto.merlin.keystore.password", "security");
             String type = properties.getProperty("org.apache.ws.security.crypto.merlin.keystore.type", KeyStore.getDefaultType());
             this.keystore = load(is, passwd, provider, type);
         } finally {
-            is.close();
+            if (is != null) {
+                is.close();
+            }
         }
 
         /**
@@ -116,17 +120,13 @@
 
 
     /**
-     * Loads the the keystore from an <code>InputStream </code>.
+     * Loads the keystore from an <code>InputStream </code>.
      * <p/>
      *
      * @param input <code>InputStream</code> to read from
      * @throws CredentialException
      */
     public KeyStore load(InputStream input, String storepass, String provider, String type) throws CredentialException {
-        if (input == null) {
-            throw new IllegalArgumentException("input stream cannot be null");
-        }
-        
         KeyStore ks = null;
         
         try {

Added: webservices/wss4j/trunk/test/nofile.properties
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/nofile.properties?rev=705273&view=auto
==============================================================================
--- webservices/wss4j/trunk/test/nofile.properties (added)
+++ webservices/wss4j/trunk/test/nofile.properties Thu Oct 16 09:22:12 2008
@@ -0,0 +1,5 @@
+org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
+org.apache.ws.security.crypto.merlin.keystore.type=pkcs12
+org.apache.ws.security.crypto.merlin.keystore.password=security
+org.apache.ws.security.crypto.merlin.keystore.alias=16c73ab6-b892-458f-abf5-2f875f74882e
+org.apache.ws.security.crypto.merlin.alias.password=security

Propchange: webservices/wss4j/trunk/test/nofile.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/wss4j/trunk/test/nofile.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: webservices/wss4j/trunk/test/nofile.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: webservices/wss4j/trunk/test/wssec/TestWSSecurityNew.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/TestWSSecurityNew.java?rev=705273&r1=705272&r2=705273&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/wssec/TestWSSecurityNew.java (original)
+++ webservices/wss4j/trunk/test/wssec/TestWSSecurityNew.java Thu Oct 16 09:22:12 2008
@@ -193,4 +193,15 @@
         CustomCrypto custom = (CustomCrypto)crypto;
         assertSame(tmp, custom.config);
     }
+    
+    /**
+     * Test for WSS-149 - "AbstractCrypto requires org.apache.ws.security.crypto.merlin.file
+     * to be set and point to an existing file"
+     */
+    public void testNoKeyStoreFile() {
+        Crypto crypto = CryptoFactory.getInstance(
+            "nofile.properties"
+        );
+        assertNotNull(crypto);
+    }
 }



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