Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the implementation module into common, jwt-auth, jwt-build #331

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion doc/modules/ROOT/pages/generate-jwt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ https://tools.ietf.org/html/rfc7516[JSON Web Encryption] specification to produc
Finally both the confidentiality and integrity of the claims can be further enforced by signing them first and then
encrypting the nested JWT token.

SmallRye JWT provides an API for securing the JWT claims using all of these options.
SmallRye JWT project provides a JWT Build API for securing the JWT claims using all of these options.

== Maven dependency

[source,xml]
----
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-jwt-build</artifactId>
<version>${smallrye.jwt.version}</version>
</dependency>
----

== Create JwtClaimsBuilder and set the claims

Expand Down
108 changes: 108 additions & 0 deletions implementation/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright 2017 Red Hat, Inc.
~
~ 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.
-->

<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.smallrye</groupId>
<artifactId>smallrye-jwt-implementation-parent</artifactId>
<version>2.3.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-jwt-common</artifactId>

<name>SmallRye: MicroProfile JWT Implementation Common</name>

<dependencies>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<executions>
<execution>
<id>default-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>coverage</id>
<properties>
<argLine>@{jacocoArgLine}</argLine>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.smallrye.jwt;
package io.smallrye.jwt.util;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
Expand All @@ -8,21 +8,8 @@
import org.jboss.logging.annotations.MessageLogger;

@MessageLogger(projectCode = "SRJWT", length = 5)
interface JWTLogging extends BasicLogger {
JWTLogging log = Logger.getMessageLogger(JWTLogging.class, JWTLogging.class.getPackage().getName());

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 1000, value = "path.%s configuration will be ignored because the path depth is too large:"
+ " %d, maximum depth is %d.")
void maximumPathDepthReached(String claimName, Object pathDepth, Object maxPathDepthSupported);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 1001, value = "Token header is not 'Cookie', the cookie name value will be ignored")
void tokenHeaderIsNotCookieHeader();

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 1002, value = "Algorithm %s not supported")
void unsupportedAlgorithm(String unsupportedAlgorithm);
interface JWTUtilLogging extends BasicLogger {
JWTUtilLogging log = Logger.getMessageLogger(JWTUtilLogging.class, JWTUtilLogging.class.getPackage().getName());

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 1003, value = "Trying to create a key from the encoded PEM key...")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.smallrye.jwt;
package io.smallrye.jwt.util;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -10,8 +10,8 @@
import org.jboss.logging.annotations.MessageBundle;

@MessageBundle(projectCode = "SRJWT", length = 5)
interface JWTMessages {
JWTMessages msg = Messages.getBundle(JWTMessages.class);
interface JWTUtilMessages {
JWTUtilMessages msg = Messages.getBundle(JWTUtilMessages.class);

@Message(id = 0, value = "Failed to decode the JWKS Public Key")
UncheckedIOException invalidJWKSPublicKey(@Cause IOException ioe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package io.smallrye.jwt;
package io.smallrye.jwt.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -173,7 +173,7 @@ public static PrivateKey decodeDecryptionPrivateKey(String pemEncoded, KeyEncryp
return decodePrivateKeyInternal(pemEncoded, encryptionKeyFactoryAlgorithm(algo));
}

public static PrivateKey decodePrivateKeyInternal(String pemEncoded, String algo) throws GeneralSecurityException {
static PrivateKey decodePrivateKeyInternal(String pemEncoded, String algo) throws GeneralSecurityException {
pemEncoded = removePemKeyBeginEnd(pemEncoded);
byte[] pkcs8EncodedBytes = Base64.getDecoder().decode(pemEncoded);

Expand Down Expand Up @@ -207,7 +207,7 @@ public static PublicKey decodeJWKSPublicKey(String jwksValue) throws GeneralSecu
JsonReader json = Json.createReader(stream)) {
jwks = json.readObject();
} catch (IOException ioe) {
throw JWTMessages.msg.invalidJWKSPublicKey(ioe);
throw JWTUtilMessages.msg.invalidJWKSPublicKey(ioe);
}
}
JsonArray keys = jwks.getJsonArray("keys");
Expand Down Expand Up @@ -280,7 +280,7 @@ static String keyFactoryAlgorithm(SignatureAlgorithm algo) throws NoSuchAlgorith
if (algo.name().startsWith("ES")) {
return EC;
}
throw JWTMessages.msg.unsupportedAlgorithm(algo.name());
throw JWTUtilMessages.msg.unsupportedAlgorithm(algo.name());
}

static String encryptionKeyFactoryAlgorithm(KeyEncryptionAlgorithm algo) throws NoSuchAlgorithmException {
Expand All @@ -290,7 +290,7 @@ static String encryptionKeyFactoryAlgorithm(KeyEncryptionAlgorithm algo) throws
if (algo.name().startsWith("EC")) {
return EC;
}
throw JWTMessages.msg.unsupportedAlgorithm(algo.name());
throw JWTUtilMessages.msg.unsupportedAlgorithm(algo.name());
}

/**
Expand Down Expand Up @@ -352,49 +352,49 @@ static String readKeyContent(String keyLocation) throws IOException {

String content = ResourceUtils.readResource(keyLocation);
if (content == null) {
throw JWTMessages.msg.keyNotFound(keyLocation);
throw JWTUtilMessages.msg.keyNotFound(keyLocation);
}
return content;
}

static PrivateKey tryAsPEMPrivateKey(String content) {
JWTLogging.log.creatingKeyFromPemKey();
JWTUtilLogging.log.creatingKeyFromPemKey();
try {
return decodePrivateKey(content);
} catch (Exception e) {
JWTLogging.log.creatingKeyFromPemKeyFailed(e);
JWTUtilLogging.log.creatingKeyFromPemKeyFailed(e);
}
return null;
}

static PublicKey tryAsPEMPublicKey(String content) {
JWTLogging.log.creatingKeyFromPemKey();
JWTUtilLogging.log.creatingKeyFromPemKey();
try {
return KeyUtils.decodePublicKey(content);
} catch (Exception e) {
JWTLogging.log.creatingKeyFromPemKeyFailed(e);
JWTUtilLogging.log.creatingKeyFromPemKeyFailed(e);
}
return null;
}

static PublicKey tryAsPEMCertificate(String content) {
JWTLogging.log.creatingKeyFromPemCertificate();
JWTUtilLogging.log.creatingKeyFromPemCertificate();
try {
return KeyUtils.decodeCertificate(content);
} catch (Exception e) {
JWTLogging.log.creatingKeyFromPemCertificateFailed(e);
JWTUtilLogging.log.creatingKeyFromPemCertificateFailed(e);
}
return null;
}

public static List<JsonWebKey> loadJsonWebKeys(String content) {
JWTLogging.log.loadingJwks();
JWTUtilLogging.log.loadingJwks();

JsonObject jwks = null;
try (JsonReader reader = Json.createReader(new StringReader(content))) {
jwks = reader.readObject();
} catch (Exception ex) {
JWTLogging.log.loadingJwksFailed(ex);
JWTUtilLogging.log.loadingJwksFailed(ex);
return null;
}

Expand All @@ -413,7 +413,7 @@ public static List<JsonWebKey> loadJsonWebKeys(String content) {
localKeys = Collections.singletonList(createJsonWebKey(jwks));
}
} catch (Exception ex) {
JWTLogging.log.parsingJwksFailed();
JWTUtilLogging.log.parsingJwksFailed();
return null;
}
return localKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package io.smallrye.jwt;
package io.smallrye.jwt.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
Expand Down
Loading