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

Provide default OIDC static tenant resolver #32864

Merged
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 @@ -306,6 +306,8 @@ public class CustomTenantResolver implements TenantResolver {
}
----

In fact, this is how Quarkus OIDC resolves static custom tenants itself if no custom `TenantResolver` is registered.

A similar technique can be used with `TenantConfigResolver` where a `tenant-id` provided in the context can be used to return `OidcTenantConfig` already prepared with the previous request.
====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class DefaultTenantConfigResolver {
private static final String CURRENT_STATIC_TENANT_ID_NULL = "static.tenant.id.null";
private static final String CURRENT_DYNAMIC_TENANT_CONFIG = "dynamic.tenant.config";

private DefaultStaticTenantResolver defaultStaticTenantResolver = new DefaultStaticTenantResolver();

@Inject
Instance<TenantResolver> tenantResolver;

Expand Down Expand Up @@ -133,6 +135,8 @@ private TenantConfigContext getStaticTenantContext(RoutingContext context) {
if (tenantId == null && context.get(CURRENT_STATIC_TENANT_ID_NULL) == null) {
if (tenantResolver.isResolvable()) {
tenantId = tenantResolver.get().resolve(context);
} else if (tenantConfigBean.getStaticTenantsConfig().size() > 0) {
tenantId = defaultStaticTenantResolver.resolve(context);
}
if (tenantId == null) {
tenantId = context.get(OidcUtils.TENANT_ID_ATTRIBUTE);
Expand Down Expand Up @@ -236,4 +240,24 @@ public TenantConfigBean getTenantConfigBean() {
return tenantConfigBean;
}

private class DefaultStaticTenantResolver implements TenantResolver {

@Override
public String resolve(RoutingContext context) {
String tenantId = context.get(OidcUtils.TENANT_ID_ATTRIBUTE);
if (tenantId != null) {
return tenantId;
}
String[] pathSegments = context.request().path().split("/");
if (pathSegments.length > 0) {
String lastPathSegment = pathSegments[pathSegments.length - 1];
if (tenantConfigBean.getStaticTenantsConfig().containsKey(lastPathSegment)) {
return lastPathSegment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
return null;
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ quarkus.keycloak.policy-enforcer.paths.19.name=Scope Permission Resource
quarkus.keycloak.policy-enforcer.paths.19.path=/api/permission/scopes/programmatic-way-denied

# Service Tenant
quarkus.oidc.tenant.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc.tenant.client-id=quarkus-app
quarkus.oidc.tenant.credentials.secret=secret
quarkus.oidc.api-permission-tenant.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc.api-permission-tenant.client-id=quarkus-app
quarkus.oidc.api-permission-tenant.credentials.secret=secret

quarkus.keycloak.tenant.policy-enforcer.paths.1.name=Permission Resource Tenant
quarkus.keycloak.tenant.policy-enforcer.paths.1.path=/api-permission-tenant
quarkus.keycloak.tenant.policy-enforcer.paths.1.claim-information-point.claims.static-claim=static-claim
quarkus.keycloak.api-permission-tenant.policy-enforcer.paths.1.name=Permission Resource Tenant
quarkus.keycloak.api-permission-tenant.policy-enforcer.paths.1.path=/api-permission-tenant
quarkus.keycloak.api-permission-tenant.policy-enforcer.paths.1.claim-information-point.claims.static-claim=static-claim

# Web App Tenant
quarkus.oidc.webapp-tenant.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc.webapp-tenant.client-id=quarkus-app
quarkus.oidc.webapp-tenant.credentials.secret=secret
quarkus.oidc.webapp-tenant.application-type=web-app
quarkus.oidc.webapp-tenant.roles.source=accesstoken

quarkus.keycloak.webapp-tenant.policy-enforcer.paths.1.name=Permission Resource WebApp
quarkus.keycloak.webapp-tenant.policy-enforcer.paths.1.path=/api-permission-webapp
quarkus.keycloak.webapp-tenant.policy-enforcer.paths.1.claim-information-point.claims.static-claim=static-claim
quarkus.oidc.api-permission-webapp.auth-server-url=${quarkus.oidc.auth-server-url}
quarkus.oidc.api-permission-webapp.client-id=quarkus-app
quarkus.oidc.api-permission-webapp.credentials.secret=secret
quarkus.oidc.api-permission-webapp.application-type=web-app
quarkus.oidc.api-permission-webapp.roles.source=accesstoken

quarkus.keycloak.api-permission-webapp.policy-enforcer.paths.1.name=Permission Resource WebApp
quarkus.keycloak.api-permission-webapp.policy-enforcer.paths.1.path=/api-permission-webapp
quarkus.keycloak.api-permission-webapp.policy-enforcer.paths.1.claim-information-point.claims.static-claim=static-claim

admin-url=${keycloak.url}

Expand Down