Skip to content

Commit db37bdf

Browse files
Merge branch '5.8.x' into 6.0.x
Closes gh-13795
2 parents 629540f + ce012a4 commit db37bdf

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

web/src/main/java/org/springframework/security/web/savedrequest/CookieRequestCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.security.web.savedrequest;
1818

1919
import java.util.Base64;
20+
import java.util.Collections;
2021

2122
import jakarta.servlet.http.Cookie;
2223
import jakarta.servlet.http.HttpServletRequest;
@@ -77,7 +78,7 @@ public SavedRequest getRequest(HttpServletRequest request, HttpServletResponse r
7778
int port = getPort(uriComponents);
7879
return builder.setScheme(uriComponents.getScheme()).setServerName(uriComponents.getHost())
7980
.setRequestURI(uriComponents.getPath()).setQueryString(uriComponents.getQuery()).setServerPort(port)
80-
.setMethod(request.getMethod()).build();
81+
.setMethod(request.getMethod()).setLocales(Collections.list(request.getLocales())).build();
8182
}
8283

8384
private int getPort(UriComponents uriComponents) {

web/src/test/java/org/springframework/security/web/savedrequest/CookieRequestCacheTests.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,10 @@
1616

1717
package org.springframework.security.web.savedrequest;
1818

19+
import java.util.Arrays;
1920
import java.util.Base64;
21+
import java.util.Collections;
22+
import java.util.Locale;
2023

2124
import jakarta.servlet.http.Cookie;
2225
import jakarta.servlet.http.HttpServletRequest;
@@ -182,6 +185,25 @@ public void removeRequestWhenInvokedThenSetsAnExpiredCookieOnResponse() {
182185
assertThat(expiredCookie.getMaxAge()).isZero();
183186
}
184187

188+
// gh-13792
189+
@Test
190+
public void matchingRequestWhenMatchThenKeepOriginalRequestLocale() {
191+
CookieRequestCache cookieRequestCache = new CookieRequestCache();
192+
MockHttpServletRequest request = new MockHttpServletRequest();
193+
request.setServerPort(443);
194+
request.setSecure(true);
195+
request.setScheme("https");
196+
request.setServerName("example.com");
197+
request.setRequestURI("/destination");
198+
request.setPreferredLocales(Arrays.asList(Locale.FRENCH, Locale.GERMANY));
199+
String redirectUrl = "https://example.com/destination";
200+
request.setCookies(new Cookie(DEFAULT_COOKIE_NAME, encodeCookie(redirectUrl)));
201+
MockHttpServletResponse response = new MockHttpServletResponse();
202+
HttpServletRequest matchingRequest = cookieRequestCache.getMatchingRequest(request, response);
203+
assertThat(matchingRequest).isNotNull();
204+
assertThat(Collections.list(matchingRequest.getLocales())).contains(Locale.FRENCH, Locale.GERMANY);
205+
}
206+
185207
private static String encodeCookie(String cookieValue) {
186208
return Base64.getEncoder().encodeToString(cookieValue.getBytes());
187209
}

0 commit comments

Comments
 (0)