Skip to content

Commit

Permalink
Add http root to OIDC back channel logout handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Aug 14, 2024
1 parent 64f0196 commit a17b30a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ public void setFrontchannel(Frontchannel frontchannel) {
public static class Backchannel {
/**
* The relative path of the Back-Channel Logout endpoint at the application.
* It must start with the forward slash '/', for example, '/back-channel-logout'.
* This value is always resolved relative to 'quarkus.http.root-path'.
*/
@ConfigItem
public Optional<String> path = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.oidc.OidcTenantConfig;
import io.quarkus.oidc.SecurityEvent;
import io.quarkus.oidc.SecurityEvent.Type;
import io.quarkus.oidc.common.runtime.OidcCommonUtils;
import io.quarkus.oidc.common.runtime.OidcConstants;
import io.quarkus.security.spi.runtime.SecurityEventHelper;
import io.vertx.core.Handler;
Expand All @@ -24,6 +25,7 @@

public class BackChannelLogoutHandler {
private static final Logger LOG = Logger.getLogger(BackChannelLogoutHandler.class);
private static final String SLASH = "/";

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

private void addRoute(Router router, OidcTenantConfig oidcTenantConfig) {
if (oidcTenantConfig.isTenantEnabled() && oidcTenantConfig.logout.backchannel.path.isPresent()) {
router.route(oidcTenantConfig.logout.backchannel.path.get()).handler(new RouteHandler(oidcTenantConfig));
router.route(getRootPath() + oidcTenantConfig.logout.backchannel.path.get())
.handler(new RouteHandler(oidcTenantConfig));
}
}

Expand Down Expand Up @@ -160,7 +163,18 @@ private TenantConfigContext getTenantConfigContext(RoutingContext context) {
private boolean isMatchingTenant(String requestPath, TenantConfigContext tenant) {
return tenant.oidcConfig.isTenantEnabled()
&& tenant.oidcConfig.getTenantId().get().equals(oidcTenantConfig.getTenantId().get())
&& requestPath.equals(tenant.oidcConfig.logout.backchannel.path.orElse(null));
&& requestPath.equals(getRootPath() + tenant.oidcConfig.logout.backchannel.path.orElse(null));
}
}

private String getRootPath() {
// Prepend '/' if it is not present
String rootPath = OidcCommonUtils.prependSlash(resolver.getRootPath());
// Strip trailing '/' if the length is > 1
if (rootPath.length() > 1 && rootPath.endsWith("/")) {
rootPath = rootPath.substring(rootPath.length() - 1);
}
// if it is only '/' then return an empty value
return SLASH.equals(rootPath) ? "" : rootPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class DefaultTenantConfigResolver {
private final TenantConfigBean tenantConfigBean;
private final TenantResolver[] staticTenantResolvers;
private final boolean annotationBasedTenantResolutionEnabled;
private final String rootPath;

@Inject
Instance<TenantConfigResolver> tenantConfigResolver;
Expand Down Expand Up @@ -86,6 +87,7 @@ public class DefaultTenantConfigResolver {
this.staticTenantResolvers = prepareStaticTenantResolvers(tenantConfigBean, rootPath, tenantResolverInstance,
resolveTenantsWithIssuer, new DefaultStaticTenantResolver());
this.annotationBasedTenantResolutionEnabled = Boolean.getBoolean(OidcUtils.ANNOTATION_BASED_TENANT_RESOLUTION_ENABLED);
this.rootPath = rootPath;
}

@PostConstruct
Expand Down Expand Up @@ -414,6 +416,10 @@ public OidcTenantConfig getResolvedConfig(String sessionTenantId) {
return null;
}

public String getRootPath() {
return rootPath;
}

private static final class IssuerBasedTenantResolver implements TenantResolver {

private final TenantConfigContext[] tenantConfigContexts;
Expand Down

0 comments on commit a17b30a

Please sign in to comment.