Use ServletUriComponentsBuilder instead of UrlPathHelper

This commit is contained in:
Craig Andrews 2021-04-16 11:55:30 -04:00 committed by Rob Winch
parent 2bcd4627fa
commit 0af74ce134
1 changed files with 3 additions and 8 deletions

View File

@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
/**
* Performs a redirect to the original request URL when an invalid requested session is
@ -42,15 +42,10 @@ public final class RequestedUrlRedirectInvalidSessionStrategy implements Invalid
private boolean createNewSession = true;
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
@Override
public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException {
String destinationUrl = this.urlPathHelper.getOriginatingRequestUri(request);
String queryString = this.urlPathHelper.getOriginatingQueryString(request);
if (queryString != null && !queryString.equals("")) {
destinationUrl = destinationUrl + "?" + queryString;
}
String destinationUrl = ServletUriComponentsBuilder.fromRequest(request).host(null).scheme(null).port(null)
.toUriString();
this.logger.debug("Starting new session (if required) and redirecting to '" + destinationUrl + "'");
if (this.createNewSession) {
request.getSession();