diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DefaultJwtValidator.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DefaultJwtValidator.java index eba174a53d..cb0fe5f629 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DefaultJwtValidator.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/DefaultJwtValidator.java @@ -19,7 +19,6 @@ import org.eclipse.ditto.base.model.common.BinaryValidationResult; import org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayAuthenticationFailedException; -import org.eclipse.ditto.gateway.service.util.config.security.OAuthConfig; import org.eclipse.ditto.jwt.model.JsonWebToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,22 +34,19 @@ public final class DefaultJwtValidator implements JwtValidator { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJwtValidator.class); private final PublicKeyProvider publicKeyProvider; - private final OAuthConfig oAuthConfig; - private DefaultJwtValidator(final PublicKeyProvider publicKeyProvider, final OAuthConfig oAuthConfig) { + private DefaultJwtValidator(final PublicKeyProvider publicKeyProvider) { this.publicKeyProvider = publicKeyProvider; - this.oAuthConfig = oAuthConfig; } /** * Creates a new {@code JwtValidator} instance. * * @param publicKeyProvider provider for public keys of jwt issuers. - * @param oAuthConfig the OAuth config. * @return the instance. */ - public static JwtValidator of(final PublicKeyProvider publicKeyProvider, final OAuthConfig oAuthConfig) { - return new DefaultJwtValidator(publicKeyProvider, oAuthConfig); + public static JwtValidator of(final PublicKeyProvider publicKeyProvider) { + return new DefaultJwtValidator(publicKeyProvider); } @Override @@ -60,7 +56,8 @@ public CompletableFuture validate(final JsonWebToken jso return publicKeyProvider.getPublicKeyWithParser(issuer, keyId) .thenApply(publicKeyWithParserOpt -> publicKeyWithParserOpt - .map(publicKeyWithParser -> tryToValidateWithJwtParser(jsonWebToken, publicKeyWithParser.getJwtParser())) + .map(publicKeyWithParser -> tryToValidateWithJwtParser(jsonWebToken, + publicKeyWithParser.getJwtParser())) .orElseGet(() -> { final var msgPattern = "Public Key of issuer <{0}> with key ID <{1}> not found!"; final var msg = MessageFormat.format(msgPattern, issuer, keyId); @@ -70,7 +67,8 @@ public CompletableFuture validate(final JsonWebToken jso })); } - private BinaryValidationResult tryToValidateWithJwtParser(final JsonWebToken jsonWebToken, final JwtParser jwtParser) { + private BinaryValidationResult tryToValidateWithJwtParser(final JsonWebToken jsonWebToken, + final JwtParser jwtParser) { try { return validateWithJwtParser(jsonWebToken, jwtParser); } catch (final Exception e) { diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtAuthenticationFactory.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtAuthenticationFactory.java index 6f00452e61..ba85353996 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtAuthenticationFactory.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/JwtAuthenticationFactory.java @@ -68,7 +68,7 @@ public static JwtAuthenticationFactory newInstance(final OAuthConfig oAuthConfig public JwtValidator getJwtValidator() { if (null == jwtValidator) { - jwtValidator = DefaultJwtValidator.of(getPublicKeyProvider(), oAuthConfig); + jwtValidator = DefaultJwtValidator.of(getPublicKeyProvider()); } return jwtValidator; } diff --git a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/PublicKeyWithParser.java b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/PublicKeyWithParser.java index 2fe060d009..4c98eec2fd 100644 --- a/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/PublicKeyWithParser.java +++ b/gateway/service/src/main/java/org/eclipse/ditto/gateway/service/security/authentication/jwt/PublicKeyWithParser.java @@ -31,7 +31,6 @@ final class PublicKeyWithParser { * * @param publicKey publicKey to use for jwt parsing. * @param jwtParser the actual jwtParser using the given publicKey. - * @return the instance. */ PublicKeyWithParser(final PublicKey publicKey, final JwtParser jwtParser) { this.publicKey = publicKey; @@ -62,9 +61,9 @@ public int hashCode() { @Override public String toString() { - return "PublicKeyWithParser{" + - "publicKey=" + publicKey + - ", jwtParser=" + jwtParser + - '}'; + return getClass().getSimpleName() + " [" + + "publicKey=" + publicKey + + ", jwtParser=" + 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 5ab04e3284..ffce9d9226 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 @@ -87,7 +87,7 @@ public void validate() throws ExecutionException, InterruptedException { when(publicKeyProvider.getPublicKeyWithParser(JwtTestConstants.ISSUER, JwtTestConstants.KEY_ID)).thenReturn( CompletableFuture.completedFuture(Optional.of(new PublicKeyWithParser(JwtTestConstants.PUBLIC_KEY, getJwtParser(JwtTestConstants.PUBLIC_KEY))))); - final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider, oAuthConfig); + final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider); final BinaryValidationResult jwtValidationResult = underTest.validate(VALID_JSON_WEB_TOKEN).get(); @@ -107,7 +107,7 @@ public void validateTokenWithNbfAheadOfTime() throws ExecutionException, Interru when(publicKeyProvider.getPublicKeyWithParser(JwtTestConstants.ISSUER, JwtTestConstants.KEY_ID)).thenReturn( CompletableFuture.completedFuture(Optional.of(new PublicKeyWithParser(JwtTestConstants.PUBLIC_KEY, getJwtParser(JwtTestConstants.PUBLIC_KEY))))); - final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider, oAuthConfig); + final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider); final BinaryValidationResult jwtValidationResult = underTest.validate(VALID_JSON_WEB_TOKEN_WITH_NBF_AHEAD_OF_TIME).get(); @@ -120,7 +120,7 @@ public void validateFailsIfNbfIsTooFarInTheFuture() throws ExecutionException, I when(publicKeyProvider.getPublicKeyWithParser(JwtTestConstants.ISSUER, JwtTestConstants.KEY_ID)).thenReturn( CompletableFuture.completedFuture(Optional.of(new PublicKeyWithParser(JwtTestConstants.PUBLIC_KEY, getJwtParser(JwtTestConstants.PUBLIC_KEY))))); - final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider, oAuthConfig); + final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider); final BinaryValidationResult jwtValidationResult = underTest.validate(INVALID_JSON_WEB_TOKEN_WITH_NBF_AHEAD_OF_TIME).get(); @@ -133,7 +133,7 @@ public void validateFailsIfSignatureIsMissing() throws ExecutionException, Inter when(publicKeyProvider.getPublicKeyWithParser(JwtTestConstants.ISSUER, JwtTestConstants.KEY_ID)).thenReturn( CompletableFuture.completedFuture(Optional.of(new PublicKeyWithParser(JwtTestConstants.PUBLIC_KEY, getJwtParser(JwtTestConstants.PUBLIC_KEY))))); - final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider, oAuthConfig); + final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider); final BinaryValidationResult jwtValidationResult = underTest.validate(VALID_JSON_WEB_TOKEN_WITHOUT_SIGNATURE).get(); @@ -148,7 +148,7 @@ public void validateFails() throws ExecutionException, InterruptedException { .thenReturn(CompletableFuture.completedFuture(Optional.of(new PublicKeyWithParser(JwtTestConstants.PUBLIC_KEY, getJwtParser(JwtTestConstants.PUBLIC_KEY))))); - final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider, oAuthConfig); + final JwtValidator underTest = DefaultJwtValidator.of(publicKeyProvider); final BinaryValidationResult jwtValidationResult = underTest.validate(INVALID_JSON_WEB_TOKEN).get();