TOMEE-2247 - Refactor Arquillian packaging to try to fix issues with war name and context root.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3b246d38 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3b246d38 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3b246d38 Branch: refs/heads/master Commit: 3b246d388b48c9525f3ecfd675273ae310722137 Parents: 72725a5 Author: Roberto Cortez <[email protected]> Authored: Thu Sep 13 17:23:53 2018 +0100 Committer: Roberto Cortez <[email protected]> Committed: Fri Dec 7 18:08:36 2018 +0000 ---------------------------------------------------------------------- .../jwt/AppDeploymentExtension.java | 141 ------------------- .../jwt/JWTAuthContextInfoProvider.java | 63 --------- .../tomee/microprofile/jwt/TCKTokenParser.java | 40 ------ .../tck/jwt/JWTAuthContextInfoProvider.java | 63 +++++++++ .../jwt/MicroProfileJWTTCKArchiveProcessor.java | 92 ++++++++++++ .../MicroProfileJWTTCKDeploymentPackager.java | 54 +++++++ .../tck/jwt/MicroProfileJWTTCKExtension.java | 32 +++++ .../tck/jwt/MicroProfileJWTTCKProtocol.java | 27 ++++ .../microprofile/tck/jwt/TCKTokenParser.java | 40 ++++++ ...lipse.microprofile.jwt.tck.util.ITokenParser | 2 +- ....jboss.arquillian.core.spi.LoadableExtension | 2 +- 11 files changed, 310 insertions(+), 246 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/AppDeploymentExtension.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/AppDeploymentExtension.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/AppDeploymentExtension.java deleted file mode 100644 index 93c6fa6..0000000 --- a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/AppDeploymentExtension.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.apache.tomee.microprofile.jwt; - -import com.nimbusds.jose.JWSSigner; -import org.apache.openejb.loader.JarLocation; -import org.apache.tomee.arquillian.remote.RemoteTomEEConfiguration; -import org.apache.tomee.arquillian.remote.RemoteTomEEContainer; -import org.eclipse.microprofile.jwt.tck.TCKConstants; -import org.eclipse.microprofile.jwt.tck.config.IssValidationTest; -import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMLocationTest; -import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMTest; -import org.eclipse.microprofile.jwt.tck.util.TokenUtils; -import org.jboss.arquillian.container.spi.Container; -import org.jboss.arquillian.container.spi.ContainerRegistry; -import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration; -import org.jboss.arquillian.container.spi.client.container.DeployableContainer; -import org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription; -import org.jboss.arquillian.container.spi.client.deployment.TargetDescription; -import org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator; -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentScenarioGenerator; -import org.jboss.arquillian.core.api.Instance; -import org.jboss.arquillian.core.api.annotation.Inject; -import org.jboss.arquillian.core.spi.LoadableExtension; -import org.jboss.arquillian.test.spi.TestClass; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.Node; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.Asset; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.shrinkwrap.impl.base.NodeImpl; - -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.logging.Logger; -import java.util.stream.Stream; - -public class AppDeploymentExtension implements LoadableExtension { - @Override - public void register(final ExtensionBuilder extensionBuilder) { - extensionBuilder.service(DeploymentScenarioGenerator.class, SimpleDeploymentScenarioGenerator.class); - extensionBuilder.service(ApplicationArchiveProcessor.class, MPJWTTCKArchiveProcess.class); - } - - public static class SimpleDeploymentScenarioGenerator implements DeploymentScenarioGenerator { - - private final DeploymentScenarioGenerator standard = new AnnotationDeploymentScenarioGenerator(); - private final DeploymentDescription emptyTestWebApp; - - public SimpleDeploymentScenarioGenerator() { - emptyTestWebApp = new DeploymentDescription("mp-jwt-tck.war", - ShrinkWrap - .create(WebArchive.class, "mp-jwt-tck.war") - .addAsLibrary(JarLocation.jarLocation(TokenUtils.class)) - .addAsLibrary(JarLocation.jarLocation(JWSSigner.class)) - .addAsLibrary(JarLocation.jarLocation(TCKConstants.class).getAbsolutePath().replace("-tests.jar", "-test-sources.jar")) - .add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")); - } - - - @Override - public List<DeploymentDescription> generate(final TestClass testClass) { - final List<DeploymentDescription> stdDeploymentDescriptions = standard.generate(testClass); - - if (stdDeploymentDescriptions != null && !stdDeploymentDescriptions.isEmpty()) { - return stdDeploymentDescriptions; - } - - return Collections.singletonList(emptyTestWebApp); - } - } - - /** - * An ApplicationArchiveProcessor for the MP-JWT TCK if needed - * With the current implementation we don't need to do anything - */ - public static class MPJWTTCKArchiveProcess implements ApplicationArchiveProcessor { - private static Logger log = Logger.getLogger(MPJWTTCKArchiveProcess.class.getName()); - - @Inject - private Instance<ContainerRegistry> containerRegistry; - - @Override - public void process(final Archive<?> appArchive, final TestClass testClass) { - if (!(appArchive instanceof WebArchive)) { - return; - } - final WebArchive war = WebArchive.class.cast(appArchive); - war.addClass(JWTAuthContextInfoProvider.class); - - // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46. - final Map<ArchivePath, Node> content = war.getContent(object -> object.get().matches(".*META-INF/.*")); - content.forEach((archivePath, node) -> war.addAsResource(node.getAsset(), node.getPath())); - - // Spec says that vendor specific ways to load the keys take precedence, so we need to remove it in test - // cases that use the Config approach. - Stream.of( - PublicKeyAsPEMTest.class, - PublicKeyAsPEMLocationTest.class, - IssValidationTest.class) - .filter(c -> c.equals(testClass.getJavaClass())) - .findAny() - .ifPresent(c -> war.deleteClass(JWTAuthContextInfoProvider.class)); - - // Rewrite the correct server port in configuration - final Container container = containerRegistry.get().getContainer(TargetDescription.DEFAULT); - if (container.getDeployableContainer() instanceof RemoteTomEEContainer) { - final RemoteTomEEContainer remoteTomEEContainer = - (RemoteTomEEContainer) container.getDeployableContainer(); - final RemoteTomEEConfiguration configuration = remoteTomEEContainer.getConfiguration(); - final String httpPort = configuration.getHttpPort() + ""; - - final Map<ArchivePath, Node> microprofileProperties = - war.getContent(object -> object.get().matches(".*META-INF/microprofile-config\\.properties")); - microprofileProperties.forEach((archivePath, node) -> { - try { - final Properties properties = new Properties(); - properties.load(node.getAsset().openStream()); - properties.replaceAll((key, value) -> ((String) value).replaceAll("8080", httpPort)); - final StringWriter stringWriter = new StringWriter(); - properties.store(stringWriter, null); - war.delete(archivePath); - war.add(new StringAsset(stringWriter.toString()), node.getPath()); - } catch (final IOException e) { - e.printStackTrace(); - } - }); - } - - log.info("Augmented war: \n"+war.toString(true)); - } - } -} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/JWTAuthContextInfoProvider.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/JWTAuthContextInfoProvider.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/JWTAuthContextInfoProvider.java deleted file mode 100644 index bf0a07f..0000000 --- a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/JWTAuthContextInfoProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tomee.microprofile.jwt; - -import org.apache.tomee.microprofile.jwt.config.JWTAuthContextInfo; - -import javax.enterprise.context.Dependent; -import javax.enterprise.inject.Produces; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.X509EncodedKeySpec; -import java.util.Base64; -import java.util.Optional; - -@Dependent -public class JWTAuthContextInfoProvider { - - @Produces - Optional<JWTAuthContextInfo> getOptionalContextInfo() throws NoSuchAlgorithmException, InvalidKeySpecException { - JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(); - - // todo use MP Config to load the configuration - contextInfo.setIssuedBy("https://server.example.com"); - - final String pemEncoded = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEq" + - "Fyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwR" + - "TYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5e" + - "UF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9" + - "AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYn" + - "sIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9x" + - "nQIDAQAB"; - byte[] encodedBytes = Base64.getDecoder().decode(pemEncoded); - - final X509EncodedKeySpec spec = new X509EncodedKeySpec(encodedBytes); - final KeyFactory kf = KeyFactory.getInstance("RSA"); - final RSAPublicKey pk = (RSAPublicKey) kf.generatePublic(spec); - - contextInfo.setSignerKey(pk); - - return Optional.of(contextInfo); - } - - @Produces - JWTAuthContextInfo getContextInfo() throws InvalidKeySpecException, NoSuchAlgorithmException { - return getOptionalContextInfo().get(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/TCKTokenParser.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/TCKTokenParser.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/TCKTokenParser.java deleted file mode 100644 index ae563ec..0000000 --- a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/jwt/TCKTokenParser.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tomee.microprofile.jwt; - -import org.apache.tomee.microprofile.jwt.config.JWTAuthContextInfo; -import org.apache.tomee.microprofile.jwt.principal.DefaultJWTCallerPrincipalFactory; -import org.apache.tomee.microprofile.jwt.principal.JWTCallerPrincipalFactory; -import org.eclipse.microprofile.jwt.JsonWebToken; -import org.eclipse.microprofile.jwt.tck.util.ITokenParser; - -import java.security.PublicKey; -import java.security.interfaces.RSAPublicKey; - -/** - * MP-JWT TCK harness class to parse a token string - */ -public class TCKTokenParser implements ITokenParser { - - @Override - public JsonWebToken parse(final String bearerToken, final String issuer, final PublicKey publicKey) throws Exception { - final JWTAuthContextInfo authContextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, issuer); - final JWTCallerPrincipalFactory factory = DefaultJWTCallerPrincipalFactory.instance(); - return factory.parse(bearerToken, authContextInfo); - } - -} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/JWTAuthContextInfoProvider.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/JWTAuthContextInfoProvider.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/JWTAuthContextInfoProvider.java new file mode 100644 index 0000000..6dc1a8f --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/JWTAuthContextInfoProvider.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import org.apache.tomee.microprofile.jwt.config.JWTAuthContextInfo; + +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Produces; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.Base64; +import java.util.Optional; + +@Dependent +public class JWTAuthContextInfoProvider { + + @Produces + Optional<JWTAuthContextInfo> getOptionalContextInfo() throws NoSuchAlgorithmException, InvalidKeySpecException { + JWTAuthContextInfo contextInfo = new JWTAuthContextInfo(); + + // todo use MP Config to load the configuration + contextInfo.setIssuedBy("https://server.example.com"); + + final String pemEncoded = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlivFI8qB4D0y2jy0CfEq" + + "Fyy46R0o7S8TKpsx5xbHKoU1VWg6QkQm+ntyIv1p4kE1sPEQO73+HY8+Bzs75XwR" + + "TYL1BmR1w8J5hmjVWjc6R2BTBGAYRPFRhor3kpM6ni2SPmNNhurEAHw7TaqszP5e" + + "UF/F9+KEBWkwVta+PZ37bwqSE4sCb1soZFrVz/UT/LF4tYpuVYt3YbqToZ3pZOZ9" + + "AX2o1GCG3xwOjkc4x0W7ezbQZdC9iftPxVHR8irOijJRRjcPDtA6vPKpzLl6CyYn" + + "sIYPd99ltwxTHjr3npfv/3Lw50bAkbT4HeLFxTx4flEoZLKO/g0bAoV2uqBhkA9x" + + "nQIDAQAB"; + byte[] encodedBytes = Base64.getDecoder().decode(pemEncoded); + + final X509EncodedKeySpec spec = new X509EncodedKeySpec(encodedBytes); + final KeyFactory kf = KeyFactory.getInstance("RSA"); + final RSAPublicKey pk = (RSAPublicKey) kf.generatePublic(spec); + + contextInfo.setSignerKey(pk); + + return Optional.of(contextInfo); + } + + @Produces + JWTAuthContextInfo getContextInfo() throws InvalidKeySpecException, NoSuchAlgorithmException { + return getOptionalContextInfo().get(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java new file mode 100644 index 0000000..41390f2 --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKArchiveProcessor.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import org.apache.tomee.arquillian.remote.RemoteTomEEConfiguration; +import org.apache.tomee.arquillian.remote.RemoteTomEEContainer; +import org.eclipse.microprofile.jwt.tck.config.IssValidationTest; +import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMLocationTest; +import org.eclipse.microprofile.jwt.tck.config.PublicKeyAsPEMTest; +import org.jboss.arquillian.container.spi.Container; +import org.jboss.arquillian.container.spi.ContainerRegistry; +import org.jboss.arquillian.container.spi.client.deployment.TargetDescription; +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.core.api.Instance; +import org.jboss.arquillian.core.api.annotation.Inject; +import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.Node; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Stream; + +public class MicroProfileJWTTCKArchiveProcessor implements ApplicationArchiveProcessor { + @Inject + private Instance<ContainerRegistry> containerRegistry; + + @Override + public void process(final Archive<?> applicationArchive, final TestClass testClass) { + if (!(applicationArchive instanceof WebArchive)) { + return; + } + final WebArchive war = WebArchive.class.cast(applicationArchive); + + // Provide keys required for tests (vendor specific way) + war.addClass(JWTAuthContextInfoProvider.class); + + // Spec says that vendor specific ways to load the keys take precedence, so we need to remove it in test + // cases that use the Config approach. + Stream.of( + PublicKeyAsPEMTest.class, + PublicKeyAsPEMLocationTest.class, + IssValidationTest.class) + .filter(c -> c.equals(testClass.getJavaClass())) + .findAny() + .ifPresent(c -> war.deleteClass(JWTAuthContextInfoProvider.class)); + + // Rewrite the correct server port in configuration + final Container container = containerRegistry.get().getContainer(TargetDescription.DEFAULT); + if (container.getDeployableContainer() instanceof RemoteTomEEContainer) { + final RemoteTomEEContainer remoteTomEEContainer = + (RemoteTomEEContainer) container.getDeployableContainer(); + final RemoteTomEEConfiguration configuration = remoteTomEEContainer.getConfiguration(); + final String httpPort = configuration.getHttpPort() + ""; + + final Map<ArchivePath, Node> microprofileProperties = war.getContent( + object -> object.get().matches(".*META-INF/microprofile-config\\.properties")); + microprofileProperties.forEach((archivePath, node) -> { + try { + final Properties properties = new Properties(); + properties.load(node.getAsset().openStream()); + properties.replaceAll((key, value) -> ((String) value).replaceAll("8080", httpPort)); + final StringWriter stringWriter = new StringWriter(); + properties.store(stringWriter, null); + war.delete(archivePath); + war.add(new StringAsset(stringWriter.toString()), node.getPath()); + } catch (final IOException e) { + e.printStackTrace(); + } + }); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKDeploymentPackager.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKDeploymentPackager.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKDeploymentPackager.java new file mode 100644 index 0000000..d1b1fe4 --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKDeploymentPackager.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import com.nimbusds.jose.JWSSigner; +import org.apache.openejb.loader.JarLocation; +import org.eclipse.microprofile.jwt.tck.util.TokenUtils; +import org.jboss.arquillian.container.test.spi.TestDeployment; +import org.jboss.arquillian.container.test.spi.client.deployment.ProtocolArchiveProcessor; +import org.jboss.arquillian.protocol.servlet.v_2_5.ServletProtocolDeploymentPackager; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ArchivePath; +import org.jboss.shrinkwrap.api.Node; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +import java.util.Collection; +import java.util.Map; + +public class MicroProfileJWTTCKDeploymentPackager extends ServletProtocolDeploymentPackager { + @Override + public Archive<?> generateDeployment(final TestDeployment testDeployment, + final Collection<ProtocolArchiveProcessor> processors) { + final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, testDeployment.getApplicationArchive().getName()) + .merge(testDeployment.getApplicationArchive()); + + // Add Required Libraries + webArchive.addAsLibrary(JarLocation.jarLocation(TokenUtils.class)) + .addAsLibrary(JarLocation.jarLocation(JWSSigner.class)) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + + // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46. + final Map<ArchivePath, Node> content = webArchive.getContent(object -> object.get().matches(".*META-INF/.*")); + content.forEach((archivePath, node) -> webArchive.addAsResource(node.getAsset(), node.getPath())); + + return super.generateDeployment( + new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKExtension.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKExtension.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKExtension.java new file mode 100644 index 0000000..2a2ec26 --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKExtension.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.container.test.spi.client.protocol.Protocol; +import org.jboss.arquillian.core.spi.LoadableExtension; +import org.jboss.arquillian.protocol.servlet.v_2_5.ServletProtocol; + +public class MicroProfileJWTTCKExtension implements LoadableExtension { + @Override + public void register(final ExtensionBuilder extensionBuilder) { + extensionBuilder + .override(Protocol.class, ServletProtocol.class, MicroProfileJWTTCKProtocol.class) + .service(ApplicationArchiveProcessor.class, MicroProfileJWTTCKArchiveProcessor.class) + ; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKProtocol.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKProtocol.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKProtocol.java new file mode 100644 index 0000000..c3650b6 --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/MicroProfileJWTTCKProtocol.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentPackager; +import org.jboss.arquillian.protocol.servlet.v_2_5.ServletProtocol; + +public class MicroProfileJWTTCKProtocol extends ServletProtocol { + @Override + public DeploymentPackager getPackager() { + return new MicroProfileJWTTCKDeploymentPackager(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/TCKTokenParser.java ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/TCKTokenParser.java b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/TCKTokenParser.java new file mode 100644 index 0000000..e13709d --- /dev/null +++ b/tck/microprofile-tck/jwt/src/test/java/org/apache/tomee/microprofile/tck/jwt/TCKTokenParser.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tomee.microprofile.tck.jwt; + +import org.apache.tomee.microprofile.jwt.config.JWTAuthContextInfo; +import org.apache.tomee.microprofile.jwt.principal.DefaultJWTCallerPrincipalFactory; +import org.apache.tomee.microprofile.jwt.principal.JWTCallerPrincipalFactory; +import org.eclipse.microprofile.jwt.JsonWebToken; +import org.eclipse.microprofile.jwt.tck.util.ITokenParser; + +import java.security.PublicKey; +import java.security.interfaces.RSAPublicKey; + +/** + * MP-JWT TCK harness class to parse a token string + */ +public class TCKTokenParser implements ITokenParser { + + @Override + public JsonWebToken parse(final String bearerToken, final String issuer, final PublicKey publicKey) throws Exception { + final JWTAuthContextInfo authContextInfo = new JWTAuthContextInfo((RSAPublicKey) publicKey, issuer); + final JWTCallerPrincipalFactory factory = DefaultJWTCallerPrincipalFactory.instance(); + return factory.parse(bearerToken, authContextInfo); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.eclipse.microprofile.jwt.tck.util.ITokenParser ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.eclipse.microprofile.jwt.tck.util.ITokenParser b/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.eclipse.microprofile.jwt.tck.util.ITokenParser index 4dcc059..f8d8098 100644 --- a/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.eclipse.microprofile.jwt.tck.util.ITokenParser +++ b/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.eclipse.microprofile.jwt.tck.util.ITokenParser @@ -1 +1 @@ -org.apache.tomee.microprofile.jwt.TCKTokenParser \ No newline at end of file +org.apache.tomee.microprofile.tck.jwt.TCKTokenParser http://git-wip-us.apache.org/repos/asf/tomee/blob/3b246d38/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension ---------------------------------------------------------------------- diff --git a/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension index 98a4867..2651f91 100644 --- a/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension +++ b/tck/microprofile-tck/jwt/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -1 +1 @@ -org.apache.tomee.microprofile.jwt.AppDeploymentExtension \ No newline at end of file +org.apache.tomee.microprofile.tck.jwt.MicroProfileJWTTCKExtension
