Refactoring of methods names in UrlUtils for consistency.
This commit is contained in:
parent
f6800fbe04
commit
d1cb85e4f3
|
@ -70,7 +70,7 @@ public class FilterInvocation {
|
|||
* @return the full URL of this request
|
||||
*/
|
||||
public String getFullRequestUrl() {
|
||||
return UrlUtils.getFullRequestUrl(this);
|
||||
return UrlUtils.buildFullRequestUrl(request);
|
||||
}
|
||||
|
||||
public HttpServletRequest getHttpRequest() {
|
||||
|
@ -87,7 +87,7 @@ public class FilterInvocation {
|
|||
* @return the URL, excluding any server name, context path or servlet path
|
||||
*/
|
||||
public String getRequestUrl() {
|
||||
return UrlUtils.getRequestUrl(this);
|
||||
return UrlUtils.buildRequestUrl(request);
|
||||
}
|
||||
|
||||
public HttpServletRequest getRequest() {
|
||||
|
|
|
@ -52,6 +52,8 @@ public class SavedRequest implements java.io.Serializable {
|
|||
|
||||
protected static final Log logger = LogFactory.getLog(SavedRequest.class);
|
||||
|
||||
public static final String SPRING_SECURITY_SAVED_REQUEST_KEY = "SPRING_SECURITY_SAVED_REQUEST_KEY";
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private ArrayList<SavedCookie> cookies = new ArrayList<SavedCookie>();
|
||||
|
@ -69,8 +71,6 @@ public class SavedRequest implements java.io.Serializable {
|
|||
private String servletPath;
|
||||
private int serverPort;
|
||||
|
||||
public static final String SPRING_SECURITY_SAVED_REQUEST_KEY = "SPRING_SECURITY_SAVED_REQUEST_KEY";
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -228,7 +228,7 @@ public class SavedRequest implements java.io.Serializable {
|
|||
*/
|
||||
public String getFullRequestUrl() {
|
||||
return UrlUtils.buildFullRequestUrl(this.getScheme(), this.getServerName(), this.getServerPort(), this.getContextPath(),
|
||||
this.getRequestURL(), this.getServletPath(), this.getRequestURI(), this.getPathInfo(), this.getQueryString());
|
||||
this.getServletPath(), this.getRequestURI(), this.getPathInfo(), this.getQueryString());
|
||||
}
|
||||
|
||||
public Iterator<String> getHeaderNames() {
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.springframework.security.web.util;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.security.web.FilterInvocation;
|
||||
|
||||
|
||||
/**
|
||||
* Provides static methods for composing URLs.<p>Placed into a separate class for visibility, so that changes to
|
||||
|
@ -28,21 +26,23 @@ import org.springframework.security.web.FilterInvocation;
|
|||
* @version $Id$
|
||||
*/
|
||||
public final class UrlUtils {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
private UrlUtils() {
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static String buildFullRequestUrl(HttpServletRequest r) {
|
||||
return buildFullRequestUrl(r.getScheme(), r.getServerName(), r.getServerPort(), r.getContextPath(),
|
||||
r.getServletPath(), r.getRequestURI(), r.getPathInfo(), r.getQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the full URL the client used to make the request.<p>Note that the server port will not be shown
|
||||
* if it is the default server port for HTTP or HTTPS (ie 80 and 443 respectively).</p>
|
||||
* Obtains the full URL the client used to make the request.
|
||||
* <p>
|
||||
* Note that the server port will not be shown if it is the default server port for HTTP or HTTPS
|
||||
* (80 and 443 respectively).
|
||||
*
|
||||
* @return the full URL
|
||||
*/
|
||||
public static String buildFullRequestUrl(String scheme, String serverName, int serverPort, String contextPath,
|
||||
String requestUrl, String servletPath, String requestURI, String pathInfo, String queryString) {
|
||||
String servletPath, String requestURI, String pathInfo, String queryString) {
|
||||
|
||||
boolean includePort = true;
|
||||
|
||||
|
@ -55,7 +55,17 @@ public final class UrlUtils {
|
|||
}
|
||||
|
||||
return scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "") + contextPath
|
||||
+ buildRequestUrl(servletPath, requestURI, contextPath, pathInfo, queryString);
|
||||
+ buildRequestUrl(servletPath, requestURI, contextPath, pathInfo, queryString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the web application-specific fragment of the request URL.
|
||||
*
|
||||
* @return the URL, excluding any server name, context path or servlet path
|
||||
*/
|
||||
public static String buildRequestUrl(HttpServletRequest r) {
|
||||
return buildRequestUrl(r.getServletPath(), r.getRequestURI(), r.getContextPath(), r.getPathInfo(),
|
||||
r.getQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,20 +86,6 @@ public final class UrlUtils {
|
|||
return uri + ((pathInfo == null) ? "" : pathInfo) + ((queryString == null) ? "" : ("?" + queryString));
|
||||
}
|
||||
|
||||
public static String getFullRequestUrl(FilterInvocation fi) {
|
||||
HttpServletRequest r = fi.getHttpRequest();
|
||||
|
||||
return buildFullRequestUrl(r.getScheme(), r.getServerName(), r.getServerPort(), r.getContextPath(),
|
||||
r.getRequestURL().toString(), r.getServletPath(), r.getRequestURI(), r.getPathInfo(), r.getQueryString());
|
||||
}
|
||||
|
||||
public static String getRequestUrl(FilterInvocation fi) {
|
||||
HttpServletRequest r = fi.getHttpRequest();
|
||||
|
||||
return buildRequestUrl(r.getServletPath(), r.getRequestURI(), r.getContextPath(), r.getPathInfo(),
|
||||
r.getQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the supplied URL starts with a "/" or "http".
|
||||
*/
|
||||
|
|
|
@ -1,20 +1,28 @@
|
|||
package org.springframework.security.web.savedrequest;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.MockPortResolver;
|
||||
import org.springframework.security.web.savedrequest.SavedRequest;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
public class SavedRequestTests extends TestCase {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SavedRequestTests {
|
||||
|
||||
public void testCaseInsensitveHeaders() throws Exception {
|
||||
@Test
|
||||
public void headersAreCaseInsensitive() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("USER-aGenT", "Mozilla");
|
||||
SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443));
|
||||
assertEquals("Mozilla", saved.getHeaderValues("user-agent").next());
|
||||
}
|
||||
|
||||
public void testCaseInsensitveParameters() throws Exception {
|
||||
// TODO: Why are parameters case insensitive. I think this is a mistake
|
||||
@Test
|
||||
public void parametersAreCaseInsensitive() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("ThisIsATest", "Hi mom");
|
||||
SavedRequest saved = new SavedRequest(request, new MockPortResolver(8080, 8443));
|
||||
|
|
Loading…
Reference in New Issue