Преглед изворни кода

Use ServletUriComponentsBuilder instead of UrlPathHelper

Craig Andrews пре 4 година
родитељ
комит
0af74ce134

+ 3 - 8
web/src/main/java/org/springframework/security/web/session/RequestedUrlRedirectInvalidSessionStrategy.java

@@ -26,7 +26,7 @@ import org.apache.commons.logging.LogFactory;
 
 
 import org.springframework.security.web.DefaultRedirectStrategy;
 import org.springframework.security.web.DefaultRedirectStrategy;
 import org.springframework.security.web.RedirectStrategy;
 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
  * 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 boolean createNewSession = true;
 
 
-	private final UrlPathHelper urlPathHelper = new UrlPathHelper();
-
 	@Override
 	@Override
 	public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException {
 	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 + "'");
 		this.logger.debug("Starting new session (if required) and redirecting to '" + destinationUrl + "'");
 		if (this.createNewSession) {
 		if (this.createNewSession) {
 			request.getSession();
 			request.getSession();