Skip to content

Commit 24c3c52

Browse files
committed
Polish postLogoutRedirectUri encoding
Issue gh-9511
1 parent 499701e commit 24c3c52

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/web/logout/OidcClientInitiatedLogoutSuccessHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected String determineTargetUrl(HttpServletRequest request, HttpServletRespo
6767
URI endSessionEndpoint = this.endSessionEndpoint(clientRegistration);
6868
if (endSessionEndpoint != null) {
6969
String idToken = idToken(authentication);
70-
URI postLogoutRedirectUri = postLogoutRedirectUri(request);
70+
String postLogoutRedirectUri = postLogoutRedirectUri(request);
7171
targetUrl = endpointUri(endSessionEndpoint, idToken, postLogoutRedirectUri);
7272
}
7373
}
@@ -89,7 +89,7 @@ private String idToken(Authentication authentication) {
8989
return ((OidcUser) authentication.getPrincipal()).getIdToken().getTokenValue();
9090
}
9191

92-
private URI postLogoutRedirectUri(HttpServletRequest request) {
92+
private String postLogoutRedirectUri(HttpServletRequest request) {
9393
if (this.postLogoutRedirectUri == null) {
9494
return null;
9595
}
@@ -100,13 +100,13 @@ private URI postLogoutRedirectUri(HttpServletRequest request) {
100100
.replaceQuery(null)
101101
.fragment(null)
102102
.build();
103-
return URI.create (UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
103+
return UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
104104
.buildAndExpand(Collections.singletonMap("baseUrl", uriComponents.toUriString()))
105-
.toUriString());
105+
.toUriString();
106106
// @formatter:on
107107
}
108108

109-
private String endpointUri(URI endSessionEndpoint, String idToken, URI postLogoutRedirectUri) {
109+
private String endpointUri(URI endSessionEndpoint, String idToken, String postLogoutRedirectUri) {
110110
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(endSessionEndpoint);
111111
builder.queryParam("id_token_hint", idToken);
112112
if (postLogoutRedirectUri != null) {

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/oidc/web/logout/OidcClientInitiatedLogoutSuccessHandlerTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,17 @@ public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect(
138138
"https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org");
139139
}
140140

141+
// gh-9511
141142
@Test
142-
public void logoutWhenUsingPostLogoutRedirectUriWithQueryParametersThenBuildItForRedirectWithEncodedQueryParameters() throws IOException, ServletException {
143+
public void logoutWhenUsingPostLogoutRedirectUriWithQueryParametersThenBuildsItForRedirect()
144+
throws IOException, ServletException {
143145
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
144146
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
145147
this.handler.setPostLogoutRedirectUri("https://rp.example.org/context?forwardUrl=secured%3Fparam%3Dtrue");
146148
this.request.setUserPrincipal(token);
147149
this.handler.onLogoutSuccess(this.request, this.response, token);
148-
assertThat(this.response.getRedirectedUrl()).isEqualTo(
149-
"https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org/context?forwardUrl%3Dsecured%253Fparam%253Dtrue");
150+
assertThat(this.response.getRedirectedUrl()).isEqualTo("https://endpoint?id_token_hint=id-token&"
151+
+ "post_logout_redirect_uri=https://rp.example.org/context?forwardUrl%3Dsecured%253Fparam%253Dtrue");
150152
}
151153

152154
@Test

0 commit comments

Comments
 (0)