ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1663695 - in /webservices/wss4j/trunk: integration/src/test/java/org/apache/wss4j/integration/test/kerberos/ ws-security-common/src/main/java/org/apache/wss4j/common/crypto/ ws-security-common/src/main/java/org/apache/wss4j/common/kerberos...
Date Tue, 03 Mar 2015 13:06:42 GMT
Author: coheigea
Date: Tue Mar  3 13:06:41 2015
New Revision: 1663695

URL: http://svn.apache.org/r1663695
Log:
More refactoring

Modified:
    webservices/wss4j/trunk/integration/src/test/java/org/apache/wss4j/integration/test/kerberos/KerberosTest.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/kerberos/KerberosTokenDecoderImpl.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/AttachmentUtils.java
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/X509Security.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/EncryptedKeyProcessor.java
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/SOAPUtil.java
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentTest.java
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TestMessageTransformer.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509PKIPathv1SecurityTokenImpl.java
    webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509V3SecurityTokenImpl.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCRLTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCertConstaintsTest.java

Modified: webservices/wss4j/trunk/integration/src/test/java/org/apache/wss4j/integration/test/kerberos/KerberosTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/integration/src/test/java/org/apache/wss4j/integration/test/kerberos/KerberosTest.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/integration/src/test/java/org/apache/wss4j/integration/test/kerberos/KerberosTest.java
(original)
+++ webservices/wss4j/trunk/integration/src/test/java/org/apache/wss4j/integration/test/kerberos/KerberosTest.java
Tue Mar  3 13:06:41 2015
@@ -191,16 +191,16 @@ public class KerberosTest extends Abstra
             
             // Read in krb5.conf and substitute in the correct port
             File f = new File(basedir + "/src/test/resources/kerberos/krb5.conf");
-            
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
-            content = content.replaceAll("port", "" + super.getKdcServer().getTransports()[0].getPort());
-            
             File f2 = new File(basedir + "/target/test-classes/kerberos/krb5.conf");
-            FileOutputStream outputStream = new FileOutputStream(f2);
-            IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
+
+            try (FileInputStream inputStream = new FileInputStream(f);
+                FileOutputStream outputStream = new FileOutputStream(f2)) {
+                String content = IOUtils.toString(inputStream, "UTF-8");
+                inputStream.close();
+                content = content.replaceAll("port", "" + super.getKdcServer().getTransports()[0].getPort());
+            
+                IOUtils.write(content, outputStream, "UTF-8");
+            }
             
             System.setProperty("java.security.krb5.conf", f2.getPath());
             

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/CryptoBase.java
Tue Mar  3 13:06:41 2015
@@ -20,6 +20,7 @@
 package org.apache.wss4j.common.crypto;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.security.MessageDigest;
@@ -276,15 +277,15 @@ public abstract class CryptoBase impleme
      */
     public X509Certificate[] getCertificatesFromBytes(byte[] data)
         throws WSSecurityException {
-        InputStream in = new ByteArrayInputStream(data);
         CertPath path = null;
-        try {
+        try (InputStream in = new ByteArrayInputStream(data)) {
             path = getCertificateFactory().generateCertPath(in);
-        } catch (CertificateException e) {
+        } catch (CertificateException | IOException e) {
             throw new WSSecurityException(
                 WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE, "parseError", e
             );
         }
+        
         List<?> l = path.getCertificates();
         X509Certificate[] certs = new X509Certificate[l.size()];
         int i = 0;

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/kerberos/KerberosTokenDecoderImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/kerberos/KerberosTokenDecoderImpl.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/kerberos/KerberosTokenDecoderImpl.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/kerberos/KerberosTokenDecoderImpl.java
Tue Mar  3 13:06:41 2015
@@ -173,12 +173,13 @@ public class KerberosTokenDecoderImpl im
     }
 
     private static byte[] toByteArray(InputStream inputStream) throws IOException {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        int read;
-        byte[] buf = new byte[1024];
-        while ((read = inputStream.read(buf)) != -1) {
-            byteArrayOutputStream.write(buf, 0, read);
+        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
+            int read;
+            byte[] buf = new byte[1024];
+            while ((read = inputStream.read(buf)) != -1) {
+                byteArrayOutputStream.write(buf, 0, read);
+            }
+            return byteArrayOutputStream.toByteArray();
         }
-        return byteArrayOutputStream.toByteArray();
     }
 }

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=1663695&r1=1663694&r2=1663695&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
Tue Mar  3 13:06:41 2015
@@ -559,8 +559,7 @@ public final class AttachmentUtils {
         final InputStream attachmentInputStream;
 
         if (complete) {
-            try {
-                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream())
{
                 OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream,
"US-ASCII");
 
                 Iterator<Map.Entry<String, String>> iterator = headers.entrySet().iterator();

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
(original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
Tue Mar  3 13:06:41 2015
@@ -20,6 +20,7 @@ package org.apache.wss4j.common.util;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 
 import javax.xml.transform.Source;
@@ -87,10 +88,11 @@ public final class XMLUtils {
         return null;
     }
     
-    public static String PrettyDocumentToString(Document doc) throws TransformerException
{
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ElementToStream(doc.getDocumentElement(), baos);
-        return new String(baos.toByteArray());
+    public static String PrettyDocumentToString(Document doc) throws IOException, TransformerException
{
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            ElementToStream(doc.getDocumentElement(), baos);
+            return new String(baos.toByteArray());
+        }
     }
 
     public static void ElementToStream(Element element, OutputStream out) 
@@ -107,20 +109,21 @@ public final class XMLUtils {
      *
      * @param source the resource to get
      */
-    public static InputSource sourceToInputSource(Source source) throws TransformerException
{
+    public static InputSource sourceToInputSource(Source source) throws IOException, TransformerException
{
         if (source instanceof SAXSource) {
             return ((SAXSource) source).getInputSource();
         } else if (source instanceof DOMSource) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
             Node node = ((DOMSource) source).getNode();
             if (node instanceof Document) {
                 node = ((Document) node).getDocumentElement();
             }
             Element domElement = (Element) node;
-            ElementToStream(domElement, baos);
-            InputSource isource = new InputSource(source.getSystemId());
-            isource.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
-            return isource;
+            try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+                ElementToStream(domElement, baos);
+                InputSource isource = new InputSource(source.getSystemId());
+                isource.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
+                return isource;
+            }
         } else if (source instanceof StreamSource) {
             StreamSource ss = (StreamSource) source;
             InputSource isource = new InputSource(ss.getSystemId());

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/X509Security.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/X509Security.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/X509Security.java
(original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/X509Security.java
Tue Mar  3 13:06:41 2015
@@ -28,6 +28,7 @@ import org.apache.wss4j.common.ext.WSSec
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
 import java.security.cert.CertificateEncodingException;
@@ -91,9 +92,15 @@ public class X509Security extends Binary
             throw new WSSecurityException(
                 WSSecurityException.ErrorCode.FAILURE, "invalidCertData", 0);
         }
-        InputStream in = new ByteArrayInputStream(data);
-        cachedCert = certCrypto.loadCertificate(in);
-        return cachedCert;
+        try (InputStream in = new ByteArrayInputStream(data)) {
+            cachedCert = certCrypto.loadCertificate(in);
+            return cachedCert;
+        } catch (IOException e) {
+            throw new WSSecurityException(
+                WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE, "parseError", e
+            );
+        }
+
     }
 
     /**

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/EncryptedKeyProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/EncryptedKeyProcessor.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/EncryptedKeyProcessor.java
(original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/EncryptedKeyProcessor.java
Tue Mar  3 13:06:41 2015
@@ -20,6 +20,7 @@
 package org.apache.wss4j.dom.processor;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
@@ -426,10 +427,15 @@ public class EncryptedKeyProcessor imple
                     if (token == null) {
                         throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"invalidCertData", 0);
                     }
-                    InputStream in = new ByteArrayInputStream(token);
-                    X509Certificate cert = data.getDecCrypto().loadCertificate(in);
-                    if (cert != null) {
-                        return new X509Certificate[]{cert};
+                    try (InputStream in = new ByteArrayInputStream(token)) {
+                        X509Certificate cert = data.getDecCrypto().loadCertificate(in);
+                        if (cert != null) {
+                            return new X509Certificate[]{cert};
+                        }
+                    } catch (IOException e) {
+                        throw new WSSecurityException(
+                            WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE, "parseError",
e
+                        );
                     }
                 }
             }

Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/SOAPUtil.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/SOAPUtil.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/SOAPUtil.java
(original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/SOAPUtil.java
Tue Mar  3 13:06:41 2015
@@ -50,9 +50,10 @@ public class SOAPUtil {
      * Convert an SOAP Envelope as a String to a org.w3c.dom.Document.
      */
     public static org.w3c.dom.Document toSOAPPart(String xml) throws Exception {
-        InputStream in = new ByteArrayInputStream(xml.getBytes());
-        DocumentBuilder builder = factory.newDocumentBuilder();
-        return builder.parse(in);
+        try (InputStream in = new ByteArrayInputStream(xml.getBytes())) {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            return builder.parse(in);
+        }
     }
     
 }

Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentTest.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentTest.java
(original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/AttachmentTest.java
Tue Mar  3 13:06:41 2015
@@ -81,13 +81,14 @@ public class AttachmentTest extends org.
     }
 
     protected byte[] readInputStream(InputStream inputStream) throws IOException {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        int read = 0;
-        byte[] buf = new byte[4096];
-        while ((read = inputStream.read(buf)) != -1) {
-            byteArrayOutputStream.write(buf, 0, read);
+        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
+            int read = 0;
+            byte[] buf = new byte[4096];
+            while ((read = inputStream.read(buf)) != -1) {
+                byteArrayOutputStream.write(buf, 0, read);
+            }
+            return byteArrayOutputStream.toByteArray();
         }
-        return byteArrayOutputStream.toByteArray();
     }
 
     @org.junit.Test

Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TestMessageTransformer.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TestMessageTransformer.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TestMessageTransformer.java
(original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/message/TestMessageTransformer.java
Tue Mar  3 13:06:41 2015
@@ -19,6 +19,7 @@
 
 package org.apache.wss4j.dom.message;
 
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -45,7 +46,7 @@ public class TestMessageTransformer exte
         SecurityTestUtil.cleanup();
     }
     
-    public static Element duplicateEncryptedDataInWsseHeader(Element saaj, boolean moveReferenceList)
throws TransformerException {
+    public static Element duplicateEncryptedDataInWsseHeader(Element saaj, boolean moveReferenceList)
throws TransformerException, IOException {
         if (moveReferenceList) {
             moveReferenceList(saaj);
         }
@@ -81,7 +82,7 @@ public class TestMessageTransformer exte
         return newEncData;
     }
 
-    public static Element duplicateEncryptedDataInWsseWrapperHeader(Element saaj, boolean
moveReferenceList) throws TransformerException {
+    public static Element duplicateEncryptedDataInWsseWrapperHeader(Element saaj, boolean
moveReferenceList) throws TransformerException, IOException {
         if (moveReferenceList) {
             moveReferenceList(saaj);
         }
@@ -120,7 +121,7 @@ public class TestMessageTransformer exte
         return newEncData;
     }
     
-    public static Element duplicateEncryptedDataInWrapperBody(Element saaj) throws TransformerException
{
+    public static Element duplicateEncryptedDataInWrapperBody(Element saaj) throws TransformerException,
IOException {
         Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/",
                                                             "Body"), true);
         Element encData = getFirstChildElement(body, new QName("http://www.w3.org/2001/04/xmlenc#",
@@ -155,7 +156,7 @@ public class TestMessageTransformer exte
         return newEncData;
     }
     
-    public static Element duplicateEncryptedDataAfterWrapperBody(Element saaj) throws TransformerException
{
+    public static Element duplicateEncryptedDataAfterWrapperBody(Element saaj) throws TransformerException,
IOException {
         Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/",
                                                             "Body"), true);
         Element encData = getFirstChildElement(body, new QName("http://www.w3.org/2001/04/xmlenc#",
@@ -193,7 +194,7 @@ public class TestMessageTransformer exte
     }
 
     public static Element duplicateEncryptedDataInExternalWrapperElement(Element saaj,
-                                                                         boolean moveReferenceList)
throws TransformerException {
+                                                                         boolean moveReferenceList)
throws TransformerException, IOException {
         if (moveReferenceList) {
             moveReferenceList(saaj);
         }
@@ -231,7 +232,7 @@ public class TestMessageTransformer exte
         return newEncData;
     }
     
-    public static Element addEncryptedDataWithEmbeddedEncryptedKeyInWsseHeader(Element saaj)
throws TransformerException {
+    public static Element addEncryptedDataWithEmbeddedEncryptedKeyInWsseHeader(Element saaj)
throws TransformerException, IOException {
         moveReferenceList(saaj);
         Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/",
                                                             "Body"), true);
@@ -301,7 +302,7 @@ public class TestMessageTransformer exte
         ref.getParentNode().appendChild(newRef);
     }
 
-    private static void print(Document doc) throws TransformerException {
+    private static void print(Document doc) throws TransformerException, IOException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("After transformation....");
             String outputString = XMLUtils.PrettyDocumentToString(doc);

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509PKIPathv1SecurityTokenImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509PKIPathv1SecurityTokenImpl.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509PKIPathv1SecurityTokenImpl.java
(original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509PKIPathv1SecurityTokenImpl.java
Tue Mar  3 13:06:41 2015
@@ -27,6 +27,8 @@ import org.apache.xml.security.exception
 import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
 
 import javax.security.auth.callback.CallbackHandler;
+
+import java.io.IOException;
 import java.io.InputStream;
 import java.security.cert.CertPath;
 import java.security.cert.Certificate;
@@ -47,8 +49,7 @@ public class X509PKIPathv1SecurityTokenI
         super(WSSecurityTokenConstants.X509PkiPathV1Token, wsInboundSecurityContext, crypto,
                 callbackHandler, id, keyIdentifier, securityProperties, true);
 
-        InputStream in = new UnsynchronizedByteArrayInputStream(binaryContent);
-        try {
+        try (InputStream in = new UnsynchronizedByteArrayInputStream(binaryContent)) {
             CertPath certPath = getCrypto().getCertificateFactory().generateCertPath(in);
             List<? extends Certificate> l = certPath.getCertificates();
             X509Certificate[] certs = new X509Certificate[l.size()];
@@ -59,7 +60,7 @@ public class X509PKIPathv1SecurityTokenI
             if (certs.length > 0) {
                 setX509Certificates(certs);
             }
-        } catch (CertificateException e) {
+        } catch (CertificateException | IOException e) {
             throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY,
"parseError", e);
         }
     }

Modified: webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509V3SecurityTokenImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509V3SecurityTokenImpl.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509V3SecurityTokenImpl.java
(original)
+++ webservices/wss4j/trunk/ws-security-stax/src/main/java/org/apache/wss4j/stax/impl/securityToken/X509V3SecurityTokenImpl.java
Tue Mar  3 13:06:41 2015
@@ -19,6 +19,7 @@
 package org.apache.wss4j.stax.impl.securityToken;
 
 import org.apache.wss4j.common.crypto.Crypto;
+import org.apache.wss4j.common.ext.WSSecurityException;
 import org.apache.wss4j.stax.ext.WSInboundSecurityContext;
 import org.apache.wss4j.stax.ext.WSSConfigurationException;
 import org.apache.wss4j.stax.ext.WSSSecurityProperties;
@@ -27,6 +28,9 @@ import org.apache.xml.security.exception
 import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
 
 import javax.security.auth.callback.CallbackHandler;
+
+import java.io.IOException;
+import java.io.InputStream;
 import java.security.cert.X509Certificate;
 
 public class X509V3SecurityTokenImpl extends X509SecurityTokenImpl {
@@ -40,8 +44,12 @@ public class X509V3SecurityTokenImpl ext
         super(WSSecurityTokenConstants.X509V3Token, wsInboundSecurityContext, crypto, callbackHandler,
id,
                 WSSecurityTokenConstants.KeyIdentifier_X509KeyIdentifier, securityProperties,
true);
 
-        X509Certificate x509Certificate = getCrypto().loadCertificate(new UnsynchronizedByteArrayInputStream(binaryContent));
-        setX509Certificates(new X509Certificate[]{x509Certificate});
+        try (InputStream inputStream = new UnsynchronizedByteArrayInputStream(binaryContent))
{
+            X509Certificate x509Certificate = getCrypto().loadCertificate(inputStream);
+            setX509Certificates(new X509Certificate[]{x509Certificate});
+        } catch (IOException e) {
+            throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY,
"parseError", e);
+        }
 
         // Check to see if the certificates actually correspond to the decryption crypto
         if (getCrypto().getX509Identifier(getX509Certificates()[0]) == null) {

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
(original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
Tue Mar  3 13:06:41 2015
@@ -73,6 +73,7 @@ import javax.xml.xpath.XPathExpressionEx
 import javax.xml.xpath.XPathFactory;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -174,14 +175,14 @@ public abstract class AbstractTestBase e
     }
 
     protected Document doOutboundSecurityWithWSS4J(InputStream sourceDocument, String action,
Properties properties)
-            throws WSSecurityException, TransformerException {
+            throws WSSecurityException, TransformerException, IOException {
         Map<String, Object> context = doOutboundSecurityWithWSS4J_1(sourceDocument,
action, properties);
         return (Document) context.get(SECURED_DOCUMENT);
     }
 
     protected Map<String, Object> doOutboundSecurityWithWSS4J_1(
             InputStream sourceDocument, String action, final Properties properties
-    ) throws WSSecurityException, TransformerException {
+    ) throws WSSecurityException, TransformerException, IOException {
         CustomWSS4JHandler wss4JHandler = new CustomWSS4JHandler();
         final Map<String, Object> messageContext = getMessageContext(sourceDocument);
         messageContext.put(WSHandlerConstants.ACTION, action);
@@ -373,9 +374,10 @@ public abstract class AbstractTestBase e
          * Handles incoming web service requests and outgoing responses
          *
          * @throws TransformerException
+         * @throws IOException 
          */
         public boolean doSender(Map<String, Object> mc, RequestData reqData, boolean
isRequest)
-                throws WSSecurityException, TransformerException {
+                throws WSSecurityException, TransformerException, IOException {
 
             /*
              * Get the action first.

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCRLTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCRLTest.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCRLTest.java
(original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCRLTest.java
Tue Mar  3 13:06:41 2015
@@ -20,6 +20,7 @@ package org.apache.wss4j.stax.test;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Enumeration;
 import java.util.Map;
@@ -128,7 +129,7 @@ public class SignatureCRLTest extends Ab
     @Override
     protected Map<String, Object> doOutboundSecurityWithWSS4J_1(
         InputStream sourceDocument, String action, final Properties properties
-    ) throws WSSecurityException, TransformerException {
+    ) throws WSSecurityException, TransformerException, IOException {
         CustomWSS4JHandler wss4JHandler = new CustomWSS4JHandler();
         final Map<String, Object> messageContext = getMessageContext(sourceDocument);
         messageContext.put(WSHandlerConstants.ACTION, action);

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCertConstaintsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCertConstaintsTest.java?rev=1663695&r1=1663694&r2=1663695&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCertConstaintsTest.java
(original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureCertConstaintsTest.java
Tue Mar  3 13:06:41 2015
@@ -20,6 +20,7 @@ package org.apache.wss4j.stax.test;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -168,7 +169,7 @@ public class SignatureCertConstaintsTest
     @Override
     protected Map<String, Object> doOutboundSecurityWithWSS4J_1(
         InputStream sourceDocument, String action, final Properties properties
-    ) throws WSSecurityException, TransformerException {
+    ) throws WSSecurityException, TransformerException, IOException {
         CustomWSS4JHandler wss4JHandler = new CustomWSS4JHandler();
         final Map<String, Object> messageContext = getMessageContext(sourceDocument);
         messageContext.put(WSHandlerConstants.ACTION, action);



Mime
View raw message