From 5bc95b203cda075e8d60fa9ffc915258d138968d Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Tue, 19 Apr 2022 22:04:44 +0200 Subject: [PATCH] [#519] Add moditect-generated module-info.java files and a simple IT. - uses lots of more profiles - requires Java 8+ for a release - requires Java 9+ for running the integration test - does not deploy integration tests - maven.compiler.release is set instead of source and target for Java9+ - maven.compiler.source/target is now only set on Java7 and Java8 so the javadoc and sources plugin will work correctly. - Does not contain ITs for neither GSON nor org.json. - Ugly workaround for the fact that the old bundle-plugin crashes on Java9+ module-info.java files, had to provide an empty static MANIFEST.MF file and disable the bundle-plugin on ITs. - I found it odd that the extensions do not reference their correct parent pom as parent pom, instead the root is chosen. This is probably a maven anti-pattern and was corrected by khmarbaise for Shiro. - parentLocation = ../pom.xml is redundant for /api and /impl, but did not bother to correct it here - some pom.xml files were missing a final line break as required by unix spec. --- api/pom.xml | 39 ++++++++++- extensions/gson/pom.xml | 35 +++++++++- extensions/jackson/pom.xml | 35 +++++++++- extensions/orgjson/pom.xml | 35 +++++++++- impl/pom.xml | 42 ++++++++++- integration-tests/pom.xml | 25 +++++++ integration-tests/unsigned-jackson/pom.xml | 70 +++++++++++++++++++ .../it/unsigned/UnsignedJwtCreator.java | 32 +++++++++ .../src/main/java/module-info.java | 4 ++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../it/unsigned/UnsignedJwtCreatorTest.java | 31 ++++++++ pom.xml | 25 +++++-- 12 files changed, 363 insertions(+), 10 deletions(-) create mode 100644 integration-tests/pom.xml create mode 100644 integration-tests/unsigned-jackson/pom.xml create mode 100644 integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java create mode 100644 integration-tests/unsigned-jackson/src/main/java/module-info.java create mode 100644 integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF create mode 100644 integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java diff --git a/api/pom.xml b/api/pom.xml index 61667e7a9..aba3f5def 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -50,4 +50,41 @@ - \ No newline at end of file + + + nonJDK7 + + [1.8,) + + + + + org.moditect + moditect-maven-plugin + + + add-module-infos + package + + add-module-info + + + + + io.jsonwebtoken.jjwt.api + + io.jsonwebtoken; + io.jsonwebtoken.*; + + + + + + + + + + + + + diff --git a/extensions/gson/pom.xml b/extensions/gson/pom.xml index 6b6985e83..21333a497 100644 --- a/extensions/gson/pom.xml +++ b/extensions/gson/pom.xml @@ -44,4 +44,37 @@ - \ No newline at end of file + + + nonJDK7 + + [1.8,) + + + + + org.moditect + moditect-maven-plugin + + + add-module-infos + package + + add-module-info + + + + + io.jsonwebtoken.jjwt.ext.gson + + + + + + + + + + + + diff --git a/extensions/jackson/pom.xml b/extensions/jackson/pom.xml index 79b0959ab..fde25ba8a 100644 --- a/extensions/jackson/pom.xml +++ b/extensions/jackson/pom.xml @@ -77,4 +77,37 @@ - \ No newline at end of file + + + + nonJDK7 + + [1.8,) + + + + + org.moditect + moditect-maven-plugin + + + add-module-infos + package + + add-module-info + + + + + io.jsonwebtoken.jjwt.ext.jackson + + + + + + + + + + + diff --git a/extensions/orgjson/pom.xml b/extensions/orgjson/pom.xml index f0ea88409..894bb9d7b 100644 --- a/extensions/orgjson/pom.xml +++ b/extensions/orgjson/pom.xml @@ -77,4 +77,37 @@ - \ No newline at end of file + + + + nonJDK7 + + [1.8,) + + + + + org.moditect + moditect-maven-plugin + + + add-module-infos + package + + add-module-info + + + + + io.jsonwebtoken.jjwt.ext.orgjson + + + + + + + + + + + diff --git a/impl/pom.xml b/impl/pom.xml index b1aaf92e1..f9c753cdf 100644 --- a/impl/pom.xml +++ b/impl/pom.xml @@ -66,4 +66,44 @@ - \ No newline at end of file + + + nonJDK7 + + [1.8,) + + + + + org.moditect + moditect-maven-plugin + + + add-module-infos + package + + add-module-info + + + + + io.jsonwebtoken.jjwt.impl + + io.jsonwebtoken.jjwt.api; + + + io.jsonwebtoken.CompressionCodec; + io.jsonwebtoken.io.Deserializer; + io.jsonwebtoken.io.Serializer; + + + + + + + + + + + + diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml new file mode 100644 index 000000000..e41ba0562 --- /dev/null +++ b/integration-tests/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + + io.jsonwebtoken + jjwt-root + 0.11.3-SNAPSHOT + + + jjwt-integration-tests + JJWT :: Integration-Tests + pom + + + true + + + + unsigned-jackson + + + diff --git a/integration-tests/unsigned-jackson/pom.xml b/integration-tests/unsigned-jackson/pom.xml new file mode 100644 index 000000000..b69f264cf --- /dev/null +++ b/integration-tests/unsigned-jackson/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + + io.jsonwebtoken + jjwt-integration-tests + 0.11.3-SNAPSHOT + + + jjwt-integration-tests-unsigned-jackson + JJWT :: Integration-Tests :: unsigned-jackson + Create and parse an unsigned JWT using Jackson and JPMS. + jar + + + 9 + true + + + + + io.jsonwebtoken + jjwt-api + + + io.jsonwebtoken + jjwt-impl + 0.11.3-SNAPSHOT + runtime + + + io.jsonwebtoken + jjwt-jackson + runtime + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + true + false + + + + + org.apache.felix + maven-bundle-plugin + + + bundle-manifest + none + + + + + + + diff --git a/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java b/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java new file mode 100644 index 000000000..6f3740f15 --- /dev/null +++ b/integration-tests/unsigned-jackson/src/main/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreator.java @@ -0,0 +1,32 @@ +package io.jsonwebtoken.it.unsigned; + +import io.jsonwebtoken.*; + +import java.time.Instant; +import java.util.Date; +import java.util.List; + +public class UnsignedJwtCreator { + + public UnsignedJwtCreator() { + // explicit + } + + public String create() { + return Jwts.builder() + .claim("roles", List.of("admin")) + .setSubject("jjwt") + .setId("jjwt-0") + .setIssuedAt(Date.from(Instant.now())) + .setNotBefore(Date.from(Instant.now())) + .compact(); + } + + public Jwt read(String jwt) { + final JwtParser jwtParser = Jwts.parserBuilder() + .requireSubject("jjwt") + .build(); + + return jwtParser.parseClaimsJwt(jwt); + } +} diff --git a/integration-tests/unsigned-jackson/src/main/java/module-info.java b/integration-tests/unsigned-jackson/src/main/java/module-info.java new file mode 100644 index 000000000..71d5b72a0 --- /dev/null +++ b/integration-tests/unsigned-jackson/src/main/java/module-info.java @@ -0,0 +1,4 @@ +module io.jsonwebtoken.jjwt.it.unsigned { + requires io.jsonwebtoken.jjwt.api; + +} diff --git a/integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF b/integration-tests/unsigned-jackson/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..e69de29bb diff --git a/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java b/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java new file mode 100644 index 000000000..a651c4b43 --- /dev/null +++ b/integration-tests/unsigned-jackson/src/test/java/io/jsonwebtoken/it/unsigned/UnsignedJwtCreatorTest.java @@ -0,0 +1,31 @@ +package io.jsonwebtoken.it.unsigned; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Header; +import io.jsonwebtoken.Jwt; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +public class UnsignedJwtCreatorTest { + + @Test + public void testUnsignedJwt() { + // given: + final UnsignedJwtCreator jwtCreator = new UnsignedJwtCreator(); + final String jwtString = jwtCreator.create(); + + // when + final Jwt readBackJwt = jwtCreator.read(jwtString); + + // then + final Claims jwtBody = readBackJwt.getBody(); + assertEquals("jjwt-0", jwtBody.getId()); + assertEquals("jjwt", jwtBody.getSubject()); + assertTrue(jwtBody.get("roles", List.class).contains("admin")); + } + +} diff --git a/pom.xml b/pom.xml index fe2bea294..e935f0e2b 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,7 @@ 3.8.0 3.1.1 1.6.1 + 1.0.0.RC2 1.7 UTF-8 @@ -251,9 +252,6 @@ org.apache.maven.plugins maven-javadoc-plugin 2.10.4 - - ${jdk.version} - jdk9AndLater [1.9,) + + integration-tests + --add-opens java.base/jdk.internal.loader=ALL-UNNAMED + ${jdk.version}