Skip to content

Commit 6315150

Browse files
authored
Merge pull request #47575 from michalvavrik/feature/oidc-only-access-fields-using-accessors
OIDC refactoring: use accessors instead of deprecated fields marked for removal
2 parents a6fefd7 + 629f3c6 commit 6315150

File tree

14 files changed

+35
-33
lines changed

14 files changed

+35
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import io.quarkus.deployment.annotations.BuildProducer;
1414
import io.quarkus.devui.spi.page.CardPageBuildItem;
1515
import io.quarkus.devui.spi.page.Page;
16-
import io.quarkus.oidc.OidcTenantConfig;
16+
import io.quarkus.oidc.runtime.OidcTenantConfig;
1717
import io.quarkus.oidc.runtime.devui.OidcDevUiRecorder;
1818
import io.quarkus.oidc.runtime.devui.OidcDevUiRpcSvcPropertiesBean;
1919
import io.quarkus.runtime.RuntimeValue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import io.quarkus.devservices.oidc.OidcDevServicesConfigBuildItem;
1818
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
1919
import io.quarkus.devui.spi.page.CardPageBuildItem;
20-
import io.quarkus.oidc.OidcTenantConfig;
21-
import io.quarkus.oidc.OidcTenantConfig.Provider;
2220
import io.quarkus.oidc.deployment.OidcBuildTimeConfig;
21+
import io.quarkus.oidc.runtime.OidcTenantConfig;
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/deployment/src/test/java/io/quarkus/oidc/test/OpaqueTokenVerificationWithUserInfoValidationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class OpaqueTokenVerificationWithUserInfoValidationTest {
3434
// assert UserInfo is required
3535
assertTrue(
3636
te.getMessage()
37-
.contains("UserInfo is not required but 'verifyAccessTokenWithUserInfo' is enabled"),
37+
.contains(
38+
"UserInfo is not required but 'quarkus.oidc.token.verify-access-token-with-user-info' is enabled"),
3839
te.getMessage());
3940
});
4041

extensions/oidc/deployment/src/test/java/io/quarkus/oidc/test/UserInfoRequiredDetectionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static class UserInfoResource {
107107
@Path("default-tenant-random")
108108
@GET
109109
public String getDefaultTenantName() {
110-
if (!tenantConfigBean.getDefaultTenant().oidcConfig().authentication.userInfoRequired.orElse(false)) {
110+
if (!tenantConfigBean.getDefaultTenant().oidcConfig().authentication().userInfoRequired().orElse(false)) {
111111
throw new IllegalStateException("Default tenant user info should be required");
112112
}
113113
String tenantId = routingContext.get(OidcUtils.TENANT_ID_ATTRIBUTE);
@@ -126,7 +126,7 @@ public String getDefaultTenantName() {
126126
@Path("named-tenant-random")
127127
@GET
128128
public String getNamedTenantName() {
129-
if (!getNamedTenantConfig("named").authentication.userInfoRequired.orElse(false)) {
129+
if (!getNamedTenantConfig("named").authentication().userInfoRequired().orElse(false)) {
130130
throw new IllegalStateException("Named tenant user info should be required");
131131
}
132132
String tenantId = routingContext.get(OidcUtils.TENANT_ID_ATTRIBUTE);
@@ -142,14 +142,14 @@ public String getNamedTenantName() {
142142
@Path("named-tenant-2")
143143
@GET
144144
public boolean getNamed2TenantUserInfoRequired() {
145-
return getNamedTenantConfig("named-2").authentication.userInfoRequired.orElse(false);
145+
return getNamedTenantConfig("named-2").authentication().userInfoRequired().orElse(false);
146146
}
147147

148148
@PermissionsAllowed("openid")
149149
@Path("named-tenant-3")
150150
@GET
151151
public boolean getNamed3TenantUserInfoRequired() {
152-
return getNamedTenantConfig("named-3").authentication.userInfoRequired.orElse(false);
152+
return getNamedTenantConfig("named-3").authentication().userInfoRequired().orElse(false);
153153
}
154154

155155
private OidcTenantConfig getNamedTenantConfig(String configName) {

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import org.eclipse.microprofile.config.Config;
1010
import org.eclipse.microprofile.config.ConfigProvider;
1111

12-
import io.quarkus.oidc.OidcTenantConfig;
13-
import io.quarkus.oidc.OidcTenantConfig.Provider;
1412
import io.quarkus.oidc.common.runtime.OidcCommonUtils;
1513
import io.quarkus.oidc.common.runtime.OidcConstants;
14+
import io.quarkus.oidc.runtime.OidcTenantConfig.Provider;
1615
import io.quarkus.oidc.runtime.providers.KnownOidcProviders;
1716
import io.smallrye.config.SmallRyeConfig;
1817

@@ -99,7 +98,7 @@ public String get(Config config) {
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

Lines changed: 1 addition & 1 deletion
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/OidcUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static OidcTenantConfig mergeTenantConfig(OidcTenantConfig tenant, OidcTenantCon
574574
static OidcTenantConfig resolveProviderConfig(OidcTenantConfig oidcTenantConfig) {
575575
if (oidcTenantConfig != null && oidcTenantConfig.provider().isPresent()) {
576576
return OidcUtils.mergeTenantConfig(oidcTenantConfig,
577-
KnownOidcProviders.provider(oidcTenantConfig.provider.get()));
577+
KnownOidcProviders.provider(oidcTenantConfig.provider().get()));
578578
} else {
579579
return oidcTenantConfig;
580580
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ private Uni<TenantConfigContext> createTenantContext(OidcTenantConfig oidcTenant
220220
}
221221
if (oidcConfig.token().verifyAccessTokenWithUserInfo().orElse(false) && !OidcUtils.isWebApp(oidcConfig)
222222
&& !enableUserInfo(oidcConfig)) {
223-
throw new ConfigurationException(
224-
"UserInfo is not required but 'verifyAccessTokenWithUserInfo' is enabled");
223+
String propertyName = getConfigPropertyForTenant(tenantId, "token.verify-access-token-with-user-info");
224+
throw new ConfigurationException("UserInfo is not required but '%s' is enabled".formatted(propertyName));
225225
}
226226
if (!oidcConfig.authentication().idTokenRequired().orElse(true) && OidcUtils.isWebApp(oidcConfig)
227227
&& StepUpAuthenticationPolicy.isEnabled()) {
@@ -234,7 +234,8 @@ private Uni<TenantConfigContext> createTenantContext(OidcTenantConfig oidcTenant
234234
}
235235
if (!oidcConfig.authentication().idTokenRequired().orElse(true) && !enableUserInfo(oidcConfig)) {
236236
throw new ConfigurationException(
237-
"UserInfo is not required but it will be needed to verify a code flow access token");
237+
"UserInfo is not required for OIDC tenant '%s' but it will be needed to verify a code flow access token"
238+
.formatted(tenantId));
238239
}
239240

240241
if (!oidcConfig.discoveryEnabled().orElse(true)) {

0 commit comments

Comments
 (0)