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

[4.x] Default tenant is not included for propagation #5900

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 @@ -415,7 +415,10 @@ private String redirectUri(ServerRequest req, String tenantName) {
} else {
uri = oidcConfig.redirectUriWithHost();
}
return uri + (uri.contains("?") ? "&" : "?") + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
if (!DEFAULT_TENANT_ID.equals(tenantName)) {
return uri + (uri.contains("?") ? "&" : "?") + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
}
return uri;
}

private String processJsonResponse(ServerRequest req,
Expand All @@ -430,7 +433,9 @@ private String processJsonResponse(ServerRequest req,
res.status(Http.Status.TEMPORARY_REDIRECT_307);
if (oidcConfig.useParam()) {
state += (state.contains("?") ? "&" : "?") + oidcConfig.paramName() + "=" + tokenValue;
state += "&" + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
if (!DEFAULT_TENANT_ID.equals(tenantName)) {
state += "&" + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
}
}

state = increaseRedirectCounter(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ private String redirectUri(ServerRequest req, String tenantName) {
} else {
uri = oidcConfig.redirectUriWithHost();
}
return uri + (uri.contains("?") ? "&" : "?") + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
if (!DEFAULT_TENANT_ID.equals(tenantName)) {
return uri + (uri.contains("?") ? "&" : "?") + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
}
return uri;
}

private String processJsonResponse(ServerRequest req,
Expand All @@ -430,7 +433,9 @@ private String processJsonResponse(ServerRequest req,
res.status(Http.Status.TEMPORARY_REDIRECT_307);
if (oidcConfig.useParam()) {
state += (state.contains("?") ? "&" : "?") + encode(oidcConfig.paramName()) + "=" + tokenValue;
state += "&" + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
if (!DEFAULT_TENANT_ID.equals(tenantName)) {
state += "&" + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantName);
}
}

state = increaseRedirectCounter(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import io.helidon.security.util.TokenHandler;

import static io.helidon.security.providers.oidc.common.OidcConfig.postJsonResponse;
import static io.helidon.security.providers.oidc.common.spi.TenantConfigFinder.DEFAULT_TENANT_ID;

/**
* Authentication handler.
Expand Down Expand Up @@ -291,9 +292,13 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest,

String authorizationEndpoint = tenant.authorizationEndpointUri();
String nonce = UUID.randomUUID().toString();
String redirectUri =
encode(redirectUri(providerRequest.env()) + "?"
+ encode(oidcConfig.tenantParamName()) + "=" + encode(tenantId));
String redirectUri;
if (DEFAULT_TENANT_ID.equals(tenantId)) {
redirectUri = encode(redirectUri(providerRequest.env()));
} else {
redirectUri = encode(redirectUri(providerRequest.env()) + "?"
+ encode(oidcConfig.tenantParamName()) + "=" + encode(tenantId));
}


StringBuilder queryString = new StringBuilder("?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.HelidonTest;
import io.helidon.security.providers.oidc.common.OidcConfig;
import io.helidon.security.providers.oidc.common.spi.TenantConfigFinder;

import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.HttpHeaders;
Expand All @@ -38,6 +37,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

Expand Down Expand Up @@ -88,8 +88,8 @@ void testDomainTenantId(WebTarget webTarget) {
void testNoneTenantId(WebTarget webTarget) {
try (Response response = webTarget.property(ClientProperties.FOLLOW_REDIRECTS, false).path("/test").request().get()) {
String redirectUri = queryParamValue((String) response.getHeaders().getFirst(HttpHeaders.LOCATION), "redirect_uri");
String tenantName = queryParamValue(redirectUri, OidcConfig.DEFAULT_TENANT_PARAM_NAME);
assertThat(tenantName, is(TenantConfigFinder.DEFAULT_TENANT_ID));
URI uri = URI.create(redirectUri);
assertThat(uri.getRawQuery(), nullValue());
}
}

Expand Down