2
0
Эх сурвалжийг харах

fix FilterInvocation so it doesn't lose the tail end (past the servlet path) of the request url

Colin Sampaleanu 21 жил өмнө
parent
commit
6eb0a47632

+ 5 - 4
core/src/main/java/org/acegisecurity/intercept/web/FilterInvocation.java

@@ -101,10 +101,11 @@ public class FilterInvocation {
     }
 
     public String getRequestUrl() {
-        return getHttpRequest().getServletPath()
-        + ((getHttpRequest().getQueryString() == null) ? ""
-                                                       : ("?"
-        + getHttpRequest().getQueryString()));
+        String pathInfo = getHttpRequest().getPathInfo();
+        String queryString = getHttpRequest().getQueryString();
+        
+        return getHttpRequest().getServletPath() + (pathInfo == null ? "" : pathInfo)
+                + (queryString == null ? "" : ("?" + queryString));
     }
 
     public ServletResponse getResponse() {

+ 15 - 9
core/src/test/java/org/acegisecurity/MockHttpServletRequest.java

@@ -59,6 +59,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
     private String serverName;
     private String servletPath;
     private int serverPort;
+    private String pathInfo;   // null for no extra path
 
     //~ Constructors ===========================================================
 
@@ -196,8 +197,13 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
+    
+    public void setPathInfo(String pathInfo) {
+        this.pathInfo = pathInfo;
+    }
+    
     public String getPathInfo() {
-        throw new UnsupportedOperationException("mock method not implemented");
+        return pathInfo;
     }
 
     public String getPathTranslated() {
@@ -240,8 +246,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
-    public void setRequestURL(String newRequestURL) {
-        requestURL = newRequestURL;
+    public void setRequestURL(String requestURL) {
+        this.requestURL = requestURL;
     }
 
     public StringBuffer getRequestURL() {
@@ -268,8 +274,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
-    public void setScheme(String newScheme) {
-        scheme = newScheme;
+    public void setScheme(String scheme) {
+        this.scheme = scheme;
     }
 
     public String getScheme() {
@@ -280,16 +286,16 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
-    public void setServerName(String newServerName) {
-        serverName = newServerName;
+    public void setServerName(String serverName) {
+        this.serverName = serverName;
     }
 
     public String getServerName() {
         return serverName;
     }
 
-    public void setServerPort(int newPort) {
-        serverPort = newPort;
+    public void setServerPort(int serverPort) {
+        this.serverPort = serverPort;
     }
 
     public int getServerPort() {

+ 5 - 4
core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java

@@ -68,7 +68,8 @@ public class FilterInvocationTests extends TestCase {
     public void testGettersAndStringMethods() {
         MockHttpServletRequest request = new MockHttpServletRequest(null, null);
         request.setServletPath("/HelloWorld");
-        request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
+        request.setPathInfo("/some/more/segments.html");
+        request.setRequestURL("http://www.example.com/mycontext/HelloWorld/some/more/segments.html");
 
         MockHttpServletResponse response = new MockHttpServletResponse();
         MockFilterChain chain = new MockFilterChain();
@@ -78,9 +79,9 @@ public class FilterInvocationTests extends TestCase {
         assertEquals(response, fi.getResponse());
         assertEquals(response, fi.getHttpResponse());
         assertEquals(chain, fi.getChain());
-        assertEquals("/HelloWorld", fi.getRequestUrl());
-        assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
-        assertEquals("http://www.example.com/mycontext/HelloWorld",
+        assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
+        assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html", fi.toString());
+        assertEquals("http://www.example.com/mycontext/HelloWorld/some/more/segments.html",
             fi.getFullRequestUrl());
     }