directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [37/44] directory-kerby git commit: DIRKRB-587 - Load JWT verification key from classpath as well
Date Thu, 30 Jun 2016 08:54:24 GMT
DIRKRB-587 - Load JWT verification key from classpath as well


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

Branch: refs/heads/gssapi
Commit: 8aae07614df706a85490c3f303ea8cf075b29dba
Parents: 83ebd60
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Jun 15 17:29:55 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Jun 15 17:29:55 2016 +0100

----------------------------------------------------------------------
 .../kerb/server/preauth/token/TokenPreauth.java | 50 ++++++++++----------
 1 file changed, 24 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/8aae0761/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
index f4580fc..34fec85 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/preauth/token/TokenPreauth.java
@@ -48,6 +48,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.util.List;
@@ -123,39 +124,35 @@ public class TokenPreauth extends AbstractPreauthPlugin {
     private void configureKeys(TokenDecoder tokenDecoder, KdcRequest kdcRequest, String issuer)
{
         String verifyKeyPath = kdcRequest.getKdcContext().getConfig().getVerifyKeyConfig();
         if (verifyKeyPath != null) {
-            File verifyKeyFile = getKeyFile(verifyKeyPath, issuer);
-            if (verifyKeyFile != null) {
-                PublicKey verifyKey = null;
-                try {
-                    FileInputStream fis = new FileInputStream(verifyKeyFile);
-                    verifyKey = PublicKeyReader.loadPublicKey(fis);
-                } catch (FileNotFoundException e) {
-                    e.printStackTrace();
-                } catch (Exception e) {
-                    e.printStackTrace();
+            try {
+                InputStream verifyKeyFile = getKeyFileStream(verifyKeyPath, issuer);
+                if (verifyKeyFile != null) {
+                    PublicKey verifyKey = PublicKeyReader.loadPublicKey(verifyKeyFile);
+                    tokenDecoder.setVerifyKey(verifyKey);
                 }
-                tokenDecoder.setVerifyKey(verifyKey);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            } catch (Exception e) {
+                e.printStackTrace();
             }
         }
         String decryptionKeyPath = kdcRequest.getKdcContext().getConfig().getDecryptionKeyConfig();
         if (decryptionKeyPath != null) {
-            File decryptionKeyFile = getKeyFile(decryptionKeyPath, issuer);
-            if (decryptionKeyFile != null) {
-                PrivateKey decryptionKey = null;
-                try {
-                    FileInputStream fis = new FileInputStream(decryptionKeyFile);
-                    decryptionKey = PrivateKeyReader.loadPrivateKey(fis);
-                } catch (FileNotFoundException e) {
-                    e.printStackTrace();
-                } catch (Exception e) {
-                    e.printStackTrace();
+            try {
+                InputStream decryptionKeyFile = getKeyFileStream(decryptionKeyPath, issuer);
+                if (decryptionKeyFile != null) {
+                    PrivateKey decryptionKey = PrivateKeyReader.loadPrivateKey(decryptionKeyFile);
+                    tokenDecoder.setDecryptionKey(decryptionKey);
                 }
-                tokenDecoder.setDecryptionKey(decryptionKey);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            } catch (Exception e) {
+                e.printStackTrace();
             }
         }
     }
 
-    private File getKeyFile(String path, String issuer) {
+    private InputStream getKeyFileStream(String path, String issuer) throws FileNotFoundException
{
         File file = new File(path);
         if (file.isDirectory()) {
             File[] listOfFiles = file.listFiles();
@@ -170,11 +167,12 @@ public class TokenPreauth extends AbstractPreauthPlugin {
                     break;
                 }
             }
-            return verifyKeyFile;
+            return new FileInputStream(verifyKeyFile);
         } else if (file.isFile()) {
-            return file;
+            return new FileInputStream(file);
         }
         
-        return null;
+        // Not a directory or a file...maybe it's a resource on the classpath
+        return this.getClass().getClassLoader().getResourceAsStream(path);
     }
 }


Mime
View raw message