diff --git a/bom/pom.xml b/bom/pom.xml index 8da76f66e6..a63e2ccaf7 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -36,22 +36,22 @@ 0.9.5 - 2.14.3 - 1.4.2 + 2.16.1 + 1.4.3 0.6.1 - 3.5.1 + 3.6.1 1.3.3 2.9.2 0.3.0 1.8.0 - 1.0.1 + 1.0.2 1.0.0 1.0.1 1.0.0 1.0.0 1.0.0 - 2.5.0 + 2.5.1 4.2.9 @@ -59,14 +59,14 @@ 4.10.2 - 0.11.5 + 0.12.5 9.2 - 1.10.0 + 1.11.0 7.0.0 5.18.0 1.0.4 - 4.1.99.Final - 2.3.0 + 4.1.106.Final + 2.5.0 2.0.11 1.4.14 @@ -75,7 +75,7 @@ 3.1.11 - 2.6.6 + 2.7.0 3.0.2 diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DittoPublicKeyProvider.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DittoPublicKeyProvider.java index ec8206776f..dbd4ca1fec 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DittoPublicKeyProvider.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DittoPublicKeyProvider.java @@ -38,6 +38,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.pekko.http.javadsl.model.HttpRequest; +import org.apache.pekko.http.javadsl.model.HttpResponse; +import org.apache.pekko.stream.Materializer; +import org.apache.pekko.stream.SystemMaterializer; +import org.apache.pekko.stream.javadsl.Sink; +import org.apache.pekko.util.ByteString; import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException; import org.eclipse.ditto.gateway.api.GatewayAuthenticationProviderUnavailableException; import org.eclipse.ditto.gateway.api.GatewayJwtIssuerNotSupportedException; @@ -65,12 +71,6 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalListener; -import org.apache.pekko.http.javadsl.model.HttpRequest; -import org.apache.pekko.http.javadsl.model.HttpResponse; -import org.apache.pekko.stream.Materializer; -import org.apache.pekko.stream.SystemMaterializer; -import org.apache.pekko.stream.javadsl.Sink; -import org.apache.pekko.util.ByteString; import io.jsonwebtoken.JwtParser; import io.jsonwebtoken.Jwts; @@ -391,10 +391,10 @@ private static JwkInvalidException getJwkInvalidExceptionException(final String } private PublicKeyWithParser mapToPublicKeyWithParser(final PublicKey publicKey) { - final var jwtParserBuilder = Jwts.parserBuilder(); - final JwtParser jwtParser = jwtParserBuilder.deserializeJsonWith(JjwtDeserializer.getInstance()) - .setSigningKey(publicKey) - .setAllowedClockSkewSeconds(oAuthConfig.getAllowedClockSkew().getSeconds()) + final var jwtParserBuilder = Jwts.parser(); + final JwtParser jwtParser = jwtParserBuilder.json(JjwtDeserializer.getInstance()) + .verifyWith(publicKey) + .clockSkewSeconds(oAuthConfig.getAllowedClockSkew().getSeconds()) .build(); return new PublicKeyWithParser(publicKey, jwtParser); diff --git a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtValidatorTest.java b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtValidatorTest.java index 7991b0489f..4884d1b5c6 100644 --- a/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtValidatorTest.java +++ b/gateway/service/src/test/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtValidatorTest.java @@ -95,10 +95,10 @@ public void validate() throws ExecutionException, InterruptedException { } private JwtParser getJwtParser(final PublicKey publicKey) { - final var jwtParserBuilder = Jwts.parserBuilder(); - return jwtParserBuilder.deserializeJsonWith(JjwtDeserializer.getInstance()) - .setSigningKey(publicKey) - .setAllowedClockSkewSeconds(oAuthConfig.getAllowedClockSkew().getSeconds()) + final var jwtParserBuilder = Jwts.parser(); + return jwtParserBuilder.json(JjwtDeserializer.getInstance()) + .verifyWith(publicKey) + .clockSkewSeconds(oAuthConfig.getAllowedClockSkew().getSeconds()) .build(); } diff --git a/internal/utils/cluster/src/main/java/org/eclipse/ditto/internal/utils/cluster/JsonValueSourceRef.java b/internal/utils/cluster/src/main/java/org/eclipse/ditto/internal/utils/cluster/JsonValueSourceRef.java index 01802d8cb0..b002082312 100644 --- a/internal/utils/cluster/src/main/java/org/eclipse/ditto/internal/utils/cluster/JsonValueSourceRef.java +++ b/internal/utils/cluster/src/main/java/org/eclipse/ditto/internal/utils/cluster/JsonValueSourceRef.java @@ -17,15 +17,15 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.json.JsonValue; +import org.apache.pekko.NotUsed; +import org.apache.pekko.stream.SourceRef; +import org.apache.pekko.stream.javadsl.Source; import org.eclipse.ditto.base.model.common.ConditionChecker; +import org.eclipse.ditto.json.JsonValue; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; - -import org.apache.pekko.NotUsed; -import org.apache.pekko.stream.SourceRef; -import org.apache.pekko.stream.javadsl.Source; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Wraps a {@link SourceRef} of {@link JsonValue}s. The purpose of this class is to make working with SourceRef type @@ -51,7 +51,7 @@ private JsonValueSourceRef(final SourceRef sourceRef) { * @throws NullPointerException if {@code sourceRef} is {@code null}. */ @JsonCreator - public static JsonValueSourceRef of(final SourceRef sourceRef) { + public static JsonValueSourceRef of(@JsonProperty("sourceRef") final SourceRef sourceRef) { return new JsonValueSourceRef(ConditionChecker.checkNotNull(sourceRef, "sourceRef")); } diff --git a/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializer.java b/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializer.java index 6294c9f6c2..8601dd935c 100644 --- a/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializer.java +++ b/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializer.java @@ -12,7 +12,7 @@ */ package org.eclipse.ditto.internal.utils.jwt; -import java.nio.charset.StandardCharsets; +import java.io.Reader; import java.text.MessageFormat; import java.util.List; import java.util.Map; @@ -20,13 +20,13 @@ import javax.annotation.concurrent.Immutable; -import org.eclipse.ditto.base.model.common.ConditionChecker; import org.eclipse.ditto.json.JsonArray; -import org.eclipse.ditto.json.JsonFactory; import org.eclipse.ditto.json.JsonField; import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.json.JsonValueParser; +import io.jsonwebtoken.io.AbstractDeserializer; import io.jsonwebtoken.io.DeserializationException; import io.jsonwebtoken.io.Deserializer; @@ -34,7 +34,7 @@ * JJWT library Deserializer implementation which translates JSON strings to Java Objects (e.g. Maps). */ @Immutable -public final class JjwtDeserializer implements Deserializer> { +public final class JjwtDeserializer extends AbstractDeserializer> { private static Deserializer> instance; @@ -49,27 +49,15 @@ public final class JjwtDeserializer implements Deserializer> { } @Override - public Map deserialize(final byte[] bytes) { - - ConditionChecker.argumentNotNull(bytes, "JSON byte array cannot be null"); - - if (bytes.length == 0) { - throw new DeserializationException("Invalid JSON: zero length byte array."); - } - + @SuppressWarnings("unchecked") + protected Map doDeserialize(final Reader reader) throws Exception { try { - return parse(new String(bytes, StandardCharsets.UTF_8)); + return (Map) toJavaObject(JsonValueParser.fromReader().apply(reader)); } catch (final Exception e) { throw new DeserializationException("Invalid JSON: " + e.getMessage(), e); } } - @SuppressWarnings("unchecked") - private static Map parse(final String json) { - - return (Map) toJavaObject(JsonFactory.readFrom(json)); - } - private static Map toJavaMap(final JsonObject jsonObject) { return jsonObject.stream() .collect(Collectors.toMap(JsonField::getKeyName, field -> toJavaObject(field.getValue()))); diff --git a/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtSerializer.java b/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtSerializer.java index 5cc54a239e..510e04ab31 100644 --- a/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtSerializer.java +++ b/internal/utils/jwt/src/main/java/org/eclipse/ditto/internal/utils/jwt/JjwtSerializer.java @@ -12,6 +12,8 @@ */ package org.eclipse.ditto.internal.utils.jwt; +import java.io.IOException; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.Collection; @@ -28,6 +30,7 @@ import org.eclipse.ditto.json.JsonObject; import org.eclipse.ditto.json.JsonValue; +import io.jsonwebtoken.io.AbstractSerializer; import io.jsonwebtoken.io.Encoders; import io.jsonwebtoken.io.SerializationException; import io.jsonwebtoken.io.Serializer; @@ -39,7 +42,7 @@ * JJWT library Serializer implementation which translates Java Objects (e.g. Maps) to JSON strings. */ @Immutable -public final class JjwtSerializer implements Serializer> { +public final class JjwtSerializer extends AbstractSerializer> { private static Serializer> instance; @@ -54,15 +57,12 @@ public final class JjwtSerializer implements Serializer> { } @Override - public byte[] serialize(final Map t) { - + protected void doSerialize(final Map stringMap, final OutputStream out) throws Exception { try { - return toJson(t).toString().getBytes(StandardCharsets.UTF_8); - } catch (final SerializationException se) { - throw se; - } catch (final Exception e) { + out.write(toJson(stringMap).toString().getBytes(StandardCharsets.UTF_8)); + } catch (final IOException e) { throw new SerializationException("Unable to serialize object of type " + - Optional.ofNullable(t).map(obj -> obj.getClass().getName()).orElse("") + + Optional.ofNullable(stringMap).map(obj -> obj.getClass().getName()).orElse("") + " to JSON: " + e.getMessage(), e); } } @@ -91,7 +91,7 @@ private static JsonValue toJson(final Object input) { return JsonFactory.newValue(Encoders.BASE64.encode((bytes))); } else if (input instanceof char[] chars) { return JsonFactory.newValue(new String(chars)); - } else if (input instanceof Map map) { + } else if (input instanceof Map map) { return toJsonObject(map); } else if (input instanceof Collection collection) { return toJsonArray(collection); diff --git a/internal/utils/jwt/src/test/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializerTest.java b/internal/utils/jwt/src/test/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializerTest.java index 8fed2ee373..b265718718 100644 --- a/internal/utils/jwt/src/test/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializerTest.java +++ b/internal/utils/jwt/src/test/java/org/eclipse/ditto/internal/utils/jwt/JjwtDeserializerTest.java @@ -39,22 +39,22 @@ public void foo() { claims.put(Claims.ISSUER, KNOWN_ISS); claims.put(Claims.SUBJECT, KNOWN_SUB); final String compact = Jwts.builder() - .serializeToJsonWith(JjwtSerializer.getInstance()) - .setClaims(claims) - .setExpiration(KNOWN_EXP) + .json(JjwtSerializer.getInstance()) + .claims(claims) + .expiration(KNOWN_EXP) .compact(); - final Jwt jwt = Jwts.parserBuilder() - .deserializeJsonWith(JjwtDeserializer.getInstance()) + final Jwt jwt = Jwts.parser().json(JjwtDeserializer.getInstance()) + .unsecured() .build() .parse(compact); - final Object jwtBody = jwt.getBody(); + final Object jwtBody = jwt.getPayload(); Assertions.assertThat(jwtBody).isInstanceOf(Claims.class); Assertions.assertThat(((Claims) jwtBody)).containsEntry(Claims.ISSUER, KNOWN_ISS) .containsEntry(Claims.SUBJECT, KNOWN_SUB) - .containsEntry(Claims.EXPIRATION, (int) (KNOWN_EXP.getTime() / 1000L)); + .containsEntry(Claims.EXPIRATION, (KNOWN_EXP.getTime() / 1000L)); } } diff --git a/json/src/main/java/org/eclipse/ditto/json/DefaultDittoJsonHandler.java b/json/src/main/java/org/eclipse/ditto/json/DefaultDittoJsonHandler.java index c9f0db1e48..d51e071b1c 100644 --- a/json/src/main/java/org/eclipse/ditto/json/DefaultDittoJsonHandler.java +++ b/json/src/main/java/org/eclipse/ditto/json/DefaultDittoJsonHandler.java @@ -27,7 +27,7 @@ * for creating a new {@link JsonArray} or {@link JsonObject}. */ @NotThreadSafe -final class DefaultDittoJsonHandler extends DittoJsonHandler, List, JsonValue> { +public final class DefaultDittoJsonHandler extends DittoJsonHandler, List, JsonValue> { private static final int DEFAULT_INITIAL_STRING_BUILDER_CAPACITY = 512; private static final char DELIMITER = ','; diff --git a/json/src/main/java/org/eclipse/ditto/json/JsonValueParser.java b/json/src/main/java/org/eclipse/ditto/json/JsonValueParser.java index 6e4dd4f2a8..c6f0fbaa5a 100644 --- a/json/src/main/java/org/eclipse/ditto/json/JsonValueParser.java +++ b/json/src/main/java/org/eclipse/ditto/json/JsonValueParser.java @@ -30,7 +30,7 @@ * This class provides access to functionality for parsing a {@link JsonValue} from various inputs. */ @Immutable -final class JsonValueParser { +public final class JsonValueParser { @Nullable private static Function fromStringInstance = null;