| 
					
				 | 
			
			
				@@ -19,6 +19,7 @@ import java.io.UnsupportedEncodingException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.net.URLDecoder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.servlet.http.HttpSession; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.security.Authentication; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.security.ui.savedrequest.SavedRequest; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -29,9 +30,9 @@ import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 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.  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 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 Luke Taylor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @version $Id$ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -40,26 +41,22 @@ import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class TargetUrlResolverImpl implements TargetUrlResolver { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static String DEFAULT_TARGET_PARAMETER = "spring-security-redirect"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /* SEC-213 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private String targetUrlParameter = DEFAULT_TARGET_PARAMETER; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * 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. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * It will then return null for a POST/PUT request. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * Defaults to false. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	private boolean justUseSavedRequestOnGet = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private boolean justUseSavedRequestOnGet = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    /* (non-Javadoc) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * @see org.acegisecurity.ui.TargetUrlResolver#determineTargetUrl(org.acegisecurity.ui.savedrequest.SavedRequest, javax.servlet.http.HttpServletRequest, org.acegisecurity.Authentication) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public String determineTargetUrl(SavedRequest savedRequest, HttpServletRequest currentRequest, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Authentication auth) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public String determineTargetUrl(HttpServletRequest currentRequest, Authentication auth) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String targetUrl = currentRequest.getParameter(targetUrlParameter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (StringUtils.hasText(targetUrl)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return URLDecoder.decode(targetUrl, "UTF-8"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -68,6 +65,8 @@ public class TargetUrlResolverImpl implements TargetUrlResolver { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SavedRequest savedRequest = getSavedRequest(currentRequest); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (savedRequest != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!justUseSavedRequestOnGet || savedRequest.getMethod().equals("GET")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 targetUrl = savedRequest.getFullRequestUrl(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -75,35 +74,47 @@ public class TargetUrlResolverImpl implements TargetUrlResolver { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return targetUrl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * @return <code>true</code> if just GET request will be used 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * to determine target URLs, <code>false</code> otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	protected boolean isJustUseSavedRequestOnGet() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return justUseSavedRequestOnGet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * @param justUseSavedRequestOnGet set to <code>true</code> if  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * just GET request will be used to determine target URLs,  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 * <code>false</code> otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public void setJustUseSavedRequestOnGet(boolean 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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	    Assert.hasText("targetUrlParamete canot be null or empty"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static SavedRequest getSavedRequest(HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        HttpSession session = request.getSession(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (session == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SavedRequest savedRequest = (SavedRequest) session.getAttribute(SavedRequest.SPRING_SECURITY_SAVED_REQUEST_KEY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return savedRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return <code>true</code> if just GET request will be used 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * to determine target URLs, <code>false</code> otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    protected boolean isJustUseSavedRequestOnGet() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return justUseSavedRequestOnGet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param justUseSavedRequestOnGet set to <code>true</code> if 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * just GET request will be used to determine target URLs, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * <code>false</code> otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void setJustUseSavedRequestOnGet(boolean 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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Assert.hasText("targetUrlParamete canot be null or empty"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.targetUrlParameter = targetUrlParameter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |