tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject [16/38] tomee git commit: TOMEE-2247 - Simplified public key reading from input stream.
Date Mon, 10 Dec 2018 14:47:19 GMT
TOMEE-2247 - Simplified public key reading from input stream.


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/66c93e86
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/66c93e86
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/66c93e86

Branch: refs/heads/master
Commit: 66c93e866a810be68c05cf029c63e21f33a6b951
Parents: 424e5d9
Author: Roberto Cortez <radcortez@yahoo.com>
Authored: Mon Sep 24 23:26:02 2018 +0100
Committer: Roberto Cortez <radcortez@yahoo.com>
Committed: Fri Dec 7 18:11:18 2018 +0000

----------------------------------------------------------------------
 .../config/ConfigurableJWTAuthContextInfo.java  | 49 +++++++-------------
 1 file changed, 16 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/66c93e86/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
----------------------------------------------------------------------
diff --git a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
index 3a6f34a..76d5a62 100644
--- a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
+++ b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
@@ -118,17 +118,7 @@ public class ConfigurableJWTAuthContextInfo {
             if (is == null) {
                 return Optional.empty();
             }
-
-            final StringWriter content = new StringWriter();
-            try (final BufferedReader reader = new BufferedReader(new InputStreamReader(is)))
{
-                String line = reader.readLine();
-                while (line != null) {
-                    content.write(line);
-                    content.write('\n');
-                    line = reader.readLine();
-                }
-            }
-            return Optional.of(content.toString());
+            return Optional.of(readPublicKeyFromInputStream(is));
         } catch (final IOException e) {
             throw new DeploymentException(
                     "Could not read MicroProfile Public Key from Location: " + publicKeyLocation,
e);
@@ -150,17 +140,7 @@ public class ConfigurableJWTAuthContextInfo {
                         publicKeyLocation +
                         ". File does not exist or it is a directory.");
             }
-
-            final StringWriter content = new StringWriter();
-            try (final BufferedReader reader = new BufferedReader(new InputStreamReader(locationURL.openStream())))
{
-                String line = reader.readLine();
-                while (line != null) {
-                    content.write(line);
-                    content.write('\n');
-                    line = reader.readLine();
-                }
-            }
-            return Optional.of(content.toString());
+            return Optional.of(readPublicKeyFromInputStream(locationURL.openStream()));
         } catch (final IOException | URISyntaxException e) {
             throw new DeploymentException(
                     "Could not read MicroProfile Public Key from Location: " + publicKeyLocation,
e);
@@ -174,17 +154,7 @@ public class ConfigurableJWTAuthContextInfo {
 
         try {
             final URL locationURL = new URL(publicKeyLocation);
-
-            final StringWriter content = new StringWriter();
-            try (final BufferedReader reader = new BufferedReader(new InputStreamReader(locationURL.openStream())))
{
-                String line = reader.readLine();
-                while (line != null) {
-                    content.write(line);
-                    content.write('\n');
-                    line = reader.readLine();
-                }
-            }
-            return Optional.of(content.toString());
+            return Optional.of(readPublicKeyFromInputStream(locationURL.openStream()));
         } catch (final IOException e) {
             throw new DeploymentException(
                     "Could not read MicroProfile Public Key from Location: " + publicKeyLocation,
e);
@@ -195,6 +165,19 @@ public class ConfigurableJWTAuthContextInfo {
         return Optional.empty();
     }
 
+    private String readPublicKeyFromInputStream(final InputStream publicKey) throws IOException
{
+        final StringWriter content = new StringWriter();
+        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(publicKey)))
{
+            String line = reader.readLine();
+            while (line != null) {
+                content.write(line);
+                content.write('\n');
+                line = reader.readLine();
+            }
+        }
+        return content.toString();
+    }
+
     private RSAPublicKey parsePCKS8(final String publicKey) {
         isPrivatePCKS8(publicKey);
         try {


Mime
View raw message