Skip to content

Commit d6e2301

Browse files
committed
chore(oidc): dont use methods/fields marked for removal
1 parent 63962a0 commit d6e2301

File tree

13 files changed

+147
-103
lines changed

13 files changed

+147
-103
lines changed

extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/OidcDevUIProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
1919
import io.quarkus.devui.spi.page.CardPageBuildItem;
2020
import io.quarkus.oidc.OidcTenantConfig;
21-
import io.quarkus.oidc.OidcTenantConfig.Provider;
2221
import io.quarkus.oidc.deployment.OidcBuildTimeConfig;
22+
import io.quarkus.oidc.runtime.OidcTenantConfig.Provider;
2323
import io.quarkus.oidc.runtime.devui.OidcDevJsonRpcService;
2424
import io.quarkus.oidc.runtime.devui.OidcDevUiRecorder;
2525
import io.quarkus.oidc.runtime.providers.KnownOidcProviders;

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcTenantConfig.java

+7
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,13 @@ public Optional<io.quarkus.oidc.runtime.OidcTenantConfig.Provider> provider() {
30033003
return provider.map(Enum::toString).map(io.quarkus.oidc.runtime.OidcTenantConfig.Provider::valueOf);
30043004
}
30053005

3006+
/**
3007+
* @return new {@link OidcTenantConfig} with {@link OidcTenantConfig#tenantEnabled()} set to {@code false}
3008+
*/
3009+
public OidcTenantConfig disableTenant() {
3010+
return builder(this).disableTenant().build();
3011+
}
3012+
30063013
/**
30073014
* Creates {@link OidcTenantConfigBuilder} builder populated with documented default values.
30083015
*

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,10 @@ private String generateInternalIdToken(TenantConfigContext context, UserInfo use
10401040
} else if (accessTokenExpiresInSecs != null) {
10411041
builder.expiresIn(accessTokenExpiresInSecs);
10421042
}
1043-
builder.audience(context.oidcConfig().getClientId().get());
1043+
builder.audience(context.oidcConfig().clientId().get());
10441044

10451045
JwtSignatureBuilder sigBuilder = builder.jws().header(INTERNAL_IDTOKEN_HEADER, true);
1046-
String clientOrJwtSecret = OidcCommonUtils.getClientOrJwtSecret(context.oidcConfig().credentials);
1046+
String clientOrJwtSecret = OidcCommonUtils.getClientOrJwtSecret(context.oidcConfig().credentials());
10471047
if (clientOrJwtSecret != null) {
10481048
LOG.debug("Signing internal ID token with a configured client secret");
10491049
return sigBuilder.sign(KeyUtils.createSecretKeyFromSecret(clientOrJwtSecret));

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/DefaultTenantConfigResolver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private Uni<OidcTenantConfig> getDynamicTenantConfig(RoutingContext context) {
246246
//shouldn't happen, but guard against it anyway
247247
oidcConfig = Uni.createFrom().nullItem();
248248
} else {
249-
oidcConfig = oidcConfig.onItem().transform(cfg -> OidcUtils.resolveProviderConfig(cfg));
249+
oidcConfig = oidcConfig.map(OidcUtils::resolveProviderConfig);
250250
}
251251
context.put(CURRENT_DYNAMIC_TENANT_CONFIG, oidcConfig);
252252
}
@@ -261,7 +261,7 @@ private Uni<TenantConfigContext> getDynamicTenantContext(RoutingContext context)
261261
@Override
262262
public Uni<? extends TenantConfigContext> apply(OidcTenantConfig tenantConfig) {
263263
if (tenantConfig != null) {
264-
var tenantId = tenantConfig.getTenantId()
264+
var tenantId = tenantConfig.tenantId()
265265
.orElseThrow(() -> new OIDCException("Tenant configuration must have tenant id"));
266266
var tenantContext = tenantConfigBean.getDynamicTenant(tenantId);
267267
if (tenantContext == null) {

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcConfigPropertySupplier.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import org.eclipse.microprofile.config.ConfigProvider;
1111

1212
import io.quarkus.oidc.OidcTenantConfig;
13-
import io.quarkus.oidc.OidcTenantConfig.Provider;
1413
import io.quarkus.oidc.common.runtime.OidcCommonUtils;
1514
import io.quarkus.oidc.common.runtime.OidcConstants;
15+
import io.quarkus.oidc.runtime.OidcTenantConfig.Provider;
1616
import io.quarkus.oidc.runtime.providers.KnownOidcProviders;
1717
import io.smallrye.config.SmallRyeConfig;
1818

@@ -90,16 +90,15 @@ public void setUrlProperty(boolean urlProperty) {
9090
}
9191

9292
public String get(Config config) {
93-
Optional<Provider> provider = config.getOptionalValue(OIDC_PROVIDER_CONFIG_KEY,
94-
Provider.class);
93+
Optional<Provider> provider = config.getOptionalValue(OIDC_PROVIDER_CONFIG_KEY, Provider.class);
9594
OidcTenantConfig providerConfig = provider.isPresent() ? KnownOidcProviders.provider(provider.get()) : null;
9695
if (defaultValue != null || RELATIVE_PATH_CONFIG_PROPS.contains(oidcConfigProperty)) {
9796
Optional<String> value = config.getOptionalValue(oidcConfigProperty, String.class);
9897
if (value.isEmpty() && providerConfig != null) {
9998
if (END_SESSION_PATH_CONFIG_KEY.equals(oidcConfigProperty)) {
10099
value = providerConfig.endSessionPath();
101100
} else if (TOKEN_PATH_CONFIG_KEY.equals(oidcConfigProperty)) {
102-
value = providerConfig.tokenPath;
101+
value = providerConfig.tokenPath();
103102
} else if (AUTH_PATH_CONFIG_KEY.equals(oidcConfigProperty)) {
104103
value = providerConfig.authorizationPath();
105104
}

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class OidcImpl implements Oidc {
1515

16-
private Map<String, OidcTenantConfig> staticTenantConfigs;
16+
private final Map<String, OidcTenantConfig> staticTenantConfigs;
1717
private OidcTenantConfig defaultTenantConfig;
1818

1919
OidcImpl(OidcConfig config) {

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public Key resolveKey(JsonWebSignature jws, List<JsonWebStructure> nestingContex
624624
}
625625

626626
private Key initKey(Key generatedInternalSignatureKey) {
627-
String clientSecret = OidcCommonUtils.getClientOrJwtSecret(oidcConfig.credentials);
627+
String clientSecret = OidcCommonUtils.getClientOrJwtSecret(oidcConfig.credentials());
628628
if (clientSecret != null) {
629629
LOG.debug("Verifying internal ID token with a configured client secret");
630630
return KeyUtils.createSecretKeyFromSecret(clientSecret);

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcProviderClientImpl.java

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public OidcProviderClientImpl(WebClient client,
8686
this.clientSecretQueryAuthentication = oidcConfig.credentials().clientSecret().method().orElse(null) == Method.QUERY;
8787
}
8888

89+
OidcTenantConfig getOidcConfig() {
90+
return oidcConfig;
91+
}
92+
8993
private static ClientAssertionProvider createClientAssertionProvider(Vertx vertx, OidcTenantConfig oidcConfig) {
9094
var clientAssertionProvider = new ClientAssertionProvider(vertx,
9195
oidcConfig.credentials().jwt().tokenPath().get());

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/OidcUtils.java

+58-46
Original file line numberDiff line numberDiff line change
@@ -494,87 +494,99 @@ static OidcTenantConfig mergeTenantConfig(OidcTenantConfig tenant, OidcTenantCon
494494
// OidcRecorder sets it before the merge operation
495495
throw new IllegalStateException();
496496
}
497+
var tenantBuilder = OidcTenantConfig.builder(tenant);
497498
// root properties
498-
if (tenant.authServerUrl().isEmpty()) {
499-
tenant.authServerUrl = provider.authServerUrl();
499+
if (tenant.authServerUrl().isEmpty() && provider.authServerUrl().isPresent()) {
500+
tenantBuilder.authServerUrl(provider.authServerUrl().get());
500501
}
501-
if (tenant.applicationType().isEmpty()) {
502-
tenant.applicationType = provider.applicationType;
502+
if (tenant.applicationType().isEmpty() && provider.applicationType().isPresent()) {
503+
tenantBuilder.applicationType(provider.applicationType().get());
503504
}
504-
if (tenant.discoveryEnabled().isEmpty()) {
505-
tenant.discoveryEnabled = provider.discoveryEnabled();
505+
if (tenant.discoveryEnabled().isEmpty() && provider.discoveryEnabled().isPresent()) {
506+
tenantBuilder.discoveryEnabled(provider.discoveryEnabled().get());
506507
}
507-
if (tenant.authorizationPath().isEmpty()) {
508-
tenant.authorizationPath = provider.authorizationPath();
508+
if (tenant.authorizationPath().isEmpty() && provider.authorizationPath().isPresent()) {
509+
tenantBuilder.authorizationPath(provider.authorizationPath().get());
509510
}
510-
if (tenant.jwksPath().isEmpty()) {
511-
tenant.jwksPath = provider.jwksPath();
511+
if (tenant.jwksPath().isEmpty() && provider.jwksPath().isPresent()) {
512+
tenantBuilder.jwksPath(provider.jwksPath().get());
512513
}
513-
if (tenant.tokenPath().isEmpty()) {
514-
tenant.tokenPath = provider.tokenPath();
514+
if (tenant.tokenPath().isEmpty() && provider.tokenPath().isPresent()) {
515+
tenantBuilder.tokenPath(provider.tokenPath().get());
515516
}
516-
if (tenant.userInfoPath().isEmpty()) {
517-
tenant.userInfoPath = provider.userInfoPath();
517+
if (tenant.userInfoPath().isEmpty() && provider.userInfoPath().isPresent()) {
518+
tenantBuilder.userInfoPath(provider.userInfoPath().get());
518519
}
519520

520521
// authentication
521-
if (tenant.authentication().idTokenRequired().isEmpty()) {
522-
tenant.authentication.idTokenRequired = provider.authentication().idTokenRequired();
522+
var tenantAuth = tenant.authentication();
523+
var providerAuth = provider.authentication();
524+
var authBuilder = tenantBuilder.authentication();
525+
if (tenantAuth.idTokenRequired().isEmpty() && providerAuth.idTokenRequired().isPresent()) {
526+
authBuilder.idTokenRequired(providerAuth.idTokenRequired().get());
523527
}
524-
if (tenant.authentication().userInfoRequired().isEmpty()) {
525-
tenant.authentication.userInfoRequired = provider.authentication().userInfoRequired();
528+
if (tenantAuth.userInfoRequired().isEmpty() && providerAuth.userInfoRequired().isPresent()) {
529+
authBuilder.userInfoRequired(providerAuth.userInfoRequired().get());
526530
}
527-
if (tenant.authentication().pkceRequired().isEmpty()) {
528-
tenant.authentication.pkceRequired = provider.authentication().pkceRequired();
531+
if (tenantAuth.pkceRequired().isEmpty() && providerAuth.pkceRequired().isPresent()) {
532+
authBuilder.pkceRequired(providerAuth.pkceRequired().get());
529533
}
530-
if (tenant.authentication().scopes().isEmpty()) {
531-
tenant.authentication.scopes = provider.authentication().scopes();
534+
if (tenantAuth.scopes().isEmpty() && providerAuth.scopes().isPresent()) {
535+
authBuilder.scopes(providerAuth.scopes().get());
532536
}
533-
if (tenant.authentication().scopeSeparator().isEmpty()) {
534-
tenant.authentication.scopeSeparator = provider.authentication().scopeSeparator();
537+
if (tenantAuth.scopeSeparator().isEmpty() && providerAuth.scopeSeparator().isPresent()) {
538+
authBuilder.scopeSeparator(providerAuth.scopeSeparator().get());
535539
}
536-
if (tenant.authentication().addOpenidScope().isEmpty()) {
537-
tenant.authentication.addOpenidScope = provider.authentication().addOpenidScope();
540+
if (tenantAuth.addOpenidScope().isEmpty() && providerAuth.addOpenidScope().isPresent()) {
541+
authBuilder.addOpenidScope(providerAuth.addOpenidScope().get());
538542
}
539-
if (tenant.authentication().forceRedirectHttpsScheme().isEmpty()) {
540-
tenant.authentication.forceRedirectHttpsScheme = provider.authentication().forceRedirectHttpsScheme();
543+
if (tenantAuth.forceRedirectHttpsScheme().isEmpty() && providerAuth.forceRedirectHttpsScheme().isPresent()) {
544+
authBuilder.forceRedirectHttpsScheme(providerAuth.forceRedirectHttpsScheme().get());
541545
}
542-
if (tenant.authentication().responseMode().isEmpty()) {
543-
tenant.authentication.responseMode = provider.authentication.responseMode;
546+
if (tenantAuth.responseMode().isEmpty() && providerAuth.responseMode().isPresent()) {
547+
authBuilder.responseMode(providerAuth.responseMode().get());
544548
}
545-
if (tenant.authentication().redirectPath().isEmpty()) {
546-
tenant.authentication.redirectPath = provider.authentication().redirectPath();
549+
if (tenantAuth.redirectPath().isEmpty() && providerAuth.redirectPath().isPresent()) {
550+
authBuilder.redirectPath(providerAuth.redirectPath().get());
547551
}
552+
authBuilder.end();
548553

549554
// credentials
550-
if (tenant.credentials().clientSecret().method().isEmpty()) {
551-
tenant.credentials.clientSecret.method = provider.credentials.clientSecret.method;
555+
var credentialsBuilder = tenantBuilder.credentials();
556+
if (tenant.credentials().clientSecret().method().isEmpty()
557+
&& provider.credentials().clientSecret().method().isPresent()) {
558+
credentialsBuilder.clientSecret().method(provider.credentials().clientSecret().method().get()).end();
552559
}
553-
if (tenant.credentials().jwt().audience().isEmpty()) {
554-
tenant.credentials.jwt.audience = provider.credentials().jwt().audience();
560+
if (tenant.credentials().jwt().audience().isEmpty() && provider.credentials().jwt().audience().isPresent()) {
561+
credentialsBuilder.jwt().audience(provider.credentials().jwt().audience().get()).end();
555562
}
556-
if (tenant.credentials().jwt().signatureAlgorithm().isEmpty()) {
557-
tenant.credentials.jwt.signatureAlgorithm = provider.credentials().jwt().signatureAlgorithm();
563+
if (tenant.credentials().jwt().signatureAlgorithm().isEmpty()
564+
&& provider.credentials().jwt().signatureAlgorithm().isPresent()) {
565+
credentialsBuilder.jwt().signatureAlgorithm(provider.credentials().jwt().signatureAlgorithm().get()).end();
558566
}
567+
credentialsBuilder.end();
559568

560569
// token
561-
if (tenant.token().issuer().isEmpty()) {
562-
tenant.token.issuer = provider.token().issuer();
570+
var tokenBuilder = tenantBuilder.token();
571+
if (tenant.token().issuer().isEmpty() && provider.token().issuer().isPresent()) {
572+
tokenBuilder.issuer(provider.token().issuer().get());
563573
}
564-
if (tenant.token().principalClaim().isEmpty()) {
565-
tenant.token.principalClaim = provider.token().principalClaim();
574+
if (tenant.token().principalClaim().isEmpty() && provider.token().principalClaim().isPresent()) {
575+
tokenBuilder.principalClaim(provider.token().principalClaim().get());
566576
}
567-
if (tenant.token().verifyAccessTokenWithUserInfo().isEmpty()) {
568-
tenant.token.verifyAccessTokenWithUserInfo = provider.token().verifyAccessTokenWithUserInfo();
577+
if (tenant.token().verifyAccessTokenWithUserInfo().isEmpty()
578+
&& provider.token().verifyAccessTokenWithUserInfo().isPresent()) {
579+
tokenBuilder.verifyAccessTokenWithUserInfo(provider.token().verifyAccessTokenWithUserInfo().get());
569580
}
581+
tokenBuilder.end();
570582

571-
return tenant;
583+
return tenantBuilder.build();
572584
}
573585

574586
static OidcTenantConfig resolveProviderConfig(OidcTenantConfig oidcTenantConfig) {
575587
if (oidcTenantConfig != null && oidcTenantConfig.provider().isPresent()) {
576588
return OidcUtils.mergeTenantConfig(oidcTenantConfig,
577-
KnownOidcProviders.provider(oidcTenantConfig.provider.get()));
589+
KnownOidcProviders.provider(oidcTenantConfig.provider().get()));
578590
} else {
579591
return oidcTenantConfig;
580592
}

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/TenantConfigContext.java

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ default Uni<TenantConfigContext> initialize() {
4848
return Uni.createFrom().item(this);
4949
}
5050

51+
static TenantConfigContext createReady(OidcProvider provider) {
52+
return createReady(provider, provider.oidcConfig);
53+
}
54+
5155
static TenantConfigContext createReady(OidcProvider provider, OidcTenantConfig config) {
5256
return new TenantConfigContextImpl(provider, config);
5357
}

0 commit comments

Comments
 (0)