Skip to content

Commit ab84f88

Browse files
sberyozkingsmet
authored andcommitted
Add http root to OIDC back channel logout handlers
(cherry picked from commit a17b30a)
1 parent 8c949c6 commit ab84f88

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ public void setFrontchannel(Frontchannel frontchannel) {
424424
public static class Backchannel {
425425
/**
426426
* The relative path of the Back-Channel Logout endpoint at the application.
427+
* It must start with the forward slash '/', for example, '/back-channel-logout'.
428+
* This value is always resolved relative to 'quarkus.http.root-path'.
427429
*/
428430
@ConfigItem
429431
public Optional<String> path = Optional.empty();

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.quarkus.oidc.OidcTenantConfig;
1414
import io.quarkus.oidc.SecurityEvent;
1515
import io.quarkus.oidc.SecurityEvent.Type;
16+
import io.quarkus.oidc.common.runtime.OidcCommonUtils;
1617
import io.quarkus.oidc.common.runtime.OidcConstants;
1718
import io.quarkus.security.spi.runtime.SecurityEventHelper;
1819
import io.vertx.core.Handler;
@@ -24,6 +25,7 @@
2425

2526
public class BackChannelLogoutHandler {
2627
private static final Logger LOG = Logger.getLogger(BackChannelLogoutHandler.class);
28+
private static final String SLASH = "/";
2729

2830
@Inject
2931
DefaultTenantConfigResolver resolver;
@@ -44,7 +46,8 @@ public void setup(@Observes Router router) {
4446

4547
private void addRoute(Router router, OidcTenantConfig oidcTenantConfig) {
4648
if (oidcTenantConfig.isTenantEnabled() && oidcTenantConfig.logout.backchannel.path.isPresent()) {
47-
router.route(oidcTenantConfig.logout.backchannel.path.get()).handler(new RouteHandler(oidcTenantConfig));
49+
router.route(getRootPath() + oidcTenantConfig.logout.backchannel.path.get())
50+
.handler(new RouteHandler(oidcTenantConfig));
4851
}
4952
}
5053

@@ -160,7 +163,18 @@ private TenantConfigContext getTenantConfigContext(RoutingContext context) {
160163
private boolean isMatchingTenant(String requestPath, TenantConfigContext tenant) {
161164
return tenant.oidcConfig.isTenantEnabled()
162165
&& tenant.oidcConfig.getTenantId().get().equals(oidcTenantConfig.getTenantId().get())
163-
&& requestPath.equals(tenant.oidcConfig.logout.backchannel.path.orElse(null));
166+
&& requestPath.equals(getRootPath() + tenant.oidcConfig.logout.backchannel.path.orElse(null));
164167
}
165168
}
169+
170+
private String getRootPath() {
171+
// Prepend '/' if it is not present
172+
String rootPath = OidcCommonUtils.prependSlash(resolver.getRootPath());
173+
// Strip trailing '/' if the length is > 1
174+
if (rootPath.length() > 1 && rootPath.endsWith("/")) {
175+
rootPath = rootPath.substring(rootPath.length() - 1);
176+
}
177+
// if it is only '/' then return an empty value
178+
return SLASH.equals(rootPath) ? "" : rootPath;
179+
}
166180
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class DefaultTenantConfigResolver {
5151
private final TenantConfigBean tenantConfigBean;
5252
private final TenantResolver[] staticTenantResolvers;
5353
private final boolean annotationBasedTenantResolutionEnabled;
54+
private final String rootPath;
5455

5556
@Inject
5657
Instance<TenantConfigResolver> tenantConfigResolver;
@@ -86,6 +87,7 @@ public class DefaultTenantConfigResolver {
8687
this.staticTenantResolvers = prepareStaticTenantResolvers(tenantConfigBean, rootPath, tenantResolverInstance,
8788
resolveTenantsWithIssuer, new DefaultStaticTenantResolver());
8889
this.annotationBasedTenantResolutionEnabled = Boolean.getBoolean(OidcUtils.ANNOTATION_BASED_TENANT_RESOLUTION_ENABLED);
90+
this.rootPath = rootPath;
8991
}
9092

9193
@PostConstruct
@@ -414,6 +416,10 @@ public OidcTenantConfig getResolvedConfig(String sessionTenantId) {
414416
return null;
415417
}
416418

419+
public String getRootPath() {
420+
return rootPath;
421+
}
422+
417423
private static final class IssuerBasedTenantResolver implements TenantResolver {
418424

419425
private final TenantConfigContext[] tenantConfigContexts;

0 commit comments

Comments
 (0)