Skip to content

Commit

Permalink
Do not require custom TenantResolver when named tenants are configured
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Jun 15, 2023
1 parent eaa17ea commit 6646071
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TenantConfigContext> uniContext = createTenantContext(vertx, oidcConfig, checkTenantResolver, tlsConfig, tenantId);
Uni<TenantConfigContext> uniContext = createTenantContext(vertx, oidcConfig, checkNamedTenants, tlsConfig, tenantId);
return uniContext.onFailure()
.recoverWithItem(new Function<Throwable, TenantConfigContext>() {
@Override
Expand Down Expand Up @@ -152,7 +151,7 @@ private static Throwable logTenantConfigContextFailure(Throwable t, String tenan

@SuppressWarnings("resource")
private Uni<TenantConfigContext> createTenantContext(Vertx vertx, OidcTenantConfig oidcTenantConfig,
boolean checkTenantResolver,
boolean checkNamedTenants,
TlsConfig tlsConfig, String tenantId) {
if (!oidcTenantConfig.tenantId.isPresent()) {
oidcTenantConfig.tenantId = Optional.of(tenantId);
Expand All @@ -174,11 +173,10 @@ private Uni<TenantConfigContext> 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));
Expand Down

0 comments on commit 6646071

Please sign in to comment.