Skip to content

CookieRequestCache SavedRequest has no parameters #18204

@StefanPopa99

Description

@StefanPopa99

Describe the bug
RequestCache.getRequest returns the SavedRequest. However, CookieRequestCache.getRequest implementation returns a SavedRequest without parameters; Hence, calling getParameterValues will always return null. On the other hand, HttpSessionRequestCache implementation works as expected.

As a workaround, I rely on SavedRequest.getRedirectUrl and extract the parameters from there.

To Reproduce
For example, use CookieRequestCache and go through an oauth2 flow. On callback, the SavedRequest has no parameters.

Expected behavior
SavedRequest.getParameterValues should return the parameters if they are available in the url.

Proposed solution
class CookieRequestCache

@Override
public @Nullable SavedRequest getRequest(HttpServletRequest request, HttpServletResponse response) {
	Cookie savedRequestCookie = WebUtils.getCookie(request, COOKIE_NAME);
	if (savedRequestCookie == null) {
		return null;
	}
	String originalURI = decodeCookie(savedRequestCookie.getValue());
	if (originalURI == null) {
		return null;
	}
	UriComponents uriComponents = UriComponentsBuilder.fromUriString(originalURI).build();
	DefaultSavedRequest.Builder builder = new DefaultSavedRequest.Builder();
	int port = getPort(uriComponents);
	MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
	Map<String, String[]> parameterMap = queryParams.entrySet().stream().collect(
			Collectors.toMap(
					Map.Entry::getKey,
					entry -> entry.getValue().toArray(new String[0])));
	return builder.setScheme(uriComponents.getScheme())
		.setServerName(uriComponents.getHost())
		.setRequestURI(uriComponents.getPath())
		.setQueryString(uriComponents.getQuery())
		.setServerPort(port)
		.setMethod(request.getMethod())
		.setLocales(Collections.list(request.getLocales()))
		.setParameters(parameterMap)
		.build();
}

Metadata

Metadata

Assignees

Labels

in: webAn issue in web modules (web, webmvc)status: duplicateA duplicate of another issuetype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions