From 3fdb2ae432d25e2fba15e718ea04535962911deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Walkiewicz?= Date: Tue, 28 Jun 2022 12:53:06 +0200 Subject: [PATCH] Simplify logic of getting value of OIDC field --- .../server/security/oauth2/OidcDiscovery.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/server/security/oauth2/OidcDiscovery.java b/core/trino-main/src/main/java/io/trino/server/security/oauth2/OidcDiscovery.java index 1e67bd660330..4ecaa614bc92 100644 --- a/core/trino-main/src/main/java/io/trino/server/security/oauth2/OidcDiscovery.java +++ b/core/trino-main/src/main/java/io/trino/server/security/oauth2/OidcDiscovery.java @@ -142,16 +142,23 @@ private static URI getRequiredField(String metadataField, URI metadataValue, Str private static Optional getOptionalField(String metadataField, Optional metadataValue, String configurationField, Optional configurationValue) { - if (configurationValue.isPresent()) { - if (!configurationValue.equals(metadataValue)) { - LOG.warn("Overriding \"%s=%s\" from OpenID metadata document with value \"%s=%s\" defined in configuration", - metadataField, metadataValue.orElse(""), configurationField, configurationValue.orElse("")); - } else { - LOG.warn("Provided redundant configuration property \"%s\" with the same value as \"%s\" field in OpenID metadata document"); - } + if (configurationValue.isEmpty()) { + return metadataValue; + } + + if (metadataValue.isEmpty()) { return configurationValue; } - return metadataValue; + + if (!configurationValue.equals(metadataValue)) { + LOG.warn("Overriding \"%s=%s\" from OpenID metadata document with value \"%s=%s\" defined in configuration", + metadataField, metadataValue.orElse(""), configurationField, configurationValue.orElse("")); + } + else { + LOG.warn("Provided redundant configuration property \"%s\" with the same value as \"%s\" field in OpenID metadata document", + configurationField, metadataField); + } + return configurationValue; } private static void checkMetadataState(boolean expression, String additionalMessage, String... additionalMessageArgs)