cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [2/2] cxf-fediz git commit: Backporting some changes from master
Date Tue, 05 May 2015 16:02:32 GMT
Backporting some changes from master


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/41462bfe
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/41462bfe
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/41462bfe

Branch: refs/heads/1.2.x-fixes
Commit: 41462bfe714804c8d496bb6af7b300b0ed121e39
Parents: 696f8b4
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue May 5 17:02:18 2015 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue May 5 17:02:18 2015 +0100

----------------------------------------------------------------------
 .../cxf/fediz/core/config/FedizContext.java     | 51 +-------------------
 .../core/processor/FederationProcessorImpl.java |  4 +-
 .../apache/cxf/fediz/core/util/CertsUtils.java  | 14 ++++--
 pom.xml                                         |  2 +-
 4 files changed, 15 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/41462bfe/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FedizContext.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FedizContext.java
b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FedizContext.java
index 1084b96..f537dcb 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FedizContext.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/config/FedizContext.java
@@ -19,14 +19,10 @@
 
 package org.apache.cxf.fediz.core.config;
 
-import java.io.BufferedInputStream;
 import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.math.BigInteger;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.List;
@@ -43,12 +39,12 @@ import org.apache.cxf.fediz.core.config.jaxb.TrustManagersType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuerType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuers;
 import org.apache.cxf.fediz.core.exception.IllegalConfigurationException;
+import org.apache.cxf.fediz.core.util.CertsUtils;
 import org.apache.wss4j.common.cache.ReplayCache;
 import org.apache.wss4j.common.cache.ReplayCacheFactory;
 import org.apache.wss4j.common.crypto.CertificateStore;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoFactory;
-import org.apache.wss4j.common.crypto.Merlin;
 import org.apache.wss4j.common.ext.WSSecurityException;
 import org.apache.wss4j.common.util.Loader;
 import org.slf4j.Logger;
@@ -113,7 +109,7 @@ public class FedizContext implements Closeable {
             try {
                 if (manager.getKeyStore().getType().equalsIgnoreCase("PEM")) {
                     X509Certificate[] certificates = new X509Certificate[1];
-                    certificates[0] = readX509Certificate(tm.getName());
+                    certificates[0] = CertsUtils.getX509Certificate(tm.getName(), classloader);
                     crypto = new CertificateStore(certificates);
                 } else {
                     Properties sigProperties = createCryptoProperties(manager);
@@ -351,49 +347,6 @@ public class FedizContext implements Closeable {
         return p;
     }
     
-    private X509Certificate readX509Certificate(String filename) {
-        Certificate cert = null;
-        BufferedInputStream bis = null;
-        try {
-            ClassLoader cl = getClassloader();
-            if (cl == null) {
-                cl = Thread.currentThread().getContextClassLoader();
-            }
-            InputStream is = Merlin.loadInputStream(cl, filename);
-            
-            bis = new BufferedInputStream(is);
-
-            CertificateFactory cf = CertificateFactory.getInstance("X.509");
-
-            if (bis.available() > 0) {
-                cert = cf.generateCertificate(bis);
-                if (!(cert instanceof X509Certificate)) {
-                    LOG.error("Certificate " + filename + " is not of type X509Certificate");
-                    throw new IllegalConfigurationException("Certificate "
-                                                            + filename + " is not of type
X509Certificate");
-                }
-                if (bis.available() > 0) {
-                    LOG.warn("There are more certificates configured in " + filename + ".
Only first is parsed");
-                }
-                return (X509Certificate)cert;    
-            } else  {
-                LOG.error("No bytes can be read in certificate file " + filename);
-                throw new IllegalConfigurationException("No bytes can be read in certificate
file " + filename);
-            }
-        } catch (IllegalConfigurationException ex) {
-            throw ex;
-        } catch (Exception ex) {
-            LOG.error("Failed to read certificate file " + filename, ex);
-            throw new IllegalConfigurationException("Failed to read certificate file " +
filename, ex);
-        } finally {
-            try {
-                bis.close();
-            } catch (IOException ex) {
-                LOG.error("Failed to close certificate file " + filename, ex);
-            }
-        }
-    }
-
     public ClassLoader getClassloader() {
         return classloader;
     }

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/41462bfe/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java
b/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java
index 0fc6a15..f828bbf 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/processor/FederationProcessorImpl.java
@@ -28,7 +28,7 @@ import java.net.URLEncoder;
 import java.security.cert.Certificate;
 import java.text.DateFormat;
 import java.text.ParseException;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -642,7 +642,7 @@ public class FederationProcessorImpl extends AbstractFedizProcessor {
         @Override
         public List<WSSecurityEngineResult> handleToken(Element arg0, RequestData arg1,
WSDocInfo arg2)
             throws WSSecurityException {
-            return new ArrayList<WSSecurityEngineResult>();
+            return Collections.emptyList();
         }
 
     }

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/41462bfe/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/CertsUtils.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/CertsUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/CertsUtils.java
index ad338f4..0d3981f 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/CertsUtils.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/CertsUtils.java
@@ -44,19 +44,25 @@ public final class CertsUtils {
     }
     
     public static X509Certificate getX509Certificate(String filename) {
-        Certificate cert = null;
+        return getX509Certificate(filename, Thread.currentThread().getContextClassLoader());
+    }
+    
+    public static X509Certificate getX509Certificate(String filename, ClassLoader classLoader)
{
+        ClassLoader cl = classLoader;
+        if (cl == null) {
+            cl = Thread.currentThread().getContextClassLoader();
+        }
         BufferedInputStream bis = null;
         try {
             
-            InputStream is = Merlin.loadInputStream(Thread.currentThread().getContextClassLoader(),
filename);
+            InputStream is = Merlin.loadInputStream(cl, filename);
             
-            //FileInputStream fis = new FileInputStream(filename);
             bis = new BufferedInputStream(is);
 
             CertificateFactory cf = CertificateFactory.getInstance("X.509");
 
             if (bis.available() > 0) {
-                cert = cf.generateCertificate(bis);
+                Certificate cert = cf.generateCertificate(bis);
                 if (!(cert instanceof X509Certificate)) {
                     LOG.error("Certificate " + filename + " is not of type X509Certificate");
                     throw new RuntimeException("Certificate "

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/41462bfe/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7b6cd19..885f37d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -288,7 +288,7 @@
                     <version>2.10.1</version>
                     <configuration>
                         <attach>true</attach>
-                        <source>1.5</source>
+                        <source>${jdk.version}</source>
                         <quiet>true</quiet>
                         <bottom>Apache Fediz</bottom>
                         <encoding>UTF-8</encoding>


Mime
View raw message