Add placeholders to reactive post_logout_redirect_uri
Now also supports baseScheme, baseHost, basePort, and basePath Issue gh-11229
This commit is contained in:
parent
6f69d85fcb
commit
01513ab17e
|
@ -132,7 +132,19 @@ public class OidcClientInitiatedServerLogoutSuccessHandler implements ServerLogo
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Map<String, String> uriVariables = new HashMap<>();
|
Map<String, String> uriVariables = new HashMap<>();
|
||||||
|
String scheme = uriComponents.getScheme();
|
||||||
|
uriVariables.put("baseScheme", (scheme != null) ? scheme : "");
|
||||||
uriVariables.put("baseUrl", uriComponents.toUriString());
|
uriVariables.put("baseUrl", uriComponents.toUriString());
|
||||||
|
|
||||||
|
String host = uriComponents.getHost();
|
||||||
|
uriVariables.put("baseHost", (host != null) ? host : "");
|
||||||
|
|
||||||
|
String path = uriComponents.getPath();
|
||||||
|
uriVariables.put("basePath", (path != null) ? path : "");
|
||||||
|
|
||||||
|
int port = uriComponents.getPort();
|
||||||
|
uriVariables.put("basePort", (port == -1) ? "" : ":" + port);
|
||||||
|
|
||||||
uriVariables.put("registrationId", clientRegistration.getRegistrationId());
|
uriVariables.put("registrationId", clientRegistration.getRegistrationId());
|
||||||
|
|
||||||
return UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
|
return UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
|
||||||
|
@ -154,8 +166,15 @@ public class OidcClientInitiatedServerLogoutSuccessHandler implements ServerLogo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the post logout redirect uri template to use. Supports the {@code "{baseUrl}"}
|
* Set the post logout redirect uri template.
|
||||||
* placeholder, for example:
|
*
|
||||||
|
* <br />
|
||||||
|
* The supported uri template variables are: {@code {baseScheme}}, {@code {baseHost}},
|
||||||
|
* {@code {basePort}} and {@code {basePath}}.
|
||||||
|
*
|
||||||
|
* <br />
|
||||||
|
* <b>NOTE:</b> {@code {baseUrl}} is also supported, which is the same as
|
||||||
|
* {@code "{baseScheme}://{baseHost}{basePort}{basePath}"}
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* handler.setPostLogoutRedirectUri("{baseUrl}");
|
* handler.setPostLogoutRedirectUri("{baseUrl}");
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class OidcClientInitiatedServerLogoutSuccessHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect()
|
public void logoutWhenUsingPostLogoutBaseUrlRedirectUriTemplateThenBuildsItForRedirect()
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
|
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
|
||||||
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
|
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
|
||||||
|
@ -163,6 +163,34 @@ public class OidcClientInitiatedServerLogoutSuccessHandlerTests {
|
||||||
+ "post_logout_redirect_uri=https://rp.example.org/context?forwardUrl%3Dsecured%253Fparam%253Dtrue");
|
+ "post_logout_redirect_uri=https://rp.example.org/context?forwardUrl%3Dsecured%253Fparam%253Dtrue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect() {
|
||||||
|
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
|
||||||
|
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
|
||||||
|
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
|
||||||
|
MockServerHttpRequest request = MockServerHttpRequest.get("https://rp.example.org/").build();
|
||||||
|
given(this.exchange.getRequest()).willReturn(request);
|
||||||
|
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
|
||||||
|
this.handler.setPostLogoutRedirectUri("{baseScheme}://{baseHost}{basePort}{basePath}");
|
||||||
|
this.handler.onLogoutSuccess(f, token).block();
|
||||||
|
assertThat(redirectedUrl(this.exchange)).isEqualTo(
|
||||||
|
"https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void logoutWhenUsingPostLogoutRedirectUriTemplateWithOtherPortThenBuildsItForRedirect() {
|
||||||
|
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
|
||||||
|
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
|
||||||
|
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
|
||||||
|
MockServerHttpRequest request = MockServerHttpRequest.get("https://rp.example.org:400").build();
|
||||||
|
given(this.exchange.getRequest()).willReturn(request);
|
||||||
|
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
|
||||||
|
this.handler.setPostLogoutRedirectUri("{baseScheme}://{baseHost}{basePort}{basePath}");
|
||||||
|
this.handler.onLogoutSuccess(f, token).block();
|
||||||
|
assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?" + "id_token_hint=id-token&"
|
||||||
|
+ "post_logout_redirect_uri=https://rp.example.org:400");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirectExpanded()
|
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirectExpanded()
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
Loading…
Reference in New Issue