Skip to content

Commit

Permalink
Merge pull request #32481 from sberyozkin/fix_tenant_config_resolver_npe
Browse files Browse the repository at this point in the history
Fix NPE when OIDC TenantConfigResolver returns null
  • Loading branch information
gastaldi authored Apr 6, 2023
2 parents 4746a69 + a6ee7a3 commit 5822c8a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ private void useTenantConfigResolver() throws IOException, InterruptedException

assertEquals("tenant-config-resolver:alice", page.getBody().asNormalizedText());
webClient.getCookieManager().clearCookies();
try {
webClient.getPage("http://localhost:8080/protected/tenant/null-tenant");
fail("401 status error is expected");
} catch (FailingHttpStatusCodeException ex) {
assertEquals(401, ex.getStatusCode());
}
try {
webClient.getPage("http://localhost:8080/protected/tenant/unknown-tenant");
fail("401 status error is expected");
} catch (FailingHttpStatusCodeException ex) {
assertEquals(401, ex.getStatusCode());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public Uni<OidcTenantConfig> resolve(RoutingContext context, OidcRequestContext<
config.setApplicationType(ApplicationType.WEB_APP);
return Uni.createFrom().item(config);
}
if (context.request().path().endsWith("/null-tenant")) {
return null;
}
return Uni.createFrom().nullItem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ private Uni<OidcTenantConfig> getDynamicTenantConfig(RoutingContext context) {
if (tenantConfigResolver.isResolvable()) {
Uni<OidcTenantConfig> oidcConfig = context.get(CURRENT_DYNAMIC_TENANT_CONFIG);
if (oidcConfig == null) {
oidcConfig = tenantConfigResolver.get().resolve(context, blockingRequestContext).memoize().indefinitely();
oidcConfig = tenantConfigResolver.get().resolve(context, blockingRequestContext);
if (oidcConfig == null) {
//shouldn't happen, but guard against it anyway
oidcConfig = Uni.createFrom().nullItem();
}
oidcConfig = oidcConfig.memoize().indefinitely();
if (oidcConfig == null) {
//shouldn't happen, but guard against it anyway
oidcConfig = Uni.createFrom().nullItem();
Expand Down

0 comments on commit 5822c8a

Please sign in to comment.