Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http root to OIDC back channel logout handlers #42524

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
sberyozkin marked this conversation as resolved.
Show resolved Hide resolved
}
}

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