From 93d6818314c50ab0ae9e5c25dbae0b7619530dc3 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Thu, 11 Mar 2021 14:26:41 +0000 Subject: [PATCH] Distinguish between Oidc and OidcClient configuration exceptions --- .../oidc/client/runtime/OidcClientRecorder.java | 2 +- .../oidc/common/runtime/OidcCommonUtils.java | 13 +++++++++---- .../java/io/quarkus/oidc/runtime/OidcRecorder.java | 4 +--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientRecorder.java b/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientRecorder.java index 9c28f7741aeb51..7ea0df89b5fcfb 100644 --- a/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientRecorder.java +++ b/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientRecorder.java @@ -97,7 +97,7 @@ protected static Uni createOidcClientUni(OidcClientConfig oidcConfig oidcConfig.setId(oidcClientId); } - OidcCommonUtils.verifyCommonConfiguration(oidcConfig); + OidcCommonUtils.verifyCommonConfiguration(oidcConfig, false); String authServerUriString = OidcCommonUtils.getAuthServerUrl(oidcConfig); diff --git a/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/OidcCommonUtils.java b/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/OidcCommonUtils.java index a560416d6e387a..a694ad270cca74 100644 --- a/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/OidcCommonUtils.java +++ b/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/OidcCommonUtils.java @@ -28,19 +28,24 @@ private OidcCommonUtils() { } - public static void verifyCommonConfiguration(OidcCommonConfig oidcConfig) { + public static void verifyCommonConfiguration(OidcCommonConfig oidcConfig, boolean isServerConfig) { + final String configPrefix = isServerConfig ? "quarkus.oidc." : "quarkus.oidc-client."; if (!oidcConfig.getAuthServerUrl().isPresent() || !oidcConfig.getClientId().isPresent()) { - throw new ConfigurationException("Both 'auth-server-url' and 'client-id' properties must be configured"); + throw new ConfigurationException( + String.format("Both '%sauth-server-url' and '%sclient-id' properties must be configured", configPrefix)); } Credentials creds = oidcConfig.getCredentials(); if (creds.secret.isPresent() && creds.clientSecret.value.isPresent()) { throw new ConfigurationException( - "'credentials.secret' and 'credentials.client-secret' properties are mutually exclusive"); + String.format("'%scredentials.secret' and '%scredentials.client-secret' properties are mutually exclusive", + configPrefix)); } if ((creds.secret.isPresent() || creds.clientSecret.value.isPresent()) && creds.jwt.secret.isPresent()) { throw new ConfigurationException( - "Use only 'credentials.secret' or 'credentials.client-secret' or 'credentials.jwt.secret' property"); + String.format( + "Use only '%scredentials.secret' or '%scredentials.client-secret' or '%scredentials.jwt.secret' property", + configPrefix)); } } diff --git a/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcRecorder.java b/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcRecorder.java index e6bb891ba32953..870965b1d18439 100644 --- a/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcRecorder.java +++ b/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcRecorder.java @@ -114,7 +114,7 @@ private Uni createTenantContext(Vertx vertx, OidcTenantConf return Uni.createFrom().item(createTenantContextFromPublicKey(oidcConfig)); } - OidcCommonUtils.verifyCommonConfiguration(oidcConfig); + OidcCommonUtils.verifyCommonConfiguration(oidcConfig, true); if (!oidcConfig.discoveryEnabled) { if (oidcConfig.applicationType != ApplicationType.SERVICE) { @@ -213,8 +213,6 @@ public OidcProvider apply(JsonWebKeyCache jwks) { protected static Uni createOidcClientUni(OidcTenantConfig oidcConfig, TlsConfig tlsConfig, Vertx vertx) { - OidcCommonUtils.verifyCommonConfiguration(oidcConfig); - String authServerUriString = OidcCommonUtils.getAuthServerUrl(oidcConfig); WebClientOptions options = new WebClientOptions();