From 2b6821622e6a90b6ed16d5141904940a0ed79cf7 Mon Sep 17 00:00:00 2001 From: Dennis Kieselhorst Date: Sat, 7 Jun 2014 09:24:29 +0200 Subject: [PATCH] Make DefaultRedirectStrategy more extensible Fixes gh-2173 --- .../security/web/DefaultRedirectStrategy.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/DefaultRedirectStrategy.java b/web/src/main/java/org/springframework/security/web/DefaultRedirectStrategy.java index be07f6cd78..76474b1288 100644 --- a/web/src/main/java/org/springframework/security/web/DefaultRedirectStrategy.java +++ b/web/src/main/java/org/springframework/security/web/DefaultRedirectStrategy.java @@ -57,9 +57,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy { response.sendRedirect(redirectUrl); } - private String calculateRedirectUrl(String contextPath, String url) { + protected String calculateRedirectUrl(String contextPath, String url) { if (!UrlUtils.isAbsoluteUrl(url)) { - if (contextRelative) { + if (isContextRelative()) { return url; } else { @@ -69,7 +69,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy { // Full URL, including http(s):// - if (!contextRelative) { + if (!isContextRelative()) { return url; } @@ -93,4 +93,11 @@ public class DefaultRedirectStrategy implements RedirectStrategy { this.contextRelative = useRelativeContext; } + /** + * Returns true, if the redirection URL should be calculated + * minus the protocol and context path (defaults to false). + */ + protected boolean isContextRelative() { + return contextRelative; + } }