You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pl...@apache.org on 2016/07/07 06:42:00 UTC

[15/27] directory-kerby git commit: Make it possible to load certificates from the classpath and not just a filename

Make it possible to load certificates from the classpath and not just a filename


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/5c76b64f
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/5c76b64f
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/5c76b64f

Branch: refs/heads/kpasswd
Commit: 5c76b64f618bef19cbaae50469a45a1cea89dee4
Parents: 35fb465
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Tue Jul 5 12:49:00 2016 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Tue Jul 5 12:49:00 2016 +0100

----------------------------------------------------------------------
 .../kerb/client/preauth/pkinit/PkinitPreauth.java   |  7 +++++--
 .../kerb/preauth/pkinit/CertificateHelper.java      | 16 ++++++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5c76b64f/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
index 9b37eb2..b47a46f 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/preauth/pkinit/PkinitPreauth.java
@@ -358,8 +358,11 @@ public class PkinitPreauth extends AbstractPreauthPlugin {
 
             X509Certificate x509Certificate = null;
             try {
-                x509Certificate = (X509Certificate) CertificateHelper.loadCerts(
-                        anchorFileName).iterator().next();
+                List<java.security.cert.Certificate> certs = 
+                    CertificateHelper.loadCerts(anchorFileName);
+                if (certs != null && !certs.isEmpty()) {
+                    x509Certificate = (X509Certificate) certs.iterator().next();
+                }
             } catch (KrbException e) {
                 e.printStackTrace();
             }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/5c76b64f/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
index db96ed6..53096d4 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/CertificateHelper.java
@@ -21,6 +21,7 @@ package org.apache.kerby.kerberos.kerb.preauth.pkinit;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
@@ -35,12 +36,19 @@ public class CertificateHelper {
 
 
     public static List<Certificate> loadCerts(String filename) throws KrbException {
+        
+        File file = new File(filename);
         InputStream res = null;
-        try {
-            res = new FileInputStream(filename);
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
+        if (file.isFile()) {
+            try {
+                res = new FileInputStream(file);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            }
+        } else {
+            res = CertificateHelper.class.getClassLoader().getResourceAsStream(filename);
         }
+        
         return loadCerts(res);
     }