From 6646071ce5f31619a055a714dcd6521eea290ab6 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Thu, 15 Jun 2023 13:27:02 +0100 Subject: [PATCH] Do not require custom TenantResolver when named tenants are configured --- .../java/io/quarkus/oidc/OidcTenantConfig.java | 5 +++-- .../java/io/quarkus/oidc/runtime/OidcRecorder.java | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcTenantConfig.java b/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcTenantConfig.java index 0ff84fb10d26f..912fdd4281771 100644 --- a/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcTenantConfig.java +++ b/extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcTenantConfig.java @@ -31,8 +31,9 @@ public class OidcTenantConfig extends OidcCommonConfig { /** * If this tenant configuration is enabled. * - * Note that the default tenant will be disabled if it is not configured - * but either {@link TenantResolver} or {@link TenantConfigResolver} are registered. + * Note that the default tenant will be disabled if it is not configured but either + * {@link TenantConfigResolver} which will resolve tenant configurations is registered + * or named tenants are configured. * You do not have to disable the default tenant in this case. */ @ConfigItem(defaultValue = "true") 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 1a77ace20ff89..7771095192dd2 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 @@ -24,7 +24,6 @@ import io.quarkus.oidc.OidcTenantConfig.Roles.Source; import io.quarkus.oidc.OidcTenantConfig.TokenStateManager.Strategy; import io.quarkus.oidc.TenantConfigResolver; -import io.quarkus.oidc.TenantResolver; import io.quarkus.oidc.common.runtime.OidcCommonConfig; import io.quarkus.oidc.common.runtime.OidcCommonUtils; import io.quarkus.runtime.ExecutorRecorder; @@ -115,9 +114,9 @@ public TenantConfigContext apply(TenantConfigContext t) { } private TenantConfigContext createStaticTenantContext(Vertx vertx, - OidcTenantConfig oidcConfig, boolean checkTenantResolver, TlsConfig tlsConfig, String tenantId) { + OidcTenantConfig oidcConfig, boolean checkNamedTenants, TlsConfig tlsConfig, String tenantId) { - Uni uniContext = createTenantContext(vertx, oidcConfig, checkTenantResolver, tlsConfig, tenantId); + Uni uniContext = createTenantContext(vertx, oidcConfig, checkNamedTenants, tlsConfig, tenantId); return uniContext.onFailure() .recoverWithItem(new Function() { @Override @@ -152,7 +151,7 @@ private static Throwable logTenantConfigContextFailure(Throwable t, String tenan @SuppressWarnings("resource") private Uni createTenantContext(Vertx vertx, OidcTenantConfig oidcTenantConfig, - boolean checkTenantResolver, + boolean checkNamedTenants, TlsConfig tlsConfig, String tenantId) { if (!oidcTenantConfig.tenantId.isPresent()) { oidcTenantConfig.tenantId = Optional.of(tenantId); @@ -174,11 +173,10 @@ private Uni createTenantContext(Vertx vertx, OidcTenantConf if (OidcUtils.DEFAULT_TENANT_ID.equals(oidcConfig.tenantId.get())) { ArcContainer container = Arc.container(); if (container != null - && (container.instance(TenantConfigResolver.class).isAvailable() - || (checkTenantResolver && container.instance(TenantResolver.class).isAvailable()))) { + && (container.instance(TenantConfigResolver.class).isAvailable() || checkNamedTenants)) { LOG.debugf("Default tenant is not configured and will be disabled" - + " because either 'TenantConfigResolver' or `TenantResolver`which will resolve" - + " tenant configurations are registered"); + + " because either 'TenantConfigResolver' which will resolve tenant configurations is registered" + + " or named tenants are configured."); oidcConfig.setTenantEnabled(false); return Uni.createFrom() .item(new TenantConfigContext(new OidcProvider(null, null, null, null), oidcConfig));