ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1660078 - in /webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common: crypto/Merlin.java crypto/MerlinDevice.java util/AttachmentUtils.java
Date Mon, 16 Feb 2015 11:48:34 GMT
Author: coheigea
Date: Mon Feb 16 11:48:33 2015
New Revision: 1660078

URL: http://svn.apache.org/r1660078
Log:
Use automatic resource closing

Modified:
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/MerlinDevice.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java?rev=1660078&r1=1660077&r2=1660078&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/Merlin.java
Mon Feb 16 11:48:33 2015
@@ -131,26 +131,15 @@ public class Merlin extends CryptoBase {
         super();
 
         if (truststore == null && loadCACerts) {
-            InputStream cacertsIs = null;
-
-            try {
-                String cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts";
-                cacertsIs = new FileInputStream(cacertsPath);
-
+            String cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts";
+            
+            try (InputStream cacertsIs = new FileInputStream(cacertsPath)) {
+                
                 truststore = KeyStore.getInstance(KeyStore.getDefaultType());
                 truststore.load(cacertsIs, cacertsPasswd.toCharArray());
                 loadCACerts = true;
             } catch (Exception e) {
                 LOG.warn("CA certs could not be loaded: " + e.getMessage());
-            } finally {
-                if (cacertsIs != null) {
-                    try {
-                        cacertsIs.close();
-                    } catch (IOException e) {
-                        LOG.debug(e.getMessage(), e);
-                        //ignore
-                    }
-                }
             }
         }
     }
@@ -209,9 +198,8 @@ public class Merlin extends CryptoBase {
         }
         if (keyStoreLocation != null) {
             keyStoreLocation = keyStoreLocation.trim();
-            InputStream is = loadInputStream(loader, keyStoreLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, keyStoreLocation)) {
                 String passwd = properties.getProperty(prefix + KEYSTORE_PASSWORD, "security");
                 if (passwd != null) {
                     passwd = passwd.trim();
@@ -232,10 +220,6 @@ public class Merlin extends CryptoBase {
                 if (privatePasswd != null) {
                     privatePasswordSet = true;
                 }
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         } else {
             if (DO_DEBUG) {
@@ -249,9 +233,8 @@ public class Merlin extends CryptoBase {
         String trustStoreLocation = properties.getProperty(prefix + TRUSTSTORE_FILE);
         if (trustStoreLocation != null) {
             trustStoreLocation = trustStoreLocation.trim();
-            InputStream is = loadInputStream(loader, trustStoreLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, trustStoreLocation)) {
                 String passwd = properties.getProperty(prefix + TRUSTSTORE_PASSWORD, "changeit");
                 if (passwd != null) {
                     passwd = passwd.trim();
@@ -269,10 +252,6 @@ public class Merlin extends CryptoBase {
                     );
                 }
                 loadCACerts = false;
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         } else {
             String loadCacerts = properties.getProperty(prefix + LOAD_CA_CERTS, "false");
@@ -284,8 +263,7 @@ public class Merlin extends CryptoBase {
                 if (cacertsPath != null) {
                     cacertsPath = cacertsPath.trim();
                 }
-                InputStream is = new FileInputStream(cacertsPath);
-                try {
+                try (InputStream is = new FileInputStream(cacertsPath)) {
                     String cacertsPasswd = properties.getProperty(prefix + TRUSTSTORE_PASSWORD,
"changeit");
                     if (cacertsPasswd != null) {
                         cacertsPasswd = cacertsPasswd.trim();
@@ -296,10 +274,6 @@ public class Merlin extends CryptoBase {
                         LOG.debug("CA certs have been loaded");
                     }
                     loadCACerts = true;
-                } finally {
-                    if (is != null) {
-                        is.close();
-                    }
                 }
             }
         }
@@ -309,9 +283,8 @@ public class Merlin extends CryptoBase {
         String crlLocation = properties.getProperty(prefix + X509_CRL_FILE);
         if (crlLocation != null) {
             crlLocation = crlLocation.trim();
-            InputStream is = loadInputStream(loader, crlLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, crlLocation)) {
                 CertificateFactory cf = getCertificateFactory();
                 X509CRL crl = (X509CRL)cf.generateCRL(is);
                 
@@ -339,10 +312,6 @@ public class Merlin extends CryptoBase {
                     LOG.debug(e.getMessage(), e);
                 }
                 throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "failedCredentialLoad",
e);
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         }
     }
@@ -898,8 +867,7 @@ public class Merlin extends CryptoBase {
         } catch (NoSuchProviderException | NoSuchAlgorithmException 
             | CertificateException | java.security.InvalidAlgorithmParameterException
             | java.security.cert.CertPathValidatorException 
-            | KeyStoreException
-            | NullPointerException e) {
+            | KeyStoreException e) {
                 throw new WSSecurityException(
                     WSSecurityException.ErrorCode.FAILURE, "certpath", e
                 );

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/MerlinDevice.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/MerlinDevice.java?rev=1660078&r1=1660077&r2=1660078&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/MerlinDevice.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/MerlinDevice.java
Mon Feb 16 11:48:33 2015
@@ -93,9 +93,8 @@ public class MerlinDevice extends Merlin
         }
         if (keyStoreLocation != null) {
             keyStoreLocation = keyStoreLocation.trim();
-            InputStream is = loadInputStream(loader, keyStoreLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, keyStoreLocation)) {
                 keystore = load(is, keyStorePassword, provider, keyStoreType);
                 if (DO_DEBUG) {
                     LOG.debug(
@@ -103,10 +102,6 @@ public class MerlinDevice extends Merlin
                         + " has been loaded"
                     );
                 }
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         } else {
             keystore = load(null, keyStorePassword, provider, keyStoreType);
@@ -131,9 +126,8 @@ public class MerlinDevice extends Merlin
         String trustStoreLocation = properties.getProperty(TRUSTSTORE_FILE);
         if (trustStoreLocation != null) {
             trustStoreLocation = trustStoreLocation.trim();
-            InputStream is = loadInputStream(loader, trustStoreLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, trustStoreLocation)) {
                 truststore = load(is, trustStorePassword, provider, trustStoreType);
                 if (DO_DEBUG) {
                     LOG.debug(
@@ -142,18 +136,13 @@ public class MerlinDevice extends Merlin
                     );
                 }
                 loadCACerts = false;
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         } else if (Boolean.valueOf(loadCacerts)) {
             String cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts";
             if (cacertsPath != null) {
                 cacertsPath = cacertsPath.trim();
             }
-            InputStream is = new FileInputStream(cacertsPath);
-            try {
+            try (InputStream is = new FileInputStream(cacertsPath)) {
                 String cacertsPasswd = properties.getProperty(TRUSTSTORE_PASSWORD, "changeit");
                 if (cacertsPasswd != null) {
                     cacertsPasswd = cacertsPasswd.trim();
@@ -164,10 +153,6 @@ public class MerlinDevice extends Merlin
                     LOG.debug("CA certs have been loaded");
                 }
                 loadCACerts = true;
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         } else {
             truststore = load(null, trustStorePassword, provider, trustStoreType);
@@ -178,9 +163,8 @@ public class MerlinDevice extends Merlin
         String crlLocation = properties.getProperty(X509_CRL_FILE);
         if (crlLocation != null) {
             crlLocation = crlLocation.trim();
-            InputStream is = loadInputStream(loader, crlLocation);
 
-            try {
+            try (InputStream is = loadInputStream(loader, crlLocation)) {
                 CertificateFactory cf = getCertificateFactory();
                 X509CRL crl = (X509CRL)cf.generateCRL(is);
                 
@@ -208,10 +192,6 @@ public class MerlinDevice extends Merlin
                     LOG.debug(e.getMessage(), e);
                 }
                 throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "failedCredentialLoad",
e);
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
         }
     }

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java?rev=1660078&r1=1660077&r2=1660078&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java
Mon Feb 16 11:48:33 2015
@@ -385,8 +385,8 @@ public class AttachmentUtils {
     }
 
     /*
-         * Removes any comment outside quoted text. Comments are enclosed between ()
-         */
+     * Removes any comment outside quoted text. Comments are enclosed between ()
+     */
     public static String uncomment(String text) {
         StringBuilder stringBuilder = new StringBuilder();
 



Mime
View raw message