TOMEE-2247 - Support to load keys from generic Urls.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/01c2fb67 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/01c2fb67 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/01c2fb67 Branch: refs/heads/master Commit: 01c2fb6725f1e2b132e1743236b24de902610dda Parents: e3aaa33 Author: Roberto Cortez <[email protected]> Authored: Tue Sep 25 12:06:31 2018 +0100 Committer: Roberto Cortez <[email protected]> Committed: Fri Dec 7 18:11:18 2018 +0000 ---------------------------------------------------------------------- .../jwt/config/ConfigurableJWTAuthContextInfo.java | 10 ++++++++-- .../tck/jwt/MicroProfileJWTTCKArchiveProcessor.java | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/01c2fb67/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 dd2e74f..ede66b4 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 @@ -179,7 +179,13 @@ public class ConfigurableJWTAuthContextInfo { } private Optional<String> readPublicKeyFromUrl(final String publicKeyLocation) { - return Optional.empty(); + try { + final URL locationURL = new URL(publicKeyLocation); + return Optional.of(readPublicKeyFromInputStream(locationURL.openStream())); + } catch (final IOException e) { + throw new DeploymentException( + "Could not read MicroProfile Public Key from Location: " + publicKeyLocation, e); + } } private String readPublicKeyFromInputStream(final InputStream publicKey) throws IOException { @@ -200,7 +206,7 @@ public class ConfigurableJWTAuthContextInfo { final X509EncodedKeySpec spec = new X509EncodedKeySpec(normalizeAndDecodePCKS8(publicKey)); final KeyFactory kf = KeyFactory.getInstance("RSA"); return Optional.of((RSAPublicKey) kf.generatePublic(spec)); - } catch (final NoSuchAlgorithmException | InvalidKeySpecException e) { + } catch (final NoSuchAlgorithmException | InvalidKeySpecException | IllegalArgumentException e) { return Optional.empty(); } } http://git-wip-us.apache.org/repos/asf/tomee/blob/01c2fb67/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java index ab98f42..efe9bf0 100644 --- a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java @@ -23,6 +23,7 @@ import org.apache.tomee.arquillian.remote.RemoteTomEEContainer; import org.eclipse.microprofile.jwt.tck.config.IssValidationTest; import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsBase64JWKTest; import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsFileLocationURLTest; +import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsJWKLocationTest; import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMLocationTest; import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMTest; import org.eclipse.microprofile.jwt.tck.util.TokenUtils; @@ -72,6 +73,7 @@ public class MicroProfileJWTTCKArchiveProcessor implements ApplicationArchivePro PublicKeyAsPEMLocationTest.class, PublicKeyAsFileLocationURLTest.class, PublicKeyAsBase64JWKTest.class, + PublicKeyAsJWKLocationTest.class, IssValidationTest.class, org.apache.tomee.microprofile.tck.jwt.config.PublicKeyAsPEMLocationTest.class) .filter(c -> c.equals(testClass.getJavaClass()))
