From 16e7e1e0a9a6f4015fe7f79b20668ec2c75d0e71 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Thu, 11 Apr 2024 14:57:33 +0100 Subject: [PATCH] Remove Sandbox --- sandbox/README.adoc | 24 -- sandbox/pom.xml | 128 ---------- .../JWTAuthenticationMechanismDefinition.java | 33 --- .../config/PrivateKeyConverter.java | 53 ----- .../config/PublicKeyConverter.java | 52 ---- .../authentication/config/TokenUtils.java | 130 ---------- .../src/test/java/cdi/WeldJUnit4Runner.java | 78 ------ .../src/test/java/config/package-info.java | 25 -- .../java/config/seimpl/DefaultConfig.java | 225 ------------------ .../config/seimpl/DefaultConfigBuilder.java | 118 --------- .../seimpl/DefaultConfigProviderResolver.java | 62 ----- .../config/seimpl/DefaultMPConfigSource.java | 66 ----- .../config/seimpl/SystemEnvConfigSource.java | 50 ---- .../seimpl/SystemPropertyConfigSource.java | 52 ---- .../config/seimpl/cdi/ConfigProducer.java | 53 ----- .../cdi/ConfigPropertyBeanAttribute.java | 90 ------- .../seimpl/cdi/ConfigPropertyProducer.java | 123 ---------- .../config/seimpl/cdi/MPConfigExtension.java | 115 --------- .../seimpl/converters/BooleanConverter.java | 34 --- .../seimpl/converters/ByteConverter.java | 34 --- .../seimpl/converters/CharacterConverter.java | 34 --- .../seimpl/converters/DoubleConverter.java | 34 --- .../seimpl/converters/DurationConverter.java | 36 --- .../seimpl/converters/FloatConverter.java | 34 --- .../seimpl/converters/InstantConverter.java | 36 --- .../seimpl/converters/IntegerConverter.java | 34 --- .../converters/LocalDateTimeConverter.java | 36 --- .../seimpl/converters/LongConverter.java | 34 --- .../seimpl/converters/ShortConverter.java | 34 --- .../converters/StringArrayConverter.java | 31 --- sandbox/src/test/java/issue62/AuthConfig.java | 81 ------- .../src/test/java/issue62/AuthConfigTest.java | 64 ----- .../src/test/java/issue62/SomeAuthMech.java | 34 --- .../src/test/java/jwks/AbstractJWKSTest.java | 172 ------------- sandbox/src/test/java/jwks/Auth0JWKSTest.java | 80 ------- sandbox/src/test/java/jwks/JWKSResTest.java | 129 ---------- sandbox/src/test/java/jwks/JWKxPEMTest.java | 127 ---------- .../src/test/java/jwks/Jose4jJWKSTest.java | 80 ------- .../src/test/java/jwks/NimbusJWKSTest.java | 95 -------- .../test/java/jwt/AbstractVerifierTest.java | 126 ---------- .../src/test/java/jwt/Auth0VerifierTest.java | 42 ---- .../src/test/java/jwt/JjwtVerifierTest.java | 50 ---- .../src/test/java/jwt/Jose4jVerifierTest.java | 58 ----- .../src/test/java/jwt/NimbusVerifierTest.java | 91 ------- sandbox/src/test/java/url/jwks/Handler.java | 35 --- .../test/java/url/jwks/JwksURLConnection.java | 77 ------ .../src/test/java/url/pemjwks/Handler.java | 35 --- .../url/pemjwks/PemJwksURLConnection.java | 153 ------------ sandbox/src/test/resources/META-INF/beans.xml | 21 -- .../META-INF/microprofile-config.properties | 26 -- .../javax.enterprise.inject.spi.Extension | 1 - ...oprofile.config.spi.ConfigProviderResolver | 1 - ....eclipse.microprofile.config.spi.Converter | 2 - sandbox/src/test/resources/Token1.json | 63 ----- sandbox/src/test/resources/privateKey.pem | 28 --- sandbox/src/test/resources/privateKey4k.pem | 52 ---- sandbox/src/test/resources/publicKey.pem | 9 - sandbox/src/test/resources/publicKey4k.pem | 14 -- sandbox/src/test/resources/signer-keypair.jwk | 9 - sandbox/src/test/resources/signer-keyset.jwk | 12 - .../src/test/resources/signer-keyset4k.jwk | 12 - sandbox/src/test/resources/signer.jwk | 8 - 62 files changed, 3675 deletions(-) delete mode 100644 sandbox/README.adoc delete mode 100644 sandbox/pom.xml delete mode 100644 sandbox/src/main/java/org/eclipse/microprofile/authentication/JWTAuthenticationMechanismDefinition.java delete mode 100644 sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PrivateKeyConverter.java delete mode 100644 sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PublicKeyConverter.java delete mode 100644 sandbox/src/main/java/org/eclipse/microprofile/authentication/config/TokenUtils.java delete mode 100644 sandbox/src/test/java/cdi/WeldJUnit4Runner.java delete mode 100644 sandbox/src/test/java/config/package-info.java delete mode 100644 sandbox/src/test/java/config/seimpl/DefaultConfig.java delete mode 100644 sandbox/src/test/java/config/seimpl/DefaultConfigBuilder.java delete mode 100644 sandbox/src/test/java/config/seimpl/DefaultConfigProviderResolver.java delete mode 100644 sandbox/src/test/java/config/seimpl/DefaultMPConfigSource.java delete mode 100644 sandbox/src/test/java/config/seimpl/SystemEnvConfigSource.java delete mode 100644 sandbox/src/test/java/config/seimpl/SystemPropertyConfigSource.java delete mode 100644 sandbox/src/test/java/config/seimpl/cdi/ConfigProducer.java delete mode 100644 sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyBeanAttribute.java delete mode 100644 sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyProducer.java delete mode 100644 sandbox/src/test/java/config/seimpl/cdi/MPConfigExtension.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/BooleanConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/ByteConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/CharacterConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/DoubleConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/DurationConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/FloatConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/InstantConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/IntegerConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/LocalDateTimeConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/LongConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/ShortConverter.java delete mode 100644 sandbox/src/test/java/config/seimpl/converters/StringArrayConverter.java delete mode 100644 sandbox/src/test/java/issue62/AuthConfig.java delete mode 100644 sandbox/src/test/java/issue62/AuthConfigTest.java delete mode 100644 sandbox/src/test/java/issue62/SomeAuthMech.java delete mode 100644 sandbox/src/test/java/jwks/AbstractJWKSTest.java delete mode 100644 sandbox/src/test/java/jwks/Auth0JWKSTest.java delete mode 100644 sandbox/src/test/java/jwks/JWKSResTest.java delete mode 100644 sandbox/src/test/java/jwks/JWKxPEMTest.java delete mode 100644 sandbox/src/test/java/jwks/Jose4jJWKSTest.java delete mode 100644 sandbox/src/test/java/jwks/NimbusJWKSTest.java delete mode 100644 sandbox/src/test/java/jwt/AbstractVerifierTest.java delete mode 100644 sandbox/src/test/java/jwt/Auth0VerifierTest.java delete mode 100644 sandbox/src/test/java/jwt/JjwtVerifierTest.java delete mode 100644 sandbox/src/test/java/jwt/Jose4jVerifierTest.java delete mode 100644 sandbox/src/test/java/jwt/NimbusVerifierTest.java delete mode 100644 sandbox/src/test/java/url/jwks/Handler.java delete mode 100644 sandbox/src/test/java/url/jwks/JwksURLConnection.java delete mode 100644 sandbox/src/test/java/url/pemjwks/Handler.java delete mode 100644 sandbox/src/test/java/url/pemjwks/PemJwksURLConnection.java delete mode 100644 sandbox/src/test/resources/META-INF/beans.xml delete mode 100644 sandbox/src/test/resources/META-INF/microprofile-config.properties delete mode 100644 sandbox/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension delete mode 100644 sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver delete mode 100644 sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter delete mode 100644 sandbox/src/test/resources/Token1.json delete mode 100644 sandbox/src/test/resources/privateKey.pem delete mode 100644 sandbox/src/test/resources/privateKey4k.pem delete mode 100644 sandbox/src/test/resources/publicKey.pem delete mode 100644 sandbox/src/test/resources/publicKey4k.pem delete mode 100644 sandbox/src/test/resources/signer-keypair.jwk delete mode 100644 sandbox/src/test/resources/signer-keyset.jwk delete mode 100644 sandbox/src/test/resources/signer-keyset4k.jwk delete mode 100644 sandbox/src/test/resources/signer.jwk diff --git a/sandbox/README.adoc b/sandbox/README.adoc deleted file mode 100644 index 406a4401..00000000 --- a/sandbox/README.adoc +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) 2016-2017 Contributors to the Eclipse Foundation -// -// See the NOTICES file(s) distributed with this work for additional -// information regarding copyright ownership. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -# JWT RBAC for MicroProfile Sandbox - -This subproject is not part of the microprofile-jwt-auth release. It is used to -prototype features under development for future releases. - diff --git a/sandbox/pom.xml b/sandbox/pom.xml deleted file mode 100644 index afd63d8f..00000000 --- a/sandbox/pom.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - 4.0.0 - - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-parent - 1.1-SNAPSHOT - - - microprofile-jwt-auth-sandbox - 1.1-SNAPSHOT - MicroProfile JWT Auth Sandbox - Eclipse MicroProfile JWT Feature - Sandbox - - - true - true - 0.6.2 - 4.23 - 3.3.0 - 0.9.0 - - - - - javax.json - javax.json-api - 1.0 - provided - - - javax.enterprise - cdi-api - 1.2 - provided - - - org.glassfish - javax.json - 1.0.4 - - - org.eclipse.microprofile.config - microprofile-config-api - 1.2.1 - - - org.jboss.weld.se - weld-se-core - 2.4.6.Final - test - - - junit - junit - 4.12 - test - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-api - 1.1-SNAPSHOT - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-tck - 1.1-SNAPSHOT - - - org.bitbucket.b_c - jose4j - ${version.jose4j} - - - com.nimbusds - nimbus-jose-jwt - ${version.numbusds} - - - com.auth0 - java-jwt - ${version.auth0} - - - com.auth0 - jwks-rsa - 0.3.0 - - - io.jsonwebtoken - jjwt - ${version.jsonwebtoken} - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - - - diff --git a/sandbox/src/main/java/org/eclipse/microprofile/authentication/JWTAuthenticationMechanismDefinition.java b/sandbox/src/main/java/org/eclipse/microprofile/authentication/JWTAuthenticationMechanismDefinition.java deleted file mode 100644 index d491e178..00000000 --- a/sandbox/src/main/java/org/eclipse/microprofile/authentication/JWTAuthenticationMechanismDefinition.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.eclipse.microprofile.authentication; - - -import org.eclipse.microprofile.jwt.config.Names; - -/** - * Annotation used to define a container AuthenticationMechanism that implements the MP-JWT authentication protocol as defined - * by the Microprofile JWT RBAC spec and makes that implementation available as an enabled CDI bean. - */ -public @interface JWTAuthenticationMechanismDefinition { - String verifierKey() default "#{MPConfig.config["+ Names.VERIFIER_PUBLIC_KEY +"]}"; - String acceptedIssuer() default "#{MPConfig.config["+ Names.ISSUER +"]}"; - int clockSkew() default 30; -} diff --git a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PrivateKeyConverter.java b/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PrivateKeyConverter.java deleted file mode 100644 index 41e46cb3..00000000 --- a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PrivateKeyConverter.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.eclipse.microprofile.authentication.config; - -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -import java.security.PrivateKey; - -import org.eclipse.microprofile.config.spi.Converter; - -import static org.eclipse.microprofile.authentication.config.TokenUtils.decodePrivateKey; - -/** - * A custom configuration converter for {@linkplain PrivateKey} injection using - * {@linkplain org.eclipse.microprofile.config.inject.ConfigProperty} - */ -public class PrivateKeyConverter implements Converter { - /** - * Converts a string to a PrivateKey by loading it as a classpath resource - * @param value - the string value to convert - * @return the PrivateKey loaded as a resource - * @throws IllegalArgumentException - on failure to load the key - */ - @Override - public PrivateKey convert(String value) throws IllegalArgumentException { - - PrivateKey pk = null; - try { - pk = decodePrivateKey(value); - } - catch (Exception e) { - IllegalArgumentException ex = new IllegalArgumentException("Failed to parse "); - ex.initCause(e); - throw ex; - } - return pk; - } -} diff --git a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PublicKeyConverter.java b/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PublicKeyConverter.java deleted file mode 100644 index 42f38229..00000000 --- a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/PublicKeyConverter.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.eclipse.microprofile.authentication.config; - -import java.security.PublicKey; - -import org.eclipse.microprofile.config.spi.Converter; - -import static org.eclipse.microprofile.authentication.config.TokenUtils.decodePublicKey; - -/** - * A custom configuration converter for {@linkplain PublicKey} injection using - * {@linkplain org.eclipse.microprofile.config.inject.ConfigProperty} - */ -public class PublicKeyConverter implements Converter { - /** - * Converts a string to a PublicKey by loading it as a classpath resource - * @param value - the PEM encoded string value to convert - * @return the PublicKey loaded as a resource - * @throws IllegalArgumentException - on failure to load the key - */ - @Override - public PublicKey convert(String value) throws IllegalArgumentException { - PublicKey pk; - try { - pk = decodePublicKey(value); - } - catch (Exception e) { - IllegalArgumentException ex = new IllegalArgumentException("Failed to parse: "+value); - ex.initCause(e); - throw ex; - } - return pk; - } -} diff --git a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/TokenUtils.java b/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/TokenUtils.java deleted file mode 100644 index 492c8d68..00000000 --- a/sandbox/src/main/java/org/eclipse/microprofile/authentication/config/TokenUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.eclipse.microprofile.authentication.config; - -import java.io.InputStream; -import java.security.KeyFactory; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; -import java.util.Base64; - -/** - * Key parsing related utilties - */ -public class TokenUtils { - private TokenUtils() { - } - - /** - * Read a PEM encoded private key from the classpath - * @param pemResName - key file resource name - * @return PrivateKey - * @throws Exception on decode failure - */ - public static PrivateKey readPrivateKey(String pemResName) throws Exception { - InputStream contentIS = TokenUtils.class.getResourceAsStream(pemResName); - byte[] tmp = new byte[4096]; - int length = contentIS.read(tmp); - PrivateKey privateKey = decodePrivateKey(new String(tmp, 0, length)); - return privateKey; - } - /** - * Read a PEM encoded public key from the classpath - * @param pemResName - key file resource name - * @return PublicKey - * @throws Exception on decode failure - */ - public static PublicKey readPublicKey(String pemResName) throws Exception { - InputStream contentIS = TokenUtils.class.getResourceAsStream(pemResName); - byte[] tmp = new byte[4096]; - int length = contentIS.read(tmp); - PublicKey publicKey = decodePublicKey(new String(tmp, 0, length)); - return publicKey; - } - - /** - * Generate a new RSA keypair. - * @param keySize - the size of the key - * @return KeyPair - * @throws NoSuchAlgorithmException on failure to load RSA key generator - */ - public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { - KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); - keyPairGenerator.initialize(keySize); - KeyPair keyPair = keyPairGenerator.genKeyPair(); - return keyPair; - } - - /** - * Decode a PEM encoded private key string to an RSA PrivateKey - * @param pemEncoded - PEM string for private key - * @return PrivateKey - * @throws Exception on decode failure - */ - public static PrivateKey decodePrivateKey(String pemEncoded) throws Exception { - pemEncoded = removeBeginEnd(pemEncoded); - byte[] pkcs8EncodedBytes = Base64.getDecoder().decode(pemEncoded); - - // extract the private key - - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8EncodedBytes); - KeyFactory kf = KeyFactory.getInstance("RSA"); - PrivateKey privKey = kf.generatePrivate(keySpec); - return privKey; - } - - /** - * Decode a PEM encoded public key string to an RSA PublicKey - * @param pemEncoded - PEM string for private key - * @return PublicKey - * @throws Exception on decode failure - */ - public static PublicKey decodePublicKey(String pemEncoded) throws Exception { - pemEncoded = removeBeginEnd(pemEncoded); - byte[] encodedBytes = Base64.getDecoder().decode(pemEncoded); - - X509EncodedKeySpec spec = new X509EncodedKeySpec(encodedBytes); - KeyFactory kf = KeyFactory.getInstance("RSA"); - return kf.generatePublic(spec); - } - - private static String removeBeginEnd(String pem) { - pem = pem.replaceAll("-----BEGIN (.*)-----", ""); - pem = pem.replaceAll("-----END (.*)----", ""); - pem = pem.replaceAll("\r\n", ""); - pem = pem.replaceAll("\n", ""); - return pem.trim(); - } - - /** - * @return the current time in seconds since epoch - */ - public static int currentTimeInSecs() { - long currentTimeMS = System.currentTimeMillis(); - int currentTimeSec = (int) (currentTimeMS / 1000); - return currentTimeSec; - } - -} diff --git a/sandbox/src/test/java/cdi/WeldJUnit4Runner.java b/sandbox/src/test/java/cdi/WeldJUnit4Runner.java deleted file mode 100644 index 3f04c21b..00000000 --- a/sandbox/src/test/java/cdi/WeldJUnit4Runner.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package cdi; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.jboss.weld.environment.se.Weld; -import org.jboss.weld.environment.se.WeldContainer; -import org.jboss.weld.environment.se.WeldSEProvider; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.InitializationError; - -import javax.enterprise.inject.spi.CDI; - -/** - * A simple runner that boots up the Weld Java SE container - */ -public class WeldJUnit4Runner extends BlockJUnit4ClassRunner { - - private final Class klass; - private final Weld weld; - private final WeldContainer container; - - /** - * A little utility method that configures the JDK root and Weld root loggers for the given log level. It also - * sets the handler associated with the JDK root logger to this level. Typically this is only useful when - * called with a {@link Level#FINE} level or more verbose. - * @param level the logger level to set - */ - public static void enableJDKConsoleLogging(Level level) { - // Set up the root and org.jboss.weld logger to level and override the ConsoleHandler level to level - Logger rootLog = Logger.getLogger(""); - rootLog.setLevel( level ); - rootLog.getHandlers()[0].setLevel( level); - Logger.getLogger("org.jboss.weld").setLevel(Level.ALL); - } - - public WeldJUnit4Runner(final Class klass) throws InitializationError { - super(klass); - this.klass = klass; - // Uncomment to enable verbose tracing of CDI - //enableJDKConsoleLogging(Level.FINEST); - this.weld = new Weld(); - /* Use this to put the Weld container in development with export of the trace information to the /tmp directory - this.weld = new Weld().property("org.jboss.weld.development", true) - .property("org.jboss.weld.probe.exportDataAfterDeployment", "/tmp/"); - */ - this.container = weld.initialize(); - // This is currently needed in order for a class called by the ServiceLoader to be able to access the CDI instance - WeldSEProvider cdi = new WeldSEProvider(); - CDI.setCDIProvider(cdi); - } - - @Override - protected Object createTest() throws Exception { - final Object test = container.select(klass).get(); - - return test; - } -} diff --git a/sandbox/src/test/java/config/package-info.java b/sandbox/src/test/java/config/package-info.java deleted file mode 100644 index 48fd52b2..00000000 --- a/sandbox/src/test/java/config/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -/** - * A simple Java SE partial implementation of the MP config spec. - *

- * See microprofile-config-weld-se - */ -package config; diff --git a/sandbox/src/test/java/config/seimpl/DefaultConfig.java b/sandbox/src/test/java/config/seimpl/DefaultConfig.java deleted file mode 100644 index 43466ae4..00000000 --- a/sandbox/src/test/java/config/seimpl/DefaultConfig.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl; - -import java.io.IOException; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.SortedSet; -import java.util.concurrent.ConcurrentSkipListSet; - -import javax.enterprise.inject.Vetoed; - -import config.seimpl.converters.StringArrayConverter; -import org.eclipse.microprofile.config.Config; -import config.seimpl.converters.BooleanConverter; -import config.seimpl.converters.ByteConverter; -import config.seimpl.converters.CharacterConverter; -import config.seimpl.converters.DoubleConverter; -import config.seimpl.converters.DurationConverter; -import config.seimpl.converters.FloatConverter; -import config.seimpl.converters.IntegerConverter; -import config.seimpl.converters.LocalDateTimeConverter; -import config.seimpl.converters.LongConverter; -import config.seimpl.converters.ShortConverter; -import org.eclipse.microprofile.config.spi.ConfigSource; -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/1/17. - */ -@Vetoed -public class DefaultConfig implements Config { - private static SystemEnvConfigSource systemEnvCS = new SystemEnvConfigSource(); - private static SystemPropertyConfigSource systemPropertyCS = new SystemPropertyConfigSource(); - - /** - * The list of ConfigSource objects ordered by their ordinal value - */ - private SortedSet sources = new ConcurrentSkipListSet<>(Comparator.comparing(ConfigSource::getOrdinal)); - private HashMap converters = new HashMap<>(); - - DefaultConfig() { - loadStandardConverters(); - } - DefaultConfig(List sources) { - this.sources.addAll(sources); - loadStandardConverters(); - } - - public void loadStandardSources(ClassLoader loader) { - if(loader == null) { - loader = getClass().getClassLoader(); - } - sources.add(systemPropertyCS); - System.out.printf("Added System property ConfigSource\n"); - sources.add(systemEnvCS); - System.out.printf("Added System environment ConfigSource\n"); - try { - sources.add(new DefaultMPConfigSource(loader)); - System.out.printf("Added META-INF/microprofile-config.properties ConfigSource\n"); - } - catch (IOException e) { - // Ignore - } - } - - public void loadStandardConverters() { - converters.put(Boolean.class, new BooleanConverter()); - converters.put(boolean.class, new BooleanConverter()); - converters.put(Character.class, new CharacterConverter()); - converters.put(char.class, new CharacterConverter()); - converters.put(Byte.class, new ByteConverter()); - converters.put(byte.class, new ByteConverter()); - converters.put(Short.class, new ShortConverter()); - converters.put(short.class, new ShortConverter()); - converters.put(Integer.class, new IntegerConverter()); - converters.put(int.class, new IntegerConverter()); - converters.put(Long.class, new LongConverter()); - converters.put(long.class, new LongConverter()); - converters.put(Float.class, new FloatConverter()); - converters.put(float.class, new FloatConverter()); - converters.put(Double.class, new DoubleConverter()); - converters.put(double.class, new DoubleConverter()); - converters.put(Duration.class, new DurationConverter()); - converters.put(LocalDateTime.class, new LocalDateTimeConverter()); - converters.put(String[].class, new StringArrayConverter()); - } - - /** - * Use the {@link Converter}s registered with the config to convert a String value to a target property type. - * @param svalue - the string value representation of the property - * @param propertyType - the desired Java type of the property - * @return the converted value - * @throws TypeNotPresentException if there is no registered Converter - */ - public T convertValue(String svalue, Class propertyType) { - T value = null; - if(propertyType.isAssignableFrom(String.class)) { - value = propertyType.cast(svalue); - } - else { - Converter converter = converters.get(propertyType); - if(converter != null) { - value = converter.convert(svalue); - } - else { - System.err.printf("Failed to find Converter for type: %s\n", propertyType); - throw new TypeNotPresentException(propertyType.getTypeName(), null); - } - } - return value; - } - - /** - * Use the {@link Converter}s registered with the config to try to convert a String value to a target property type. - * @param svalue - the string value representation of the property - * @param propertyType - the desired Java type of the property - * @return the converted value if a matching converter is found, Optional.empty() otherwise - */ - public Optional tryConvertValue(String svalue, Class propertyType) { - Optional value = Optional.empty(); - if(propertyType.isAssignableFrom(String.class)) { - value = Optional.of((T)svalue); - } - else { - Converter converter = converters.get(propertyType); - if(converter != null) { - value = Optional.of(converter.convert(svalue)); - } - else { - System.err.printf("Failed to find Converter for type: %s\n", propertyType); - } - } - return value; - } - - /** - * Add a new ConfigSource. This will be added to the existing sources based on the {@link ConfigSource#getOrdinal()} value. - * @param cs the ConfigSource to add - * @return true if the ConfigSource was added, false otherwise - */ - public boolean addConfigSource(ConfigSource cs) { - return sources.add(cs); - } - public void addConverter(Converter converter) { - // Determine the target type of the converter - Type[] genericInterfaces = converter.getClass().getGenericInterfaces(); - for(Type type : genericInterfaces) { - if(type instanceof ParameterizedType) { - ParameterizedType ptype = (ParameterizedType) type; - if(ptype.getRawType().equals(Converter.class)) { - Type actualType = ptype.getActualTypeArguments()[0]; - converters.put(actualType, converter); - System.out.printf("+++ Added converter(%s) for type: %s\n", converter, actualType); - } - } - } - } - - @Override - public T getValue(String propertyName, Class propertyType) { - T value = getOptionalValue(propertyName, propertyType).orElse(null); - return value; - } - - @Override - public Optional getOptionalValue(String propertyName, Class propertyType) { - Optional value = Optional.empty(); - for (ConfigSource cs : sources) { - String svalue = cs.getValue(propertyName); - if(svalue == null) { - value = Optional.empty(); - } - else if(propertyType.isAssignableFrom(String.class)) { - value = Optional.of(propertyType.cast(svalue)); - break; - } - else { - Converter converter = converters.get(propertyType); - if(converter != null) { - value = Optional.of(converter.convert(svalue)); - } - else { - System.err.printf("Failed to find Converter for: %s of type: %s\n", propertyName, propertyType); - } - break; - } - } - return value; - } - - @Override - public Iterable getPropertyNames() { - return null; - } - - @Override - public Iterable getConfigSources() { - return sources; - } -} diff --git a/sandbox/src/test/java/config/seimpl/DefaultConfigBuilder.java b/sandbox/src/test/java/config/seimpl/DefaultConfigBuilder.java deleted file mode 100644 index 24fe937e..00000000 --- a/sandbox/src/test/java/config/seimpl/DefaultConfigBuilder.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl; - -import java.net.URL; -import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.ServiceLoader; - -import javax.enterprise.inject.spi.BeanManager; -import javax.inject.Inject; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigBuilder; -import org.eclipse.microprofile.config.spi.ConfigSource; -import org.eclipse.microprofile.config.spi.Converter; - -/** - * The Weld/JavaSE ConfigBuilder implementation. It configures a {@link DefaultConfig} instance. - */ -public class DefaultConfigBuilder implements ConfigBuilder { - @Inject - private BeanManager beanManager; - private DefaultConfig config = new DefaultConfig(); - private ClassLoader loader; - - public DefaultConfigBuilder() { - loader = AccessController.doPrivileged((PrivilegedAction) () -> Thread.currentThread().getContextClassLoader()); - } - @Override - public ConfigBuilder addDefaultSources() { - config.loadStandardSources(loader); - return this; - } - - @Override - public ConfigBuilder addDiscoveredSources() { - boolean debugClassLoader = Boolean.getBoolean("config.seimpl.debugClassLoader"); - if(debugClassLoader) { - System.out.printf("ClassLoader: %s\n", loader); - if (loader instanceof URLClassLoader) { - URLClassLoader urlClassLoader = (URLClassLoader) loader; - URL[] urls = urlClassLoader.getURLs(); - for (URL url : urls) { - System.out.printf("\t: %s\n", url); - } - } - } - ServiceLoader sources = ServiceLoader.load(ConfigSource.class, loader); - int count = 0; - for(ConfigSource cs : sources) { - config.addConfigSource(cs); - count ++; - } - System.out.printf("Discovered %d additional ConfigSource\n", count); - return this; - } - - @Override - public ConfigBuilder addDiscoveredConverters() { - ServiceLoader converters = ServiceLoader.load(Converter.class, loader); - converters.forEach(converter -> config.addConverter(converter)); - return this; - } - - @Override - public ConfigBuilder forClassLoader(ClassLoader loader) { - this.loader = loader; - return this; - } - - @Override - public ConfigBuilder withSources(ConfigSource... sources) { - for(ConfigSource cs : sources) { - config.addConfigSource(cs); - } - return this; - } - - @Override - public ConfigBuilder withConverters(Converter[] converters) { - for(Converter converter : converters) { - config.addConverter(converter); - } - return this; - } - - @Override - public Config build() { - return config; - } - - @Override - public ConfigBuilder withConverter(Class type, int priority, Converter converter) { - config.addConverter(converter); - return this; - } -} diff --git a/sandbox/src/test/java/config/seimpl/DefaultConfigProviderResolver.java b/sandbox/src/test/java/config/seimpl/DefaultConfigProviderResolver.java deleted file mode 100644 index 590c61f8..00000000 --- a/sandbox/src/test/java/config/seimpl/DefaultConfigProviderResolver.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl; - -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigBuilder; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; - -/** - * Created by starksm on 6/1/17. - */ -public class DefaultConfigProviderResolver extends ConfigProviderResolver { - - @Override - public Config getConfig() { - ClassLoader loader = AccessController.doPrivileged((PrivilegedAction) () -> Thread.currentThread().getContextClassLoader()); - return getConfig(loader); - } - - @Override - public Config getConfig(ClassLoader loader) { - DefaultConfig config = new DefaultConfig(); - config.loadStandardSources(loader); - return config; - } - - @Override - public ConfigBuilder getBuilder() { - return new DefaultConfigBuilder(); - } - - @Override - public void registerConfig(Config config, ClassLoader classLoader) { - - } - - @Override - public void releaseConfig(Config config) { - - } -} diff --git a/sandbox/src/test/java/config/seimpl/DefaultMPConfigSource.java b/sandbox/src/test/java/config/seimpl/DefaultMPConfigSource.java deleted file mode 100644 index 1be1aa91..00000000 --- a/sandbox/src/test/java/config/seimpl/DefaultMPConfigSource.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.eclipse.microprofile.config.spi.ConfigSource; - -/** - * A default implementation of a ConfigSource that loads configuration from /META-INF/microprofile-config.properties - */ -public class DefaultMPConfigSource implements ConfigSource { - private URL mpcURL; - private HashMap properties = new HashMap<>(); - - DefaultMPConfigSource(ClassLoader loader) throws IOException { - mpcURL = loader.getResource("META-INF/microprofile-config.properties"); - Properties tmp = new Properties(); - if(mpcURL != null) { - tmp.load(mpcURL.openStream()); - } - tmp.forEach((key, value) -> properties.put((String) key, (String) value)); - } - - @Override - public int getOrdinal() { - return 100; - } - @Override - public Map getProperties() { - return properties; - } - - @Override - public String getValue(String propertyName) { - String propertyVaue = properties.get(propertyName); - return propertyVaue; - } - - @Override - public String getName() { - return mpcURL != null ? mpcURL.toExternalForm() : "NONE"; - } -} diff --git a/sandbox/src/test/java/config/seimpl/SystemEnvConfigSource.java b/sandbox/src/test/java/config/seimpl/SystemEnvConfigSource.java deleted file mode 100644 index f84f79c0..00000000 --- a/sandbox/src/test/java/config/seimpl/SystemEnvConfigSource.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl; - -import java.util.Map; - -import org.eclipse.microprofile.config.spi.ConfigSource; - -/** - * Created by starksm on 6/1/17. - */ -public class SystemEnvConfigSource implements ConfigSource { - @Override - public int getOrdinal() { - return 300; - } - - @Override - public Map getProperties() { - return System.getenv(); - } - - @Override - public String getValue(String propertyName) { - return System.getenv(propertyName); - } - - @Override - public String getName() { - return "java.lang.System#getenv"; - } -} diff --git a/sandbox/src/test/java/config/seimpl/SystemPropertyConfigSource.java b/sandbox/src/test/java/config/seimpl/SystemPropertyConfigSource.java deleted file mode 100644 index 85ca2613..00000000 --- a/sandbox/src/test/java/config/seimpl/SystemPropertyConfigSource.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.microprofile.config.spi.ConfigSource; - -/** - * Created by starksm on 6/1/17. - */ -public class SystemPropertyConfigSource implements ConfigSource { - @Override - public int getOrdinal() { - return 400; - } - @Override - public Map getProperties() { - HashMap props = new HashMap<>(); - System.getProperties().putAll(props); - return props; - } - - @Override - public String getValue(String propertyName) { - return System.getProperty(propertyName); - } - - @Override - public String getName() { - return "java.lang.System#getProperties()"; - } -} diff --git a/sandbox/src/test/java/config/seimpl/cdi/ConfigProducer.java b/sandbox/src/test/java/config/seimpl/cdi/ConfigProducer.java deleted file mode 100644 index 69e3915e..00000000 --- a/sandbox/src/test/java/config/seimpl/cdi/ConfigProducer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.cdi; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.Dependent; -import javax.enterprise.inject.Produces; -import javax.enterprise.inject.spi.InjectionPoint; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; - -/** - * A producer for the application Config instance. - */ -public class ConfigProducer { - private Config config; - - @PostConstruct - void init() { - config = ConfigProviderResolver.instance().getBuilder() - .addDefaultSources() - .addDiscoveredSources() - .addDiscoveredConverters() - .build(); - } - - @Produces - @Dependent - Config produceConfig(InjectionPoint injectionPoint) { - System.out.printf("produceConfig: %s\n", injectionPoint); - return config; - } -} diff --git a/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyBeanAttribute.java b/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyBeanAttribute.java deleted file mode 100644 index 82dffa69..00000000 --- a/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyBeanAttribute.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.cdi; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Set; - -import javax.enterprise.inject.spi.BeanAttributes; - -/** - * Implementation of {@link BeanAttributes} SPI to decorate an existing

BeanAttributes
- * by replacing its type set with the full set of @ConfigProperty injection target site types. Based on the converter example - * in the CDI-Sandbox(https://github.com/starksm64/CDI-Sandbox.git) - * @author Antoine Sabot-Durand - * @author Scott Stark - */ -public class ConfigPropertyBeanAttribute implements BeanAttributes { - /** - * Decorate the ConfigPropertyProducer BeanAttributes to set the types the producer applies to. This set is collected - * from all injection points annotated with @ConfigProperty. - * - * @see MPConfigExtension#processConfigPropertyInjections - * @see ConfigPropertyProducer#produceConfigProperty(javax.enterprise.inject.spi.InjectionPoint) - * - * @param delegate - the original producer method BeanAttributes - * @param types - the full set of @ConfigProperty injection point types - */ - public ConfigPropertyBeanAttribute(BeanAttributes delegate, Set types) { - this.delegate = delegate; - this.types = types; - if(this.types.size() == 0) { - this.types.add(String.class); - } - } - - @Override - public Set getTypes() { - return types; - } - - @Override - public Set getQualifiers() { - return delegate.getQualifiers(); - } - - @Override - public Class getScope() { - return delegate.getScope(); - } - - @Override - public String getName() { - return delegate.getName(); - } - - @Override - public Set> getStereotypes() { - return delegate.getStereotypes(); - } - - @Override - public boolean isAlternative() { - return delegate.isAlternative(); - } - - private BeanAttributes delegate; - - private Set types; - -} diff --git a/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyProducer.java b/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyProducer.java deleted file mode 100644 index 8060f20d..00000000 --- a/sandbox/src/test/java/config/seimpl/cdi/ConfigPropertyProducer.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl.cdi; - -import java.lang.annotation.Annotation; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Optional; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.Dependent; -import javax.enterprise.inject.Produces; -import javax.enterprise.inject.spi.DeploymentException; -import javax.enterprise.inject.spi.InjectionPoint; -import javax.inject.Inject; - -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.inject.ConfigProperty; -import config.seimpl.DefaultConfig; - -/** - * A CDI producer method bean that handles injection of @ConfigProperty annotated values. - */ -@ApplicationScoped -public class ConfigPropertyProducer { - @Inject - private Config appConfig; - private DefaultConfig config; - - @PostConstruct - void init() { - config = (DefaultConfig) appConfig; - } - - @Produces - @ConfigProperty - @Dependent - private Object produceConfigProperty(InjectionPoint injectionPoint) { - System.out.printf("produceConfigProperty: %s\n", injectionPoint); - boolean isOptional = injectionPoint.getAnnotated().getBaseType().getTypeName().startsWith("java.util.Optional"); - Class toType = unwrapType(injectionPoint.getAnnotated().getBaseType()); - - Object value = getValue(injectionPoint, toType, isOptional); - return isOptional ? Optional.ofNullable(value) : value; - } - - private T getValue(InjectionPoint injectionPoint, Class target, boolean isOptional) { - String name = getName(injectionPoint); - if (name == null || name.isEmpty() || this.config == null) { - return null; - } - - Optional configValue = this.config.getOptionalValue(name, target); - if(!configValue.isPresent()) { - // Check for a default value - String defaultValue = getDefaultValue(injectionPoint); - if(defaultValue != null && !defaultValue.contentEquals(ConfigProperty.UNCONFIGURED_VALUE)) { - configValue = this.config.tryConvertValue(defaultValue, target); - } - } - if(!isOptional && !configValue.isPresent()) { - System.err.printf("Failed to find ConfigProperty for: %s\n", injectionPoint); - throw new DeploymentException(String.format("%s has no configured value", name)); - } - return configValue.orElse(null); - } - - private String getName(InjectionPoint injectionPoint) { - for (Annotation qualifier : injectionPoint.getQualifiers()) { - if (qualifier.annotationType().equals(ConfigProperty.class)) { - // Check for a non-default value - String name = ((ConfigProperty) qualifier).name(); - if(name.length() == 0) { - // - name = injectionPoint.getBean().getBeanClass().getTypeName() + "." + injectionPoint.getMember().getName(); - } - return name; - } - } - return null; - } - private String getDefaultValue(InjectionPoint injectionPoint) { - String defaultValue = null; - for (Annotation qualifier : injectionPoint.getQualifiers()) { - if (qualifier.annotationType().equals(ConfigProperty.class)) { - // Check for a non-default value - defaultValue = ((ConfigProperty) qualifier).defaultValue(); - if(defaultValue.length() == 0) { - defaultValue = null; - } - break; - } - } - return defaultValue; - } - - @SuppressWarnings("unchecked") - private Class unwrapType(Type type) { - if (type instanceof ParameterizedType) { - type = ((ParameterizedType) type).getActualTypeArguments()[0]; - } - return (Class) type; - } -} diff --git a/sandbox/src/test/java/config/seimpl/cdi/MPConfigExtension.java b/sandbox/src/test/java/config/seimpl/cdi/MPConfigExtension.java deleted file mode 100644 index 734a4812..00000000 --- a/sandbox/src/test/java/config/seimpl/cdi/MPConfigExtension.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl.cdi; - - -import java.lang.reflect.Type; -import java.util.HashSet; -import java.util.Set; - -import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.AfterBeanDiscovery; -import javax.enterprise.inject.spi.AfterTypeDiscovery; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.BeforeBeanDiscovery; -import javax.enterprise.inject.spi.Extension; -import javax.enterprise.inject.spi.InjectionPoint; -import javax.enterprise.inject.spi.ProcessAnnotatedType; -import javax.enterprise.inject.spi.ProcessBean; -import javax.enterprise.inject.spi.ProcessBeanAttributes; -import javax.enterprise.inject.spi.ProcessInjectionPoint; -import javax.enterprise.inject.spi.ProcessInjectionTarget; -import javax.enterprise.inject.spi.ProcessProducer; - -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * The CDI Extension that tracks the @ConfigProperty injection points. - */ -public class MPConfigExtension implements Extension { - private Set configPropertyTypes = new HashSet<>(); - - void afterTypeDiscovery(@Observes AfterTypeDiscovery event) { - System.out.printf("afterTypeDiscovery, configPropertyTypes=%s\n", configPropertyTypes); - } - void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) { - if(configPropertyTypes.size() == 0) { - configPropertyTypes.add(String.class); - } - System.out.printf("afterBeanDiscovery, configPropertyTypes=%s\n", configPropertyTypes); - } - - void doProcessAnnotatedType(@Observes ProcessAnnotatedType pat) { - System.out.printf("pat: %s\n", pat.getAnnotatedType()); - } - - /** - * Collect the types of all injection points annotated with @ConfigProperty. - * @param pip - the injection point event information - */ - void processConfigPropertyInjections(@Observes ProcessInjectionPoint pip) { - System.out.printf("pip: %s\n", pip.getInjectionPoint()); - InjectionPoint ip = pip.getInjectionPoint(); - if (ip.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - configPropertyTypes.add(ip.getType()); - System.out.printf("+++ Added ConfigProperty target type: %s\n", ip.getType()); - } - } - void doProcessProducers(@Observes ProcessProducer pp) { - System.out.printf("pp: %s, %s\n", pp.getAnnotatedMember(), pp.getProducer()); - } - void doProcessBeanAttributes(@Observes ProcessBeanAttributes pba) { - System.out.printf("pab: %s\n", pba.getAnnotated()); - if (pba.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - System.out.printf("\t+++ has ConfigProperty annotation\n"); - //pba.setBeanAttributes(new ConverterBeanAttribute(pba.getBeanAttributes(), types)); - } - } - void doProcessBean(@Observes ProcessBean pb) { - System.out.printf("pb: %s, class:%s, types:%s\n", pb.getAnnotated(), pb.getBean().getBeanClass(), pb.getBean().getTypes()); - if (pb.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - System.out.printf("\t+++ has ConfigProperty annotation\n"); - //pba.setBeanAttributes(new ConverterBeanAttribute(pba.getBeanAttributes(), types)); - } - } - void findNeededConfigPropertyProducers(@Observes ProcessInjectionTarget pit) { - System.out.printf("ConfigPropertyTarget: %s", pit.getInjectionTarget()); - } - - /** - * Replace our {@linkplain ConfigPropertyProducer#produceConfigProperty(InjectionPoint)} BeanAttributes with - * {@linkplain ConfigPropertyBeanAttribute} to properly reflect all of the type locations the producer method applies to. - * @see ConfigPropertyBeanAttribute - * @param pba - */ - public void addTypeToConfigProperty(@Observes ProcessBeanAttributes pba) { - if (pba.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - System.out.printf("addTypeToConfigProperty: %s", pba); - pba.setBeanAttributes(new ConfigPropertyBeanAttribute(pba.getBeanAttributes(), configPropertyTypes)); - } - } - - public void addConfigPropertyProduer(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) { - System.out.printf("MPConfigExtension, added ConfigPropertyProduer\n"); - //bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigProducer.class)); - //bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigPropertyProducer.class)); - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/BooleanConverter.java b/sandbox/src/test/java/config/seimpl/converters/BooleanConverter.java deleted file mode 100644 index 7618f424..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/BooleanConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * - */ -public class BooleanConverter implements Converter { - @Override - public Boolean convert(String value) { - return Boolean.valueOf(value); - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/ByteConverter.java b/sandbox/src/test/java/config/seimpl/converters/ByteConverter.java deleted file mode 100644 index 6c532ffc..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/ByteConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class ByteConverter implements Converter { - @Override - public Byte convert(String value) { - return value != null ? Byte.parseByte(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/CharacterConverter.java b/sandbox/src/test/java/config/seimpl/converters/CharacterConverter.java deleted file mode 100644 index dc9d6776..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/CharacterConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * - */ -public class CharacterConverter implements Converter { - @Override - public Character convert(String value) { - return value != null ? new Character(value.charAt(0)) : '\0'; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/DoubleConverter.java b/sandbox/src/test/java/config/seimpl/converters/DoubleConverter.java deleted file mode 100644 index b388359b..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/DoubleConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class DoubleConverter implements Converter { - @Override - public Double convert(String value) { - return value != null ? Double.parseDouble(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/DurationConverter.java b/sandbox/src/test/java/config/seimpl/converters/DurationConverter.java deleted file mode 100644 index 802c7720..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/DurationConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import java.time.Duration; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class DurationConverter implements Converter { - @Override - public Duration convert(String value) { - return value != null ? Duration.parse(value) : Duration.ZERO; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/FloatConverter.java b/sandbox/src/test/java/config/seimpl/converters/FloatConverter.java deleted file mode 100644 index f8c9ea6e..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/FloatConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class FloatConverter implements Converter { - @Override - public Float convert(String value) { - return value != null ? Float.parseFloat(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/InstantConverter.java b/sandbox/src/test/java/config/seimpl/converters/InstantConverter.java deleted file mode 100644 index fe2517af..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/InstantConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import java.time.Instant; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class InstantConverter implements Converter { - @Override - public Instant convert(String value) { - return value != null ? Instant.parse(value) : Instant.EPOCH; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/IntegerConverter.java b/sandbox/src/test/java/config/seimpl/converters/IntegerConverter.java deleted file mode 100644 index d34f63cc..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/IntegerConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class IntegerConverter implements Converter { - @Override - public Integer convert(String value) { - return value != null ? Integer.parseInt(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/LocalDateTimeConverter.java b/sandbox/src/test/java/config/seimpl/converters/LocalDateTimeConverter.java deleted file mode 100644 index 8b99f422..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/LocalDateTimeConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import java.time.LocalDateTime; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class LocalDateTimeConverter implements Converter { - @Override - public LocalDateTime convert(String value) { - return value != null ? LocalDateTime.parse(value) : null; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/LongConverter.java b/sandbox/src/test/java/config/seimpl/converters/LongConverter.java deleted file mode 100644 index 2024ac63..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/LongConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class LongConverter implements Converter { - @Override - public Long convert(String value) { - return value != null ? Long.parseLong(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/ShortConverter.java b/sandbox/src/test/java/config/seimpl/converters/ShortConverter.java deleted file mode 100644 index a089dd37..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/ShortConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ - -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -/** - * Created by starksm on 6/3/17. - */ -public class ShortConverter implements Converter { - @Override - public Short convert(String value) { - return value != null ? Short.parseShort(value) : 0; - } -} diff --git a/sandbox/src/test/java/config/seimpl/converters/StringArrayConverter.java b/sandbox/src/test/java/config/seimpl/converters/StringArrayConverter.java deleted file mode 100644 index 2e816fc0..00000000 --- a/sandbox/src/test/java/config/seimpl/converters/StringArrayConverter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package config.seimpl.converters; - -import org.eclipse.microprofile.config.spi.Converter; - -public class StringArrayConverter implements Converter { - @Override - public String[] convert(String value) { - String[] array = value.split(","); - return array; - } -} diff --git a/sandbox/src/test/java/issue62/AuthConfig.java b/sandbox/src/test/java/issue62/AuthConfig.java deleted file mode 100644 index 46950a0d..00000000 --- a/sandbox/src/test/java/issue62/AuthConfig.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package issue62; - -import java.security.PublicKey; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * An example CDI bean that injects the standard MP-JWT config settings - */ -@Named("MPConfig") -@ApplicationScoped -public class AuthConfig { - @Inject - private Config config; - @Inject - @ConfigProperty(name = "org.eclipse.microprofile.authentication.JWT.verifierPublicKey") - private String testKey; - @Inject - @ConfigProperty(name = "org.eclipse.microprofile.authentication.JWT.verifierPublicKey") - private PublicKey keyFromPEM; - @Inject - @ConfigProperty(name = "org.eclipse.microprofile.authentication.JWT.issuer") - private String issuer; - @Inject - @ConfigProperty(name = "org.eclipse.microprofile.authentication.JWT.issuers") - private String[] issuers; - @Inject - @ConfigProperty(name = "org.eclipse.microprofile.authentication.JWT.clockSkew", defaultValue = "30") - private int clockSkew; - - public Config getConfig() { - return config; - } - - public void setConfig(Config config) { - this.config = config; - } - - public String getTestKey() { - return testKey; - } - - public PublicKey getKeyFromPEM() { - return keyFromPEM; - } - - public String getIssuer() { - return issuer; - } - - public String[] getIssuers() { - return issuers; - } - - public int getClockSkew() { - return clockSkew; - } -} diff --git a/sandbox/src/test/java/issue62/AuthConfigTest.java b/sandbox/src/test/java/issue62/AuthConfigTest.java deleted file mode 100644 index ad5c1a05..00000000 --- a/sandbox/src/test/java/issue62/AuthConfigTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package issue62; - -import java.util.Arrays; -import java.util.HashSet; - -import javax.inject.Inject; - -import cdi.WeldJUnit4Runner; -import org.eclipse.microprofile.config.Config; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Test injection of MP-JWT config values - */ -@RunWith(WeldJUnit4Runner.class) -public class AuthConfigTest { - - @Inject - private AuthConfig authConfig; - - @Test - public void testConfigPropertyInjection() { - Config config = authConfig.getConfig(); - System.out.println(config); - Assert.assertEquals("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEqFyy46R0o7S8TKpsx5xbHKoU1" - +"VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwRTYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7Ta" - +"qszP5eUF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9AX2o1GCG3xwOjkc4x0W7ezbQZdC" - +"9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYnsIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBh" - +"kA9xnQIDAQAB", authConfig.getTestKey()); - Assert.assertEquals(15, authConfig.getClockSkew()); - Assert.assertEquals("https://mpconference.com", authConfig.getIssuer()); - String[] issuers = authConfig.getIssuers(); - HashSet issuersSet = new HashSet<>(Arrays.asList(issuers)); - Assert.assertTrue("https://www.mpconference.com", issuersSet.contains("https://www.mpconference.com")); - Assert.assertTrue("https://mpconference.com", issuersSet.contains("https://mpconference.com")); - } - - @Test - public void testAuthDefinition() { - // TODO? - } -} diff --git a/sandbox/src/test/java/issue62/SomeAuthMech.java b/sandbox/src/test/java/issue62/SomeAuthMech.java deleted file mode 100644 index 788074b9..00000000 --- a/sandbox/src/test/java/issue62/SomeAuthMech.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - */ -package issue62; - -import javax.enterprise.context.ApplicationScoped; - -import org.eclipse.microprofile.authentication.JWTAuthenticationMechanismDefinition; - -/** - * An example JWTAuthenticationMechanism bean - */ -@JWTAuthenticationMechanismDefinition( -) -@ApplicationScoped -public class SomeAuthMech { -} diff --git a/sandbox/src/test/java/jwks/AbstractJWKSTest.java b/sandbox/src/test/java/jwks/AbstractJWKSTest.java deleted file mode 100644 index 663ed4b7..00000000 --- a/sandbox/src/test/java/jwks/AbstractJWKSTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.URL; -import java.security.PrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.util.Base64; - -import com.auth0.jwt.exceptions.JWTVerificationException; -import com.nimbusds.jose.proc.BadJOSEException; -import com.sun.net.httpserver.HttpContext; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; -import org.eclipse.microprofile.jwt.tck.util.TokenUtils; -import org.jose4j.jwk.JsonWebKey; -import org.jose4j.jwk.RsaJsonWebKey; -import org.jose4j.jwt.consumer.InvalidJwtException; -import org.jose4j.keys.BigEndianBigInteger; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; - -public abstract class AbstractJWKSTest { - private static String endpoint; - private static final String TEST_ISSUER = "https://server.example.com"; - - /** - * Start an embedded HttpServer that returns the test JWKS from a http://localhost:8080/jwks endpoint - * @throws IOException - on failure - */ - @BeforeSuite - public static void startHttpServer() throws IOException { - // Load the test JKWS from the signer-keyset.jwk resource - InputStream is = AbstractJWKSTest.class.getResourceAsStream("/signer-keyset.jwk"); - byte[] response; - StringWriter sw = new StringWriter(); - try(BufferedReader br = new BufferedReader(new InputStreamReader(is))) { - String line = br.readLine(); - while(line != null) { - sw.write(line); - sw.write('\n'); - line = br.readLine(); - } - } - response = sw.toString().getBytes(); - - // Start a server listening on 8080 with a /jwks context that returns the JWKS json data - HttpServer httpServer = HttpServer.create(new InetSocketAddress(8080), 0); - endpoint = "http://localhost:8080/jwks"; - HttpContext context = httpServer.createContext("/jwks", new HttpHandler() { - public void handle(HttpExchange exchange) throws IOException { - exchange.getResponseHeaders().add("Content-Type", "application/json"); - exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length); - exchange.getResponseBody().write(response); - exchange.close(); - System.out.printf("Handled jwks request\n"); - } - }); - httpServer.start(); - - System.out.printf("Started HttpServer at: %s\n", httpServer.getAddress()); - System.out.printf("path: %s\n", context.getPath()); - System.out.printf("Started HttpServer at: %s\n", endpoint); - } - - /** - * Loads the signer-keypair.jwk resource that was generated using https://mkjwk.org - * and returns the private key - * - * @return the private key from the key pair - */ - static PrivateKey loadPrivateKey() throws Exception { - String jwk = TokenUtils.readResource("/signer-keypair.jwk"); - RsaJsonWebKey rsaJsonWebKey = (RsaJsonWebKey) JsonWebKey.Factory.newJwk(jwk); - RSAPublicKey pk = rsaJsonWebKey.getRsaPublicKey(); - String e = new String(Base64.getUrlEncoder().withoutPadding().encode(pk.getPublicExponent().toByteArray())); - byte[] nbytes = pk.getModulus().toByteArray(); - if(nbytes[0] == 0 && nbytes.length > 1) { - byte[] tmp = new byte[nbytes.length-1]; - System.arraycopy(nbytes, 1, tmp, 0, tmp.length); - nbytes = tmp; - } - String n = new String(Base64.getUrlEncoder().withoutPadding().encode(nbytes)); - System.out.printf("e: %s\n", e); - System.out.printf("n: %s\n", n); - n = BigEndianBigInteger.toBase64Url(pk.getModulus()); - System.out.printf("n: %s\n", n); - return rsaJsonWebKey.getRsaPrivateKey(); - } - - /** - * Validate access to the http://localhost:8080/jwks endpoint - * @throws IOException - on failure - */ - @Test - public void validateGet() throws Exception { - URL jwksURL = new URL(endpoint); - InputStream is = jwksURL.openStream(); - try(BufferedReader br = new BufferedReader(new InputStreamReader(is))) { - String line = br.readLine(); - while(line != null) { - System.out.println(line); - line = br.readLine(); - } - } - } - - /** - * Ensure a valid token is validated by the provider using the JWKS URL for the public key associated - * with the signer. - * - * @throws Exception - */ - @Test - public void testValidToken() throws Exception { - PrivateKey pk = loadPrivateKey(); - String token = TokenUtils.generateTokenString(pk, "jwk-test", "/Token1.json", null, null); - int expGracePeriodSecs = 60; - validateToken(token, new URL(endpoint), TEST_ISSUER, expGracePeriodSecs); - } - /** - * Ensure a token is validated by the provider using the JWKS URL for the public key associated - * with the signer. - * - * @throws Exception - */ - @Test(expectedExceptions = {InvalidJwtException.class, BadJOSEException.class, JWTVerificationException.class}) - public void testNoMatchingKID() throws Exception { - PrivateKey pk = loadPrivateKey(); - String token = TokenUtils.generateTokenString(pk, "invalid-kid", "/Token1.json", null, null); - int expGracePeriodSecs = 60; - validateToken(token, new URL(endpoint), TEST_ISSUER, expGracePeriodSecs); - } - - /** - * This method is implemented by the JWT provider library to validate the token - * - * @param token - the signed, base64 encoded header.content.sig JWT string - * @param jwksURL - URL to a JWKS that contains the public key to verify the JWT signature - * @param issuer - the expected iss claim value - * @param expGracePeriodSecs - grace period in seconds for evaluating the exp claim - * @throws Exception - */ - abstract protected void validateToken(String token, URL jwksURL, String issuer, int expGracePeriodSecs) - throws Exception; - -} diff --git a/sandbox/src/test/java/jwks/Auth0JWKSTest.java b/sandbox/src/test/java/jwks/Auth0JWKSTest.java deleted file mode 100644 index 0e418848..00000000 --- a/sandbox/src/test/java/jwks/Auth0JWKSTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.net.URL; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - -import com.auth0.jwk.Jwk; -import com.auth0.jwk.JwkProvider; -import com.auth0.jwk.UrlJwkProvider; -import com.auth0.jwt.JWT; -import com.auth0.jwt.JWTVerifier; -import com.auth0.jwt.algorithms.Algorithm; -import com.auth0.jwt.exceptions.JWTVerificationException; -import com.auth0.jwt.interfaces.DecodedJWT; -import com.auth0.jwt.interfaces.RSAKeyProvider; -import com.auth0.jwt.interfaces.Verification; - -/** - * Validate the auth0 jwt library - * https://github.com/auth0/java-jwt - */ -public class Auth0JWKSTest extends AbstractJWKSTest { - @Override - protected void validateToken(String token, URL jwksURL, String issuer, int expGracePeriodSecs) throws Exception { - JwkProvider jwkStore = new UrlJwkProvider(jwksURL); - RSAKeyProvider keyProvider = new RSAKeyProvider() { - @Override - public RSAPublicKey getPublicKeyById(String kid) throws JWTVerificationException { - //Received 'kid' value might be null if it wasn't defined in the Token's header - RSAPublicKey publicKey = null; - try { - Jwk jwk = jwkStore.get(kid); - publicKey = (RSAPublicKey) jwk.getPublicKey(); - return publicKey; - } - catch (Exception e) { - throw new JWTVerificationException("Failed to retrieve key", e); - } - } - - @Override - public RSAPrivateKey getPrivateKey() { - return null; - } - - @Override - public String getPrivateKeyId() { - return null; - } - }; - Algorithm algorithm = Algorithm.RSA256(keyProvider); - - Verification builder = JWT.require(algorithm) - .withIssuer(issuer); - if(expGracePeriodSecs > 0) { - builder = builder.acceptLeeway(expGracePeriodSecs); - } - JWTVerifier verifier = builder.build(); - DecodedJWT jwt = verifier.verify(token); - } -} diff --git a/sandbox/src/test/java/jwks/JWKSResTest.java b/sandbox/src/test/java/jwks/JWKSResTest.java deleted file mode 100644 index 30da839d..00000000 --- a/sandbox/src/test/java/jwks/JWKSResTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.io.StringReader; -import java.net.URL; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Tests of the jwks and pemjwks URL protocol handlers - */ -public class JWKSResTest { - /** - * Install the custom protocol handlers using the java.protocol.handler.pkgs system property - */ - @BeforeClass - public static void installURLHandler() { - // If other handlers are registered, don't overwrite them... - String oldPkgs = System.getProperty("java.protocol.handler.pkgs", ""); - String newPkgs = "url"; - if(!oldPkgs.isEmpty()) { - newPkgs += "|" + oldPkgs; - } - // Update handler packages - System.out.printf("Updating java.protocol.handler.pkgs to: %s\n", newPkgs); - System.setProperty("java.protocol.handler.pkgs", newPkgs); - } - - /** - * Validate that the jwks: protocol handler works - * @throws Exception on failure - */ - @Test - public void testJwksURL() throws Exception { - // Load the /signer-keyset.jwk resource from the classpath as a JWKS - URL signerJwk = new URL("jwks:/signer-keyset.jwk"); - String signerJwksContent = signerJwk.getContent().toString(); - System.out.println(signerJwksContent); - JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject(); - JsonArray keys = jwks.getJsonArray("keys"); - JsonObject key = keys.getJsonObject(0); - Assert.assertEquals(key.getJsonString("kty").getString(), "RSA"); - Assert.assertEquals(key.getJsonString("use").getString(), "sig"); - Assert.assertEquals(key.getJsonString("kid").getString(), "jwk-test"); - Assert.assertEquals(key.getJsonString("alg").getString(), "RS256"); - Assert.assertEquals(key.getJsonString("e").getString(), "AQAB"); - Assert.assertTrue(key.getJsonString("n").getString().startsWith("uGU_nmjYC7cKRR89NCAo")); - } - @Test - public void testJwks4kURL() throws Exception { - // Load the /signer-keyset.jwk resource from the classpath as a JWKS - URL signerJwk = new URL("jwks:/signer-keyset4k.jwk"); - String signerJwksContent = signerJwk.getContent().toString(); - System.out.println(signerJwksContent); - JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject(); - JsonArray keys = jwks.getJsonArray("keys"); - JsonObject key = keys.getJsonObject(0); - Assert.assertEquals(key.getJsonString("kty").getString(), "RSA"); - Assert.assertEquals(key.getJsonString("use").getString(), "sig"); - Assert.assertEquals(key.getJsonString("kid").getString(), "jwks4k-test"); - Assert.assertEquals(key.getJsonString("alg").getString(), "RS256"); - Assert.assertEquals(key.getJsonString("e").getString(), "AQAB"); - Assert.assertTrue(key.getJsonString("n").getString().startsWith("tL6HShqY5H4y56rsCo7VdhT9")); - } - /** - * Validate that the pemjwks: protocol handler works - * @throws Exception on failure - */ - @Test - public void testPemJwksURL() throws Exception { - // Load the /publicKey.pem resource from the classpath as a JWKS - URL signerJwk = new URL("pemjwks:/publicKey.pem?kid=pem-test"); - String signerJwksContent = signerJwk.getContent().toString(); - System.out.println(signerJwksContent); - JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject(); - JsonArray keys = jwks.getJsonArray("keys"); - JsonObject key = keys.getJsonObject(0); - Assert.assertEquals(key.getJsonString("kty").getString(), "RSA"); - Assert.assertEquals(key.getJsonString("use").getString(), "sig"); - Assert.assertEquals(key.getJsonString("kid").getString(), "pem-test"); - Assert.assertEquals(key.getJsonString("alg").getString(), "RS256"); - Assert.assertEquals(key.getJsonString("e").getString(), "AQAB"); - Assert.assertTrue(key.getJsonString("n").getString().startsWith("livFI8qB4D0y2jy0Cf")); - } - /** - * Validate that the pemjwks: protocol handler against the publicKey4k.pem resource - * @throws Exception on failure - */ - @Test - public void testPem4kJwksURL() throws Exception { - // Load the /publicKey.pem resource from the classpath as a JWKS - URL signerJwk = new URL("pemjwks:/publicKey4k.pem?kid=pem4k-key"); - String signerJwksContent = signerJwk.getContent().toString(); - System.out.println(signerJwksContent); - JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject(); - JsonArray keys = jwks.getJsonArray("keys"); - JsonObject key = keys.getJsonObject(0); - Assert.assertEquals(key.getJsonString("kty").getString(), "RSA"); - Assert.assertEquals(key.getJsonString("use").getString(), "sig"); - Assert.assertEquals(key.getJsonString("kid").getString(), "pem4k-key"); - Assert.assertEquals(key.getJsonString("alg").getString(), "RS256"); - Assert.assertEquals(key.getJsonString("e").getString(), "AQAB"); - Assert.assertTrue(key.getJsonString("n").getString().startsWith("tL6HShqY5H4y56rsCo7VdhT9_eLQwsJp")); - } -} diff --git a/sandbox/src/test/java/jwks/JWKxPEMTest.java b/sandbox/src/test/java/jwks/JWKxPEMTest.java deleted file mode 100644 index adf0949b..00000000 --- a/sandbox/src/test/java/jwks/JWKxPEMTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.io.StringReader; -import java.math.BigInteger; -import java.security.KeyFactory; -import java.security.PublicKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.RSAPublicKeySpec; -import java.util.Base64; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -import org.eclipse.microprofile.jwt.tck.util.TokenUtils; -import org.jose4j.jwk.JsonWebKeySet; -import org.jose4j.jwk.RsaJsonWebKey; -import org.testng.annotations.Test; - -/** - * Tests of interchanging JWKs to PEM - */ -public class JWKxPEMTest { - @Test - public void outputPEMfromJWKs() throws Exception { - String json = TokenUtils.readResource("/signer-keyset4k.jwk"); - System.out.printf("jwk: %s\n", json); - JsonWebKeySet jwks = new JsonWebKeySet(json); - RsaJsonWebKey rsaJsonWebKey = (RsaJsonWebKey) jwks.findJsonWebKey("jwks4k-test", "RSA", "sig", "RS256"); - RSAPublicKey pk = rsaJsonWebKey.getRsaPublicKey(); - String pem = new String(Base64.getEncoder().encode(pk.getEncoded())); - System.out.printf("pem: %s\n", pem); - // Use the formatted output - System.out.println("-----BEGIN PUBLIC KEY-----"); - int begin = 0; - String line = pem.substring(begin, 64); - System.out.println(line); - begin += 64; - while(begin < pem.length()) { - int end = Math.min(begin+64, pem.length()); - line = pem.substring(begin, end); - System.out.println(line); - begin += 64; - } - System.out.println("-----END PUBLIC KEY-----"); - } - - @Test - public void outputJWKsfromPEM() throws Exception { - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey4k.pem"); - JsonObjectBuilder jwksBuilder = Json.createObjectBuilder(); - JsonObjectBuilder keyBuilder = Json.createObjectBuilder(); - BigInteger nBI = publicKey.getModulus(); - byte[] nbytes = nBI.toByteArray(); - if ((nBI.bitLength() % 8 == 0) && nbytes[0] == 0 && nbytes.length > 1) { - byte[] tmp = new byte[nbytes.length-1]; - System.arraycopy(nbytes, 1, tmp, 0, tmp.length); - nbytes = tmp; - } - String n = new String(Base64.getUrlEncoder().withoutPadding().encode(nbytes)); - BigInteger eBI = publicKey.getPublicExponent(); - byte[] ebytes = eBI.toByteArray(); - if ((eBI.bitLength() % 8 == 0) && ebytes[0] == 0 && ebytes.length > 1) { - byte[] tmp = new byte[nbytes.length-1]; - System.arraycopy(nbytes, 1, tmp, 0, tmp.length); - ebytes = tmp; - } - String e = new String(Base64.getUrlEncoder().withoutPadding().encode(ebytes)); - - keyBuilder - .add("kty", "RSA") - .add("use", "sig") - .add("alg", "RS256") - .add("kid", "pem-to-jwks") - .add("e", e) - .add("n", n); - JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); - arrayBuilder.add(keyBuilder); - jwksBuilder.add("keys", arrayBuilder); - JsonObject jwks = jwksBuilder.build(); - String json = jwks.toString(); - System.out.printf("jwks=%s\n", json); - } - - @Test - public void generatePublicKeyFromJWKs() throws Exception { - String jsonJwk = TokenUtils.readResource("/signer-keyset4k.jwk"); - System.out.printf("jwk: %s\n", jsonJwk); - JsonObject jwks = Json.createReader(new StringReader(jsonJwk)).readObject(); - JsonArray keys = jwks.getJsonArray("keys"); - JsonObject jwk = keys.getJsonObject(0); - String e = jwk.getString("e"); - String n = jwk.getString("n"); - - byte[] ebytes = Base64.getUrlDecoder().decode(e); - BigInteger publicExponent = new BigInteger(1, ebytes); - byte[] nbytes = Base64.getUrlDecoder().decode(n); - BigInteger modulus = new BigInteger(1, nbytes); - KeyFactory kf = KeyFactory.getInstance("RSA"); - RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(modulus, publicExponent); - PublicKey publicKey = kf.generatePublic(rsaPublicKeySpec); - System.out.printf("publicKey=%s\n", publicKey); - String pem = new String(Base64.getEncoder().encode(publicKey.getEncoded())); - System.out.printf("pem: %s\n", pem); - } -} diff --git a/sandbox/src/test/java/jwks/Jose4jJWKSTest.java b/sandbox/src/test/java/jwks/Jose4jJWKSTest.java deleted file mode 100644 index 52794a46..00000000 --- a/sandbox/src/test/java/jwks/Jose4jJWKSTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.net.URL; -import java.security.PublicKey; -import java.util.Base64; -import java.util.List; - -import org.jose4j.jwa.AlgorithmConstraints; -import org.jose4j.jwk.HttpsJwks; -import org.jose4j.jwk.JsonWebKey; -import org.jose4j.jwk.PublicJsonWebKey; -import org.jose4j.jws.AlgorithmIdentifiers; -import org.jose4j.jwt.NumericDate; -import org.jose4j.jwt.consumer.JwtConsumer; -import org.jose4j.jwt.consumer.JwtConsumerBuilder; -import org.jose4j.jwt.consumer.JwtContext; -import org.jose4j.keys.resolvers.HttpsJwksVerificationKeyResolver; - -/** - * Validate the jose4j JWT library - * https://bitbucket.org/b_c/jose4j/overview - */ -public class Jose4jJWKSTest extends AbstractJWKSTest { - @Override - protected void validateToken(String token, URL jwksURL, String issuer, int expGracePeriodSecs) throws Exception { - JwtConsumerBuilder builder = new JwtConsumerBuilder() - .setRequireExpirationTime() - .setRequireSubject() - .setSkipDefaultAudienceValidation() - .setExpectedIssuer(issuer) - .setJwsAlgorithmConstraints( - new AlgorithmConstraints(AlgorithmConstraints.ConstraintType.WHITELIST, - AlgorithmIdentifiers.RSA_USING_SHA256)); - - HttpsJwks keySource = new HttpsJwks(jwksURL.toExternalForm()); - List keys = keySource.getJsonWebKeys(); - JsonWebKey key = keys.get(0); - if(key instanceof PublicJsonWebKey) { - PublicJsonWebKey publicJsonWebKey = (PublicJsonWebKey) key; - PublicKey pk = publicJsonWebKey.getPublicKey(); - byte[] encoded = pk.getEncoded(); - String pem = Base64.getEncoder().encodeToString(encoded); - System.out.printf("pk.pem: %s\n", pem); - } - builder.setVerificationKeyResolver(new HttpsJwksVerificationKeyResolver(keySource)); - - if (expGracePeriodSecs > 0) { - builder.setAllowedClockSkewInSeconds(expGracePeriodSecs); - } - else { - builder.setEvaluationTime(NumericDate.fromSeconds(0)); - } - - JwtConsumer jwtConsumer = builder.build(); - JwtContext jwtContext = jwtConsumer.process(token); - String type = jwtContext.getJoseObjects().get(0).getHeader("typ"); - // Validate the JWT and process it to the Claims - jwtConsumer.processContext(jwtContext); - - } -} diff --git a/sandbox/src/test/java/jwks/NimbusJWKSTest.java b/sandbox/src/test/java/jwks/NimbusJWKSTest.java deleted file mode 100644 index f99f6dd8..00000000 --- a/sandbox/src/test/java/jwks/NimbusJWKSTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwks; - -import java.net.URL; -import java.util.Date; - -import com.nimbusds.jose.JWSAlgorithm; -import com.nimbusds.jose.jwk.source.RemoteJWKSet; -import com.nimbusds.jose.proc.JWSKeySelector; -import com.nimbusds.jose.proc.JWSVerificationKeySelector; -import com.nimbusds.jose.proc.SecurityContext; -import com.nimbusds.jwt.JWTClaimsSet; -import com.nimbusds.jwt.SignedJWT; -import com.nimbusds.jwt.proc.BadJWTException; -import com.nimbusds.jwt.proc.ConfigurableJWTProcessor; -import com.nimbusds.jwt.proc.DefaultJWTProcessor; - -/** - * Validate the Nimbus JWT library - * https://connect2id.com/products/nimbus-jose-jwt - */ -public class NimbusJWKSTest extends AbstractJWKSTest { - /** - * Demonstrate how to handle a JWKS URL with Nimbus - * - * @param token - the signed, base64 encoded header.content.sig JWT string - * @param jwksURL - URL to a JWKS that contains the public key to verify the JWT signature - * @param issuer - the expected iss claim value - * @param expGracePeriodSecs - grace period in seconds for evaluating the exp claim - * @throws Exception - */ - @Override - protected void validateToken(String token, URL jwksURL, String issuer, int expGracePeriodSecs) throws Exception { - // Parse the token - SignedJWT signedJWT = SignedJWT.parse(token); - - // Add verifiers for the issuer and expiration date - ConfigurableJWTProcessor jwtProcessor = new DefaultJWTProcessor<>(); - jwtProcessor.setJWTClaimsSetVerifier((claimsSet, context) -> { - // iss - String iss = claimsSet.getIssuer(); - if (iss == null || ! iss.equals(issuer)) { - System.err.printf("issuer(%s) != %s\n", iss, issuer); - throw new BadJWTException("Invalid token issuer"); - } - // exp - if(expGracePeriodSecs > 0) { - Date expMS = null; - try { - // Nimbus coverts long exp to a Date - expMS = claimsSet.getDateClaim("exp"); - } - catch (java.text.ParseException e) { - System.err.printf("Failed to get exp claim\n"); - e.printStackTrace(); - throw new BadJWTException("Failed to get exp claim", e); - } - long now = System.currentTimeMillis(); - // The exp claim needs to be > now - grace period - long expUpperMS = now - expGracePeriodSecs * 1000; - // Fail if expMS is not in the future adjusted for grace period - if (expUpperMS > expMS.getTime()) { - System.err.printf("exp(%d) < upper bound(%d)\n", expMS.getTime(), expUpperMS); - throw new BadJWTException("Token is expired"); - } - } - }); - // Use the JWKS URL and require the RS256 signing algorithm - RemoteJWKSet keySource = new RemoteJWKSet<>(jwksURL); - JWSKeySelector authContextKeySelector = new JWSVerificationKeySelector<>(JWSAlgorithm.RS256, keySource); - jwtProcessor.setJWSKeySelector(authContextKeySelector); - jwtProcessor.process(signedJWT, null); - - JWTClaimsSet claimsSet = signedJWT.getJWTClaimsSet(); - System.out.printf("Validated JWT, claimsSet: %s\n", claimsSet); - } -} diff --git a/sandbox/src/test/java/jwt/AbstractVerifierTest.java b/sandbox/src/test/java/jwt/AbstractVerifierTest.java deleted file mode 100644 index 75aa79d8..00000000 --- a/sandbox/src/test/java/jwt/AbstractVerifierTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwt; - -import java.security.PrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.util.HashMap; -import java.util.HashSet; - -import com.auth0.jwt.exceptions.AlgorithmMismatchException; -import com.auth0.jwt.exceptions.InvalidClaimException; -import com.auth0.jwt.exceptions.SignatureVerificationException; -import com.auth0.jwt.exceptions.TokenExpiredException; -import com.nimbusds.jose.JOSEException; -import com.nimbusds.jose.proc.BadJWSException; -import com.nimbusds.jwt.proc.BadJWTException; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.IncorrectClaimException; -import io.jsonwebtoken.SignatureException; -import io.jsonwebtoken.UnsupportedJwtException; -import org.eclipse.microprofile.jwt.Claims; -import org.eclipse.microprofile.jwt.tck.util.TokenUtils; -import org.jose4j.jwt.consumer.InvalidJwtException; -import org.jose4j.jwt.consumer.InvalidJwtSignatureException; -import org.testng.annotations.Test; - - -public abstract class AbstractVerifierTest { - public static final String TEST_ISSUER = "https://server.example.com"; - - @Test - public void testValidToken() throws Exception { - String token = TokenUtils.generateTokenString("/Token1.json"); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test - public void testValidToken4k() throws Exception { - PrivateKey signer = TokenUtils.readPrivateKey("/privateKey4k.pem"); - String token = TokenUtils.generateTokenString(signer, "4k-test", "/Token1.json", null, null); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey4k.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test(expectedExceptions = {BadJWTException.class, InvalidJwtException.class, InvalidClaimException.class, IncorrectClaimException.class}, - description = "Illustrate validation of issuer") - public void testBadIssuer() throws Exception { - HashSet invalidFields = new HashSet<>(); - invalidFields.add(TokenUtils.InvalidClaims.ISSUER); - String token = TokenUtils.generateTokenString("/Token1.json", invalidFields); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test(expectedExceptions = {BadJWSException.class, SignatureVerificationException.class, - InvalidJwtSignatureException.class, SignatureException.class}, - description = "Illustrate validation of signer") - public void testFailSignature() throws Exception { - HashSet invalidFields = new HashSet<>(); - invalidFields.add(TokenUtils.InvalidClaims.SIGNER); - String token = TokenUtils.generateTokenString("/Token1.json", invalidFields); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test(expectedExceptions = {JOSEException.class, AlgorithmMismatchException.class, InvalidJwtException.class, UnsupportedJwtException.class}, - description = "Illustrate validation of signature algorithm") - public void testFailSignatureAlgorithm() throws Exception { - HashSet invalidFields = new HashSet<>(); - invalidFields.add(TokenUtils.InvalidClaims.ALG); - String token = TokenUtils.generateTokenString("/Token1.json", invalidFields); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test(expectedExceptions = {BadJWTException.class, InvalidJwtException.class, TokenExpiredException.class, ExpiredJwtException.class}, - description = "Illustrate validation of exp") - public void testFailExpired() throws Exception { - HashMap timeClaims = new HashMap<>(); - HashSet invalidFields = new HashSet<>(); - invalidFields.add(TokenUtils.InvalidClaims.EXP); - String token = TokenUtils.generateTokenString("/Token1.json", invalidFields, timeClaims); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - @Test(description = "Illustrate validation of exp that is in grace period") - public void testExpGrace() throws Exception { - HashMap timeClaims = new HashMap<>(); - // Set exp to 45 seconds in past - long exp = TokenUtils.currentTimeInSecs() - 45; - timeClaims.put(Claims.exp.name(), exp); - String token = TokenUtils.generateTokenString("/Token1.json", null, timeClaims); - RSAPublicKey publicKey = (RSAPublicKey) TokenUtils.readPublicKey("/publicKey.pem"); - int expGracePeriodSecs = 60; - validateToken(token, publicKey, TEST_ISSUER, expGracePeriodSecs); - } - /** - * - * @param token - the signed, base64 encoded header.content.sig JWT string - * @param publicKey - the public key to verify the expected signature - * @param issuer - the expected iss claim value - * @param expGracePeriodSecs - grace period in seconds for evaluating the exp claim - * @throws Exception - */ - abstract protected void validateToken(String token, RSAPublicKey publicKey, String issuer, int expGracePeriodSecs) - throws Exception; -} diff --git a/sandbox/src/test/java/jwt/Auth0VerifierTest.java b/sandbox/src/test/java/jwt/Auth0VerifierTest.java deleted file mode 100644 index 8559e082..00000000 --- a/sandbox/src/test/java/jwt/Auth0VerifierTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwt; - -import java.security.interfaces.RSAPublicKey; - -import com.auth0.jwt.JWT; -import com.auth0.jwt.JWTVerifier; -import com.auth0.jwt.algorithms.Algorithm; -import com.auth0.jwt.interfaces.DecodedJWT; -import com.auth0.jwt.interfaces.Verification; - -public class Auth0VerifierTest extends AbstractVerifierTest { - @Override - protected void validateToken(String token, RSAPublicKey publicKey, String issuer, int expGracePeriodSecs) throws Exception { - Algorithm algorithm = Algorithm.RSA256(publicKey, null); - Verification builder = JWT.require(algorithm) - .withIssuer(issuer); - if(expGracePeriodSecs > 0) { - builder = builder.acceptLeeway(expGracePeriodSecs); - } - JWTVerifier verifier = builder.build(); - DecodedJWT jwt = verifier.verify(token); - } -} diff --git a/sandbox/src/test/java/jwt/JjwtVerifierTest.java b/sandbox/src/test/java/jwt/JjwtVerifierTest.java deleted file mode 100644 index d4eac2c3..00000000 --- a/sandbox/src/test/java/jwt/JjwtVerifierTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwt; - -import java.security.interfaces.RSAPublicKey; - -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Jws; -import io.jsonwebtoken.Jwt; -import io.jsonwebtoken.JwtParser; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; -import io.jsonwebtoken.SignatureException; - -public class JjwtVerifierTest extends AbstractVerifierTest { - @Override - protected void validateToken(String token, RSAPublicKey publicKey, String issuer, int expGracePeriodSecs) throws Exception { - JwtParser parser = Jwts.parser() - .setSigningKey(publicKey) - .requireIssuer(issuer) - ; - if(expGracePeriodSecs > 0) { - parser = parser.setAllowedClockSkewSeconds(expGracePeriodSecs); - } - - Jwt jwt = parser.parse(token); - String alg = jwt.getHeader().get("alg").toString(); - if(alg == null || !alg.equals(SignatureAlgorithm.RS256.getValue())) { - throw new SignatureException("Non-RS256 alg: "+alg); - } - Jws claims = parser.parseClaimsJws(token); - } -} diff --git a/sandbox/src/test/java/jwt/Jose4jVerifierTest.java b/sandbox/src/test/java/jwt/Jose4jVerifierTest.java deleted file mode 100644 index ead75f20..00000000 --- a/sandbox/src/test/java/jwt/Jose4jVerifierTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwt; - -import java.security.interfaces.RSAPublicKey; - -import org.jose4j.jwa.AlgorithmConstraints; -import org.jose4j.jws.AlgorithmIdentifiers; -import org.jose4j.jwt.NumericDate; -import org.jose4j.jwt.consumer.JwtConsumer; -import org.jose4j.jwt.consumer.JwtConsumerBuilder; -import org.jose4j.jwt.consumer.JwtContext; - -public class Jose4jVerifierTest extends AbstractVerifierTest { - @Override - protected void validateToken(String token, RSAPublicKey publicKey, String issuer, int expGracePeriodSecs) throws Exception { - JwtConsumerBuilder builder = new JwtConsumerBuilder() - .setRequireExpirationTime() - .setRequireSubject() - .setSkipDefaultAudienceValidation() - .setExpectedIssuer(issuer) - .setJwsAlgorithmConstraints( - new AlgorithmConstraints(AlgorithmConstraints.ConstraintType.WHITELIST, - AlgorithmIdentifiers.RSA_USING_SHA256)); - - builder.setVerificationKey(publicKey); - - if (expGracePeriodSecs > 0) { - builder.setAllowedClockSkewInSeconds(expGracePeriodSecs); - } - else { - builder.setEvaluationTime(NumericDate.fromSeconds(0)); - } - - JwtConsumer jwtConsumer = builder.build(); - JwtContext jwtContext = jwtConsumer.process(token); - String type = jwtContext.getJoseObjects().get(0).getHeader("typ"); - // Validate the JWT and process it to the Claims - jwtConsumer.processContext(jwtContext); - } -} diff --git a/sandbox/src/test/java/jwt/NimbusVerifierTest.java b/sandbox/src/test/java/jwt/NimbusVerifierTest.java deleted file mode 100644 index 449d373a..00000000 --- a/sandbox/src/test/java/jwt/NimbusVerifierTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package jwt; - -import java.security.interfaces.RSAPublicKey; -import java.util.Collections; -import java.util.Date; - -import com.nimbusds.jose.JWSAlgorithm; -import com.nimbusds.jose.JWSVerifier; -import com.nimbusds.jose.KeySourceException; -import com.nimbusds.jose.crypto.RSASSAVerifier; -import com.nimbusds.jose.proc.JWSKeySelector; -import com.nimbusds.jose.proc.SecurityContext; -import com.nimbusds.jwt.JWTClaimsSet; -import com.nimbusds.jwt.SignedJWT; -import com.nimbusds.jwt.proc.BadJWTException; -import com.nimbusds.jwt.proc.ConfigurableJWTProcessor; -import com.nimbusds.jwt.proc.DefaultJWTProcessor; - -public class NimbusVerifierTest extends AbstractVerifierTest { - @Override - protected void validateToken(String token, RSAPublicKey publicKey, String issuer, int expGracePeriodSecs) throws Exception { - SignedJWT signedJWT = SignedJWT.parse(token); - // Validate the signature - JWSVerifier verifier = new RSASSAVerifier(publicKey); - signedJWT.verify(verifier); - - // Add verifiers for the issuer and expiration date - ConfigurableJWTProcessor jwtProcessor = new DefaultJWTProcessor<>(); - jwtProcessor.setJWTClaimsSetVerifier((claimsSet, context) -> { - // iss - String iss = claimsSet.getIssuer(); - if (iss == null || ! iss.equals(issuer)) { - System.err.printf("issuer(%s) != %s\n", iss, issuer); - throw new BadJWTException("Invalid token issuer"); - } - // exp - if(expGracePeriodSecs > 0) { - Date expMS = null; - try { - // Nimbus coverts long exp to a Date - expMS = claimsSet.getDateClaim("exp"); - } - catch (java.text.ParseException e) { - System.err.printf("Failed to get exp claim\n"); - e.printStackTrace(); - throw new BadJWTException("Failed to get exp claim", e); - } - long now = System.currentTimeMillis(); - // The exp claim needs to be > now - grace period - long expUpperMS = now - expGracePeriodSecs * 1000; - // Fail if expMS is not in the future adjusted for grace period - if (expUpperMS > expMS.getTime()) { - System.err.printf("exp(%d) < upper bound(%d)\n", expMS.getTime(), expUpperMS); - throw new BadJWTException("Token is expired"); - } - } - }); - // The signing algorithm must be RS256 - JWSKeySelector authContextKeySelector = (header, context) -> { - if(header.getAlgorithm() != JWSAlgorithm.RS256) { - throw new KeySourceException("RS256 algorithm not specified"); - } - return Collections.singletonList(publicKey); - }; - jwtProcessor.setJWSKeySelector(authContextKeySelector); - jwtProcessor.process(signedJWT, null); - - JWTClaimsSet claimsSet = signedJWT.getJWTClaimsSet(); - System.out.printf("Validated JWT, claimsSet: %s\n", claimsSet); - } - -} diff --git a/sandbox/src/test/java/url/jwks/Handler.java b/sandbox/src/test/java/url/jwks/Handler.java deleted file mode 100644 index 35238c87..00000000 --- a/sandbox/src/test/java/url/jwks/Handler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package url.jwks; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * The jwks URL protocol handler - */ -public class Handler extends URLStreamHandler { - @Override - protected URLConnection openConnection(URL u) throws IOException { - return new JwksURLConnection(u); - } -} diff --git a/sandbox/src/test/java/url/jwks/JwksURLConnection.java b/sandbox/src/test/java/url/jwks/JwksURLConnection.java deleted file mode 100644 index be31a5b7..00000000 --- a/sandbox/src/test/java/url/jwks/JwksURLConnection.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package url.jwks; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.net.URL; -import java.net.URLConnection; - -/** - * The jwks protocol handler URLConnection implementation. - */ -public class JwksURLConnection extends URLConnection { - private String path; - private StringWriter content; - - protected JwksURLConnection(URL url) { - super(url); - this.path = url.getPath(); - } - - @Override - public void connect() throws IOException { - InputStream is = getInputStream(); - if(is == null) { - throw new FileNotFoundException(path); - } - content = new StringWriter(); - try(BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { - String line = reader.readLine(); - while(line != null) { - content.write(line); - content.write('\n'); - line = reader.readLine(); - } - } - } - - @Override - public String getContentType() { - return "application/json"; - } - - @Override - public Object getContent() throws IOException { - if(content == null) { - connect(); - } - return content.toString(); - } - - @Override - public InputStream getInputStream() throws IOException { - return getClass().getResourceAsStream(path); - } -} diff --git a/sandbox/src/test/java/url/pemjwks/Handler.java b/sandbox/src/test/java/url/pemjwks/Handler.java deleted file mode 100644 index 7fe8f50c..00000000 --- a/sandbox/src/test/java/url/pemjwks/Handler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package url.pemjwks; - -import java.io.IOException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * The pemjwks URL protocol handler - */ -public class Handler extends URLStreamHandler { - @Override - protected URLConnection openConnection(URL u) throws IOException { - return new PemJwksURLConnection(u); - } -} diff --git a/sandbox/src/test/java/url/pemjwks/PemJwksURLConnection.java b/sandbox/src/test/java/url/pemjwks/PemJwksURLConnection.java deleted file mode 100644 index 65d2a129..00000000 --- a/sandbox/src/test/java/url/pemjwks/PemJwksURLConnection.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package url.pemjwks; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringWriter; -import java.math.BigInteger; -import java.net.URL; -import java.net.URLConnection; -import java.security.interfaces.RSAPublicKey; -import java.util.Base64; - -import javax.json.Json; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -import org.eclipse.microprofile.jwt.tck.util.TokenUtils; - -/** - * The pemjwks protocol URLConnection implementation - */ -public class PemJwksURLConnection extends URLConnection { - private String path; - private String kid; - private StringWriter content; - - protected PemJwksURLConnection(URL url) { - super(url); - this.path = url.getPath(); - // Look for kid=xxx - String query = url.getQuery(); - if(query != null) { - String[] parts = query.split("="); - kid = parts[1]; - } - else { - // Some random kid - kid = Long.toHexString(Double.doubleToLongBits(Math.random())); - } - } - - @Override - public void connect() throws IOException { - InputStream is = getInputStream(); - if(is == null) { - throw new FileNotFoundException(path); - } - content = new StringWriter(); - try(BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { - String line = reader.readLine(); - while(line != null) { - content.write(line); - content.write('\n'); - line = reader.readLine(); - } - } - } - - @Override - public String getContentType() { - return "application/json"; - } - - /** - * Generate a JWKS with a single key - * @return - * @throws IOException - */ - @Override - public Object getContent() throws IOException { - if(content == null) { - connect(); - } - // - RSAPublicKey publicKey; - try { - publicKey = (RSAPublicKey) TokenUtils.decodePublicKey(content.toString()); - } - catch (Exception e) { - throw new IOException(e); - } - /* - "keys": [ - { - "kty": "RSA", - "e": "AQAB", - "use": "sig", - "kid": "jwk-test", - "alg": "RS256", - "n": "uGU_nmjYC7cK... - } - ] - */ - JsonObjectBuilder jwksBuilder = Json.createObjectBuilder(); - JsonObjectBuilder keyBuilder = Json.createObjectBuilder(); - BigInteger nBI = publicKey.getModulus(); - byte[] nbytes = nBI.toByteArray(); - if ((nBI.bitLength() % 8 == 0) && nbytes[0] == 0 && nbytes.length > 1) { - byte[] tmp = new byte[nbytes.length-1]; - System.arraycopy(nbytes, 1, tmp, 0, tmp.length); - nbytes = tmp; - } - String n = new String(Base64.getUrlEncoder().withoutPadding().encode(nbytes)); - BigInteger eBI = publicKey.getPublicExponent(); - byte[] ebytes = eBI.toByteArray(); - if ((eBI.bitLength() % 8 == 0) && ebytes[0] == 0 && ebytes.length > 1) { - byte[] tmp = new byte[nbytes.length-1]; - System.arraycopy(nbytes, 1, tmp, 0, tmp.length); - ebytes = tmp; - } - String e = new String(Base64.getUrlEncoder().withoutPadding().encode(ebytes)); - - keyBuilder - .add("kty", "RSA") - .add("use", "sig") - .add("alg", "RS256") - .add("kid", kid) - .add("e", e) - .add("n", n); - JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); - arrayBuilder.add(keyBuilder); - jwksBuilder.add("keys", arrayBuilder); - JsonObject jwks = jwksBuilder.build(); - return jwks.toString(); - } - - @Override - public InputStream getInputStream() throws IOException { - return getClass().getResourceAsStream(path); - } -} diff --git a/sandbox/src/test/resources/META-INF/beans.xml b/sandbox/src/test/resources/META-INF/beans.xml deleted file mode 100644 index a4aec8cd..00000000 --- a/sandbox/src/test/resources/META-INF/beans.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - diff --git a/sandbox/src/test/resources/META-INF/microprofile-config.properties b/sandbox/src/test/resources/META-INF/microprofile-config.properties deleted file mode 100644 index 1db07dcf..00000000 --- a/sandbox/src/test/resources/META-INF/microprofile-config.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright (c) 2011-2017 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# You may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -org.eclipse.microprofile.authentication.JWT.signerPublicKey=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEqFyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwRTYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5eUF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYnsIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9xnQIDAQAB -org.eclipse.microprofile.authentication.JWT.issuer=https://mpconference.com -org.eclipse.microprofile.authentication.JWT.issuers=https://mpconference.com,https://www.mpconference.com -org.eclipse.microprofile.authentication.JWT.clockSkew=15 - -org.eclipse.microprofile.authentication.JWT.verifierPublicKey=[raw]MIIBIjANBgkqhkiG9w0... -org.eclipse.microprofile.authentication.JWT.verifierPublicKey=[classpath]/somepath/xzykey.pem -org.eclipse.microprofile.authentication.JWT.verifierPublicKey=[url]http://somepath/xzykey.pem diff --git a/sandbox/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/sandbox/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension deleted file mode 100644 index 1b1306c6..00000000 --- a/sandbox/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension +++ /dev/null @@ -1 +0,0 @@ -config.seimpl.cdi.MPConfigExtension diff --git a/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver b/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver deleted file mode 100644 index b085bf49..00000000 --- a/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver +++ /dev/null @@ -1 +0,0 @@ -config.seimpl.DefaultConfigProviderResolver diff --git a/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter b/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter deleted file mode 100644 index c20a1ad1..00000000 --- a/sandbox/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter +++ /dev/null @@ -1,2 +0,0 @@ -org.eclipse.microprofile.authentication.config.PrivateKeyConverter -org.eclipse.microprofile.authentication.config.PublicKeyConverter diff --git a/sandbox/src/test/resources/Token1.json b/sandbox/src/test/resources/Token1.json deleted file mode 100644 index 34962172..00000000 --- a/sandbox/src/test/resources/Token1.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "iss": "https://server.example.com", - "jti": "a-123", - "sub": "24400320", - "upn": "jdoe@example.com", - "preferred_username": "jdoe", - "aud": "s6BhdRkqt3", - "exp": 1311281970, - "iat": 1311280970, - "auth_time": 1311280969, - "roles": [ - "Echoer" - ], - "groups": [ - "Echoer", - "Tester", - "group1", - "group2" - ], - "customString": "customStringValue", - "customInteger": 123456789, - "customDouble": 3.141592653589793, - "customStringArray": [ - "value0", - "value1", - "value2" - ], - "customIntegerArray": [ - 0, - 1, - 2, - 3 - ], - "customDoubleArray": [ - 0.1, - 1.1, - 2.2, - 3.3, - 4.4 - ], - "customObject": { - "my-service": { - "groups": [ - "group1", - "group2" - ], - "roles": [ - "role-in-my-service" - ] - }, - "service-B": { - "roles": [ - "role-in-B" - ] - }, - "service-C": { - "groups": [ - "groupC", - "web-tier" - ] - } - } -} diff --git a/sandbox/src/test/resources/privateKey.pem b/sandbox/src/test/resources/privateKey.pem deleted file mode 100644 index e20d80b5..00000000 --- a/sandbox/src/test/resources/privateKey.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCWK8UjyoHgPTLa -PLQJ8SoXLLjpHSjtLxMqmzHnFscqhTVVaDpCRCb6e3Ii/WniQTWw8RA7vf4djz4H -OzvlfBFNgvUGZHXDwnmGaNVaNzpHYFMEYBhE8VGGiveSkzqeLZI+Y02G6sQAfDtN -qqzM/l5QX8X34oQFaTBW1r49nftvCpITiwJvWyhkWtXP9RP8sXi1im5Vi3dhupOh -nelk5n0BfajUYIbfHA6ORzjHRbt7NtBl0L2J+0/FUdHyKs6KMlFGNw8O0Dq88qnM -uXoLJiewhg9332W3DFMeOveel+//cvDnRsCRtPgd4sXFPHh+UShkso7+DRsChXa6 -oGGQD3GdAgMBAAECggEAAjfTSZwMHwvIXIDZB+yP+pemg4ryt84iMlbofclQV8hv -6TsI4UGwcbKxFOM5VSYxbNOisb80qasb929gixsyBjsQ8284bhPJR7r0q8h1C+jY -URA6S4pk8d/LmFakXwG9Tz6YPo3pJziuh48lzkFTk0xW2Dp4SLwtAptZY/+ZXyJ6 -96QXDrZKSSM99Jh9s7a0ST66WoxSS0UC51ak+Keb0KJ1jz4bIJ2C3r4rYlSu4hHB -Y73GfkWORtQuyUDa9yDOem0/z0nr6pp+pBSXPLHADsqvZiIhxD/O0Xk5I6/zVHB3 -zuoQqLERk0WvA8FXz2o8AYwcQRY2g30eX9kU4uDQAQKBgQDmf7KGImUGitsEPepF -KH5yLWYWqghHx6wfV+fdbBxoqn9WlwcQ7JbynIiVx8MX8/1lLCCe8v41ypu/eLtP -iY1ev2IKdrUStvYRSsFigRkuPHUo1ajsGHQd+ucTDf58mn7kRLW1JGMeGxo/t32B -m96Af6AiPWPEJuVfgGV0iwg+HQKBgQCmyPzL9M2rhYZn1AozRUguvlpmJHU2DpqS -34Q+7x2Ghf7MgBUhqE0t3FAOxEC7IYBwHmeYOvFR8ZkVRKNF4gbnF9RtLdz0DMEG -5qsMnvJUSQbNB1yVjUCnDAtElqiFRlQ/k0LgYkjKDY7LfciZl9uJRl0OSYeX/qG2 -tRW09tOpgQKBgBSGkpM3RN/MRayfBtmZvYjVWh3yjkI2GbHA1jj1g6IebLB9SnfL -WbXJErCj1U+wvoPf5hfBc7m+jRgD3Eo86YXibQyZfY5pFIh9q7Ll5CQl5hj4zc4Y -b16sFR+xQ1Q9Pcd+BuBWmSz5JOE/qcF869dthgkGhnfVLt/OQzqZluZRAoGAXQ09 -nT0TkmKIvlza5Af/YbTqEpq8mlBDhTYXPlWCD4+qvMWpBII1rSSBtftgcgca9XLB -MXmRMbqtQeRtg4u7dishZVh1MeP7vbHsNLppUQT9Ol6lFPsd2xUpJDc6BkFat62d -Xjr3iWNPC9E9nhPPdCNBv7reX7q81obpeXFMXgECgYEAmk2Qlus3OV0tfoNRqNpe -Mb0teduf2+h3xaI1XDIzPVtZF35ELY/RkAHlmWRT4PCdR0zXDidE67L6XdJyecSt -FdOUH8z5qUraVVebRFvJqf/oGsXc4+ex1ZKUTbY0wqY1y9E39yvB3MaTmZFuuqk8 -f3cg+fr8aou7pr9SHhJlZCU= ------END RSA PRIVATE KEY----- diff --git a/sandbox/src/test/resources/privateKey4k.pem b/sandbox/src/test/resources/privateKey4k.pem deleted file mode 100644 index e8de1a68..00000000 --- a/sandbox/src/test/resources/privateKey4k.pem +++ /dev/null @@ -1,52 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC0vodKGpjkfjLn -quwKjtV2FP394tDCwmkpaDrqP3xewH+pzlnGQnbkZcLOmNHRm/MDEw2WPWGsw5Fo -pXPPb/lrFmAXV5l/OCs3JD2u0ZoG0w0AHbSMuyhinmmxFNpjEp46Isc+vf3nq6RJ -FQX1h8kZJqau8Y7ALyHrNurq5rJ2/4VUleKOUwP+IKCBR+iKu1U5Yr9fUjNXtyi/ -FwbNPRfTX3/hFu2Mt2e+pmcaqakdCkEQi0j7iA29opHw0NZTECM7+/6g4pHmcRSc -NZxBILEqbJCtUm0ev08HBasfNNLHiTUvWEt/4BZcB3L+vpzQvOC3mSeZlPJYMbb6 -fxKWtfEcfEU7VbPwf84oHNMB/zMi6PaWRdij4zpqgkzupCZPKzzR21i+docZKX6O -l7amUxtL1FLhdwcfu8Kolz1pwGen0K8uCM6YDRvlFzRbI3iyfVIMVh7odlxWjhgZ -Nu1NOXCC7+jNDXH7GlMBpTSZaQczBPQI7v2s85GOENeiQS526+2npVSIBqgUXpjd -BAt/o7c/2nzKCGkEEtvjrSURCo4dBAY/QQrjpxTzV2VwPmVgTRNrIPNv2lllZTKM -gTgSXPJbvCAjjHDtzN0FqU34iFcp8ZQKogNWHtfsmmayRkxpGLF/jbjIFxkue0R6 -NnLn3IsNKywcxz9uqcGtpe6jwkEQ+QIDAQABAoICABu7wHaWbi9hTd5OU7mrAQYF -YpO6Yd4AhrJb0+5tn1/KmcwsZYoOWL/i/WlF+av4CenG2qba9EnWGFG+UW7a96J+ -5G+weVUUAU2MugpBDylM6QnDhRiy/xdix0TstjXNfYneHER8UqFhrOup1ig+lZTO -YXUmi4jhsoqs+o7gpzGrM4IvHXxJMKulxfsQVZYz+He9ty+hJU+oQxBPMDP909IT -LUQUiI629axDTD7DGbfjAujO9nvh/HnEoDAbW0eTilSB7igxm8GISGlPsJItugGQ -dwKhSy0UncOuEvvO1yjW3NpO6gbNE6E7Y2HDTbyZvsFtNq5SNH1j43e8V9XYRQ6f -q8lMfUqIfPEllivDJ8Nk9OpPD7NQzq2dk+k9DXZcfEZvWHDU0L6NNMjykqhVRbRV -CMbkaxKNPP7sZWj+pmlWA6KQGmXWiL68KsLuza4JmuuCSkaSylLVFSJsrlcQc69r -8M67ChXJPLcDwrMo+bdGWen6jxVkaxKAxSHC5xzfm4prXwCdlNJMpC6NZXimxLct -H+dR0mAKBklST9W744ViwyVUBDhQJrif2Ke1Vc//3QI43qoiHFB0oHB2SUpsoofn -tBNNQDnZ0FFB678HuCB6vUqCkrqCW3QWpDBbz2xUOfE3MwY2LYo1oQyHzBlw5XEc -FNPXsERDEodVdcDAdHwBAoIBAQDooFbMzvkSUJyHJP8qfG/1Cra2AO9EmXeh53bA -DWey5WG59XjIbn62ezs8LuDCt7mJa2gKGotjR2gRCAQE0G5fUTqSj8qmP2YfZ/20 -Esa2/+r7mMnIU0qBHBPum9DH4UqF25OovwUK0VpvJM7WioUpKpHKxDraEqjsKChQ -s2BlO5FKtq3C+dcKx8xBW6JpXmDeTcaEc//rM0bVWK2NGRCdoNEXYpDoEgS9CmJP -xTYfly5nPaE2Iicx3Fd6LpZiEoRqhi7EJZPTbINYdpqKtSqDD5uPbjCGQyWmR21F -6A2HRZSmrfW+FBw2HYbEsEgMfWcUcplfDw+ms7OgkYC8fV5xAoIBAQDG56sYgp+0 -/P6WgwEq+b1sRrlgVrqDSZ50Ark9vZPri7RDoZZmKghGH3pF2cXE+6oNELec8BFi -eOflnVSFotVVVs7pY+u5LQLQdDQNbBx3rxKOt5ZNelefnsHTMdLTcx5a+ZrZK+n1 -yBzqDZQaAAh8PYr8e9cGiyRiMy35N0ZrMOpkJwSCRPNcnNjq6LwgjKcist84WzS3 -sEQ8YHKrc8tFzBKJiq6wX1+roli58OG762HYcLCvDJzg1PUcYG3G0KebBWlyDnrq -UECuMZBo+5pX98ZyK1F0/hvTh5GT2Njt7U52g6hc/1vqCIz7awTngKpTq968Mhp/ -UVOhpRL6oi8JAoIBADLXEAFU3qR9D6iNkmLDrWg9fi8Kx0AT1kyBHLfediJn9VLB -7jLHy1OwXQLLL/3+T0NUQPmsUXhSG9FVEiPHNcgJJabwXBa3VmdYv97CF8HY7o8s -FjV81pSfAVAtp5R3jWTx1zSTAtQZaw1NWxMSVQXpMtHAzyfn2hk6sYzplxCo0xkk -EZfCKJhHkEFceINUyBDtqIw8GdtaaomoBs4Gg1Yf1nKo7Qh7H6P9B/1tGWYQEWko -0/nTvwMrp8ahNeabK2tohgICQGt9lLsZuK7F51ObbqELMPm25RyREbWsgIBm2ZUQ -AdwX4w6Ep3aHHEf2hDe40AIxdXc2YPSfuCX5tFECggEAQGDjg/9jadUpIdYtHpfO -s6kAfyoTHENLwgjPpCgkJG0HX4yBfXfFTc0KamleFa/PDoOGqokZV2ICzNLrdIWL -vx9lwSzSMxFag9XYsy9211YXD5JkV5dtnQBpg83wivgLry5y7C/GfgLTOP5EHVY9 -aNkSjz4WDswibpZaHvvBExi2BMyMLQ3cJvGtU/sYSQC9aAG1NixvF7U5oMEm3E+S -T3kJ1vLIL9XuxUK6rRRGO+intsJirYXLkQnce97KKTuHxCkwQ/Zj2ks3ZCour4wg -HLDZzkIvD0rf/ss2V0AslnXkm39pkxAj09AIsael4rhGaOaMJSWiZesQwpUHW4/6 -4QKCAQEA05npqWlJV5GiLssC9kjjaeFU7ym1vUTOjVru94gtxUO4fuIn/81kaEWR -P7fuNUaO2MR/lHVuN87DirVXANpMYoZOKF4kTvEBqSoFNYVXj3IS/KmRd8y+9Jcq -u6MGHS5Hn+aulkBWyzcRiQGrFYgUrEXVYd5Mv2ZvL0GnPKiD8Wdn6Wc77YOF/qI2 -OCpCXXNNuW53tsMHCGI7zdx+hCnetpCp9dWCmN0/Zw4+w1xyJnG5WRM1LzyTjisw -qpLVyflAeRPMA/wJTQzow3OdD1Qi2Mkvq10zIvXLnCnN4TEmAqN2leh3dWG81hL5 -zd9ETOJ6iMJRTQrD85NBgg6WJWvQrw== ------END PRIVATE KEY----- diff --git a/sandbox/src/test/resources/publicKey.pem b/sandbox/src/test/resources/publicKey.pem deleted file mode 100644 index a1dc20c8..00000000 --- a/sandbox/src/test/resources/publicKey.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN RSA PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEq -Fyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwR -TYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5e -UF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9 -AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYn -sIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9x -nQIDAQAB ------END RSA PUBLIC KEY----- diff --git a/sandbox/src/test/resources/publicKey4k.pem b/sandbox/src/test/resources/publicKey4k.pem deleted file mode 100644 index 5bb1ede4..00000000 --- a/sandbox/src/test/resources/publicKey4k.pem +++ /dev/null @@ -1,14 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtL6HShqY5H4y56rsCo7V -dhT9/eLQwsJpKWg66j98XsB/qc5ZxkJ25GXCzpjR0ZvzAxMNlj1hrMORaKVzz2/5 -axZgF1eZfzgrNyQ9rtGaBtMNAB20jLsoYp5psRTaYxKeOiLHPr3956ukSRUF9YfJ -GSamrvGOwC8h6zbq6uaydv+FVJXijlMD/iCggUfoirtVOWK/X1IzV7covxcGzT0X -019/4RbtjLdnvqZnGqmpHQpBEItI+4gNvaKR8NDWUxAjO/v+oOKR5nEUnDWcQSCx -KmyQrVJtHr9PBwWrHzTSx4k1L1hLf+AWXAdy/r6c0Lzgt5knmZTyWDG2+n8SlrXx -HHxFO1Wz8H/OKBzTAf8zIuj2lkXYo+M6aoJM7qQmTys80dtYvnaHGSl+jpe2plMb -S9RS4XcHH7vCqJc9acBnp9CvLgjOmA0b5Rc0WyN4sn1SDFYe6HZcVo4YGTbtTTlw -gu/ozQ1x+xpTAaU0mWkHMwT0CO79rPORjhDXokEuduvtp6VUiAaoFF6Y3QQLf6O3 -P9p8yghpBBLb460lEQqOHQQGP0EK46cU81dlcD5lYE0TayDzb9pZZWUyjIE4Elzy -W7wgI4xw7czdBalN+IhXKfGUCqIDVh7X7JpmskZMaRixf424yBcZLntEejZy59yL -DSssHMc/bqnBraXuo8JBEPkCAwEAAQ== ------END PUBLIC KEY----- diff --git a/sandbox/src/test/resources/signer-keypair.jwk b/sandbox/src/test/resources/signer-keypair.jwk deleted file mode 100644 index d10580c9..00000000 --- a/sandbox/src/test/resources/signer-keypair.jwk +++ /dev/null @@ -1,9 +0,0 @@ -{ - "kty": "RSA", - "d": "rq-Mc3-TnJWM7yrHCoikSMYgV_ba-5uAZzoVDGckslJiWamdDMhD7S_1rHwiK8UwoUSHILqyeEKumcGpT5TXhWgd3NKmCm93Xl8MfQYJtRUepuGxuDqE1uk-pGkWGg2Ek9fX8EKr0CEUuW2TBVn5drZ_RDvGUsKTW4ofrEYfE7S4t3If2UXpxRb5-6QlmU7xCy7TOwBhaXaUde0Mllepncbl1FNTvRlDyuGWomNFBOqdZqqDkTUSdzQ7FjjufBWc-kvW5PLum_lECUf5ky3diyqM87U5v5K5b55TB0Y7kEUr782StmMg7kmimIswrMMifTj5R4VRprgyPF_rQanhcQ", - "e": "AQAB", - "use": "sig", - "kid": "jwk-test", - "alg": "RS256", - "n": "uGU_nmjYC7cKRR89NCAoLvMhsjKyJ1z22WhlKdHGIZfMZI8n9vvOLgx21fEAiR9MLyiy397UKjYCvVwvaB9d0Iwj4G8cP8keLpY_sn38mUiPm1OdcbruQDu6fN6JjNexbogAoI5agpBzj-NrRqLuk-UTHmKGVNyKPRjcPoiHSQNis0T0_ZJn-BDIYDIwbpnfm0pYMbhxtsULMCZn_DKwQL_0OWJ_lZ_zWBOO5r-WLD-M7QfjS52pHHkDwV0SybdMkAZ_eInkYc1m_SdhauemcNhbLt84sBpsl2-5rXgWM7w3w9hEt3qgpwfelNEFbkonR_qnQd0auRk6esvAQc25Ow" -} diff --git a/sandbox/src/test/resources/signer-keyset.jwk b/sandbox/src/test/resources/signer-keyset.jwk deleted file mode 100644 index 5f208edb..00000000 --- a/sandbox/src/test/resources/signer-keyset.jwk +++ /dev/null @@ -1,12 +0,0 @@ -{ - "keys": [ - { - "kty": "RSA", - "e": "AQAB", - "use": "sig", - "kid": "jwk-test", - "alg": "RS256", - "n": "uGU_nmjYC7cKRR89NCAoLvMhsjKyJ1z22WhlKdHGIZfMZI8n9vvOLgx21fEAiR9MLyiy397UKjYCvVwvaB9d0Iwj4G8cP8keLpY_sn38mUiPm1OdcbruQDu6fN6JjNexbogAoI5agpBzj-NrRqLuk-UTHmKGVNyKPRjcPoiHSQNis0T0_ZJn-BDIYDIwbpnfm0pYMbhxtsULMCZn_DKwQL_0OWJ_lZ_zWBOO5r-WLD-M7QfjS52pHHkDwV0SybdMkAZ_eInkYc1m_SdhauemcNhbLt84sBpsl2-5rXgWM7w3w9hEt3qgpwfelNEFbkonR_qnQd0auRk6esvAQc25Ow" - } - ] -} diff --git a/sandbox/src/test/resources/signer-keyset4k.jwk b/sandbox/src/test/resources/signer-keyset4k.jwk deleted file mode 100644 index c2e0754c..00000000 --- a/sandbox/src/test/resources/signer-keyset4k.jwk +++ /dev/null @@ -1,12 +0,0 @@ -{ - "keys": [ - { - "kty": "RSA", - "use": "sig", - "alg": "RS256", - "kid": "jwks4k-test", - "e": "AQAB", - "n": "tL6HShqY5H4y56rsCo7VdhT9_eLQwsJpKWg66j98XsB_qc5ZxkJ25GXCzpjR0ZvzAxMNlj1hrMORaKVzz2_5axZgF1eZfzgrNyQ9rtGaBtMNAB20jLsoYp5psRTaYxKeOiLHPr3956ukSRUF9YfJGSamrvGOwC8h6zbq6uaydv-FVJXijlMD_iCggUfoirtVOWK_X1IzV7covxcGzT0X019_4RbtjLdnvqZnGqmpHQpBEItI-4gNvaKR8NDWUxAjO_v-oOKR5nEUnDWcQSCxKmyQrVJtHr9PBwWrHzTSx4k1L1hLf-AWXAdy_r6c0Lzgt5knmZTyWDG2-n8SlrXxHHxFO1Wz8H_OKBzTAf8zIuj2lkXYo-M6aoJM7qQmTys80dtYvnaHGSl-jpe2plMbS9RS4XcHH7vCqJc9acBnp9CvLgjOmA0b5Rc0WyN4sn1SDFYe6HZcVo4YGTbtTTlwgu_ozQ1x-xpTAaU0mWkHMwT0CO79rPORjhDXokEuduvtp6VUiAaoFF6Y3QQLf6O3P9p8yghpBBLb460lEQqOHQQGP0EK46cU81dlcD5lYE0TayDzb9pZZWUyjIE4ElzyW7wgI4xw7czdBalN-IhXKfGUCqIDVh7X7JpmskZMaRixf424yBcZLntEejZy59yLDSssHMc_bqnBraXuo8JBEPk" - } - ] -} diff --git a/sandbox/src/test/resources/signer.jwk b/sandbox/src/test/resources/signer.jwk deleted file mode 100644 index 90ba2bbb..00000000 --- a/sandbox/src/test/resources/signer.jwk +++ /dev/null @@ -1,8 +0,0 @@ -{ - "kty": "RSA", - "e": "AQAB", - "use": "sig", - "kid": "jwk-test", - "alg": "RS256", - "n": "uGU_nmjYC7cKRR89NCAoLvMhsjKyJ1z22WhlKdHGIZfMZI8n9vvOLgx21fEAiR9MLyiy397UKjYCvVwvaB9d0Iwj4G8cP8keLpY_sn38mUiPm1OdcbruQDu6fN6JjNexbogAoI5agpBzj-NrRqLuk-UTHmKGVNyKPRjcPoiHSQNis0T0_ZJn-BDIYDIwbpnfm0pYMbhxtsULMCZn_DKwQL_0OWJ_lZ_zWBOO5r-WLD-M7QfjS52pHHkDwV0SybdMkAZ_eInkYc1m_SdhauemcNhbLt84sBpsl2-5rXgWM7w3w9hEt3qgpwfelNEFbkonR_qnQd0auRk6esvAQc25Ow" -}