Skip to content

Commit

Permalink
[jwtk#519] Add src/main/java9/module-info.java files and a simple IT.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarwell committed Jul 18, 2024
1 parent 5812f63 commit 5066c68
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
</plugins>
</build>

</project>
</project>
6 changes: 6 additions & 0 deletions api/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module io.jsonwebtoken.jjwt.api {
exports io.jsonwebtoken;
exports io.jsonwebtoken.io;
exports io.jsonwebtoken.lang;
exports io.jsonwebtoken.security;
}
2 changes: 1 addition & 1 deletion extensions/gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
</plugins>
</build>

</project>
</project>
11 changes: 11 additions & 0 deletions extensions/gson/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module io.jsonwebtoken.jjwt.ext.gson {
requires transitive com.google.gson;
requires io.jsonwebtoken.jjwt.api;

exports io.jsonwebtoken.gson.io;

provides io.jsonwebtoken.io.Deserializer with
io.jsonwebtoken.gson.io.GsonDeserializer;
provides io.jsonwebtoken.io.Serializer with
io.jsonwebtoken.gson.io.GsonSerializer;
}
3 changes: 2 additions & 1 deletion extensions/jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@
</plugin>
</plugins>
</build>
</project>

</project>
13 changes: 13 additions & 0 deletions extensions/jackson/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module io.jsonwebtoken.jjwt.ext.jackson {
requires transitive com.fasterxml.jackson.core;
requires transitive com.fasterxml.jackson.databind;
requires io.jsonwebtoken.jjwt.api;

exports io.jsonwebtoken.jackson.io;

provides io.jsonwebtoken.io.Deserializer with
io.jsonwebtoken.jackson.io.JacksonDeserializer;
provides io.jsonwebtoken.io.Serializer with
io.jsonwebtoken.jackson.io.JacksonSerializer;

}
3 changes: 2 additions & 1 deletion extensions/orgjson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@
</plugin>
</plugins>
</build>
</project>

</project>
9 changes: 9 additions & 0 deletions extensions/orgjson/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module io.jsonwebtoken.jjwt.ext.orgjson {
requires transitive org.json;
requires io.jsonwebtoken.jjwt.api;

exports io.jsonwebtoken.orgjson.io;

provides io.jsonwebtoken.io.Deserializer with io.jsonwebtoken.orgjson.io.OrgJsonDeserializer;
provides io.jsonwebtoken.io.Serializer with io.jsonwebtoken.orgjson.io.OrgJsonSerializer;
}
2 changes: 1 addition & 1 deletion impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
</dependency>
</dependencies>

</project>
</project>
15 changes: 15 additions & 0 deletions impl/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module io.jsonwebtoken.jjwt.impl {
requires io.jsonwebtoken.jjwt.api;

exports io.jsonwebtoken.impl;
exports io.jsonwebtoken.impl.compression;
exports io.jsonwebtoken.impl.lang;

provides io.jsonwebtoken.CompressionCodec with
io.jsonwebtoken.impl.compression.DeflateCompressionAlgorithm,
io.jsonwebtoken.impl.compression.GzipCompressionAlgorithm;

uses io.jsonwebtoken.CompressionCodec;
uses io.jsonwebtoken.io.Deserializer;
uses io.jsonwebtoken.io.Serializer;
}
25 changes: 25 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-root</artifactId>
<version>0.12.7-SNAPSHOT</version>
</parent>

<artifactId>jjwt-integration-tests</artifactId>
<name>JJWT :: Integration-Tests</name>
<packaging>pom</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<modules>
<module>unsigned-jackson</module>
</modules>

</project>
72 changes: 72 additions & 0 deletions integration-tests/unsigned-jackson/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-integration-tests</artifactId>
<version>0.12.7-SNAPSHOT</version>
</parent>

<artifactId>jjwt-integration-tests-unsigned-jackson</artifactId>
<name>JJWT :: Integration-Tests :: unsigned-jackson</name>
<description>Create and parse an unsigned JWT using Jackson and JPMS.</description>
<packaging>jar</packaging>

<properties>
<maven.compiler.release>9</maven.compiler.release>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
<detectJavaApiLink>false</detectJavaApiLink>
</configuration>
</plugin>
<!--
this plugin needs to be disabled as long as we are stuck with plugin version 3.3.0, as it cannot
handle Java 9 module-info.class files.
This will also use an empty MANIFEST.MF file, since there is no way in maven to unsetting
an entry (like archive/manifestFile for the jar plugin).
-->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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"))
.subject("jjwt")
.id("jjwt-0")
.issuedAt(Date.from(Instant.now()))
.notBefore(Date.from(Instant.now()))
.compact();
}

public Jwt<Header, Claims> read(String jwt) {
final JwtParser jwtParser = Jwts.parser()
.unsecured()
.requireSubject("jjwt")
.build();

return jwtParser.parseUnsecuredClaims(jwt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module io.jsonwebtoken.jjwt.it.unsigned {
requires io.jsonwebtoken.jjwt.api;

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.jsonwebtoken.it.unsigned;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jws;
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<Header, Claims> readBackJws = jwtCreator.read(jwtString);

// then
final Claims jwtBody = readBackJws.getPayload();
assertEquals("jjwt-0", jwtBody.getId());
assertEquals("jjwt", jwtBody.getSubject());
assertTrue(jwtBody.get("roles", List.class).contains("admin"));
}

}
29 changes: 27 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Expand Down Expand Up @@ -689,6 +687,8 @@
<jdk>[1.8,)</jdk>
</activation>
<properties>
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>
<gmavenplus.version>3.0.2</gmavenplus.version>
<groovy.version>3.0.19</groovy.version>
<easymock.version>4.2</easymock.version>
Expand Down Expand Up @@ -733,7 +733,32 @@
<surefire.useModulePath>false</surefire.useModulePath>
<maven.javadoc.additionalOptions>-html5</maven.javadoc.additionalOptions>
<surefire.argLine>${test.addOpens}, --illegal-access=debug</surefire.argLine>
<maven.compiler.release>${jdk.version}</maven.compiler.release>
</properties>
<modules>
<module>integration-tests</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile-module-info</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>${project.basedir}/src/main/java9</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk17AndLater</id>
Expand Down

0 comments on commit 5066c68

Please sign in to comment.