|
@@ -15,26 +15,38 @@
|
|
|
|
|
|
package org.springframework.security.ui;
|
|
package org.springframework.security.ui;
|
|
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
+
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.springframework.security.Authentication;
|
|
import org.springframework.security.Authentication;
|
|
import org.springframework.security.ui.savedrequest.SavedRequest;
|
|
import org.springframework.security.ui.savedrequest.SavedRequest;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Default implementation for {@link TargetUrlResolver}
|
|
* Default implementation for {@link TargetUrlResolver}
|
|
|
|
+ * <p>
|
|
|
|
+ * Returns a target URL based from the contents of the configured <tt>targetUrlParameter</tt> if present on
|
|
|
|
+ * the current request. Failing that, the SavedRequest in the session will be used.
|
|
*
|
|
*
|
|
* @author Martino Piccinato
|
|
* @author Martino Piccinato
|
|
|
|
+ * @author Luke Taylor
|
|
* @version $Id$
|
|
* @version $Id$
|
|
* @since 2.0
|
|
* @since 2.0
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
public class TargetUrlResolverImpl implements TargetUrlResolver {
|
|
public class TargetUrlResolverImpl implements TargetUrlResolver {
|
|
|
|
+ public static String DEFAULT_TARGET_PARAMETER = "redirect";
|
|
|
|
+
|
|
|
|
+ /* SEC-213 */
|
|
|
|
+ private String targetUrlParameter;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * If <code>true</code>, will only use <code>SavedRequest</code> to determine the target url on successful
|
|
|
|
|
|
+ * If <code>true</code>, will only use <code>SavedRequest</code> to determine the target URL on successful
|
|
* authentication if the request that caused the authentication request was a GET.
|
|
* authentication if the request that caused the authentication request was a GET.
|
|
- * It will return null on POST/PUT request.
|
|
|
|
- * In most cases it's meaningless to redirect to a Url generated by a POST/PUT request.
|
|
|
|
|
|
+ * It will return null for a POST/PUT request.
|
|
|
|
+ * In most cases it's meaningless to redirect to a URL generated by a POST/PUT request.
|
|
* Defaults to true.
|
|
* Defaults to true.
|
|
*/
|
|
*/
|
|
private boolean justUseSavedRequestOnGet = true;
|
|
private boolean justUseSavedRequestOnGet = true;
|
|
@@ -46,6 +58,18 @@ public class TargetUrlResolverImpl implements TargetUrlResolver {
|
|
Authentication auth) {
|
|
Authentication auth) {
|
|
|
|
|
|
String targetUrl = null;
|
|
String targetUrl = null;
|
|
|
|
+
|
|
|
|
+ if (targetUrlParameter != null) {
|
|
|
|
+ targetUrl = currentRequest.getParameter(targetUrlParameter);
|
|
|
|
+
|
|
|
|
+ if (StringUtils.hasText(targetUrl)) {
|
|
|
|
+ try {
|
|
|
|
+ return URLDecoder.decode(targetUrl, "UTF-8");
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ throw new IllegalStateException("UTF-8 not supported. Shouldn't be possible");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
if (savedRequest != null) {
|
|
if (savedRequest != null) {
|
|
if (!justUseSavedRequestOnGet || savedRequest.getMethod().equals("GET")) {
|
|
if (!justUseSavedRequestOnGet || savedRequest.getMethod().equals("GET")) {
|
|
@@ -72,5 +96,19 @@ public class TargetUrlResolverImpl implements TargetUrlResolver {
|
|
public void setJustUseSavedRequestOnGet(boolean justUseSavedRequestOnGet) {
|
|
public void setJustUseSavedRequestOnGet(boolean justUseSavedRequestOnGet) {
|
|
this.justUseSavedRequestOnGet = justUseSavedRequestOnGet;
|
|
this.justUseSavedRequestOnGet = justUseSavedRequestOnGet;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Before checking the SavedRequest, the current request will be checked for this parameter
|
|
|
|
+ * and the value used as the target URL if resent.
|
|
|
|
+ *
|
|
|
|
+ * @param targetUrlParameter the name of the parameter containing the encoded target URL. Defaults
|
|
|
|
+ * to "redirect".
|
|
|
|
+ */
|
|
|
|
+ public void setTargetUrlParameter(String targetUrlParameter) {
|
|
|
|
+ this.targetUrlParameter = targetUrlParameter;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|