You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2011/01/22 20:35:02 UTC

svn commit: r1062243 - in /sling/trunk: bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/ launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/

Author: justin
Date: Sat Jan 22 19:35:02 2011
New Revision: 1062243

URL: http://svn.apache.org/viewvc?rev=1062243&view=rev
Log:
fixing SLING-1940 - resource attribute/param should be a full path, including the servlet context.

Modified:
    sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/AbstractAuthenticationFormServlet.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/FormGenerationTest.java

Modified: sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/AbstractAuthenticationFormServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/AbstractAuthenticationFormServlet.java?rev=1062243&r1=1062242&r2=1062243&view=diff
==============================================================================
--- sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/AbstractAuthenticationFormServlet.java (original)
+++ sling/trunk/bundles/auth/core/src/main/java/org/apache/sling/auth/core/spi/AbstractAuthenticationFormServlet.java Sat Jan 22 19:35:02 2011
@@ -162,31 +162,25 @@ public abstract class AbstractAuthentica
 
     /**
      * Returns the context path for the authentication form request. This path
-     * includes the following parts:
-     * <ol>
-     * <li>The Servlet context path (
-     * <code>HttpServletRequest.getContextPath()</code></li>
-     * <li>The path to the authenticated resource as returned by
+     * is the path to the authenticated resource as returned by
      * {@link #getResource(HttpServletRequest)} (without the optional query
-     * string which may be contained in the resource path)</li>
-     * </ol>
+     * string which may be contained in the resource path). If {@link #getResource(HttpServletRequest)}
+     * return an empty string, the servlet context path is used.
      *
      * @param request The request
-     * @return The context path for the form action consisting of the request
-     *         context path and the resource to which the user is to
-     *         authenticate.
+     * @return The context path for the form action consisting of the resource to
+     *         which the user is to authenticate.
      */
     protected String getContextPath(final HttpServletRequest request) {
-        StringBuilder b = new StringBuilder();
-        b.append(request.getContextPath());
-        String resource = getResource(request);
-        int query = resource.indexOf('?');
+        String contextPath = getResource(request);
+        if ("".equals(contextPath)) {
+            contextPath = request.getContextPath();
+        }
+        int query = contextPath.indexOf('?');
         if (query > 0) {
-            b.append(resource.substring(0, query));
-        } else {
-            b.append(resource);
+            contextPath = contextPath.substring(0, query);
         }
-        String contextPath = b.toString();
+        
         return removeEndingSlash(contextPath);
     }
 

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/FormGenerationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/FormGenerationTest.java?rev=1062243&r1=1062242&r2=1062243&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/FormGenerationTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/login/FormGenerationTest.java Sat Jan 22 19:35:02 2011
@@ -26,35 +26,36 @@ import org.apache.sling.commons.testing.
  */
 public class FormGenerationTest extends HttpTestBase {
 
+    public void testSelectorFormForDefaultResource() throws Exception {
+        String content = getContent(HTTP_BASE_URL + "/system/sling/selector/login", CONTENT_TYPE_HTML,
+                null, 200);
+
+        assertTrue("form action is not correct.", content.contains("action=\"" + SERVLET_CONTEXT + "/j_security_check\""));
+        assertTrue("sling image reference is not correct.",
+                content.contains("<img border=\"0\" src=\"" + SERVLET_CONTEXT + "/sling-logo.png\"/>"));
+    }
+
     public void testSelectorFormForRootResource() throws Exception {
-        String contextPath = getContextPath(HTTP_BASE_URL);
+        String resource = SERVLET_CONTEXT.equals("") ? "/" : SERVLET_CONTEXT;
+        
         String content = getContent(HTTP_BASE_URL + "/system/sling/selector/login", CONTENT_TYPE_HTML,
-                Arrays.asList(new NameValuePair("resource", "/")), 200);
+                Arrays.asList(new NameValuePair("resource", resource)), 200);
 
-        assertTrue("form action is not correct.", content.contains("action=\"" + contextPath + "/j_security_check\""));
+        assertTrue("form action is not correct.", content.contains("action=\"" + SERVLET_CONTEXT + "/j_security_check\""));
         assertTrue("sling image reference is not correct.",
-                content.contains("<img border=\"0\" src=\"" + contextPath + "/sling-logo.png\"/>"));
+                content.contains("<img border=\"0\" src=\"" + SERVLET_CONTEXT + "/sling-logo.png\"/>"));
     }
 
     public void testSelectorFormForNonRootResource() throws Exception {
-        String contextPath = getContextPath(HTTP_BASE_URL);
+        String resource = SERVLET_CONTEXT + "/var/classes.json";
+        
         String content = getContent(HTTP_BASE_URL + "/system/sling/selector/login", CONTENT_TYPE_HTML,
-                Arrays.asList(new NameValuePair("resource", "/var/classes.json")), 200);
+                Arrays.asList(new NameValuePair("resource", resource)), 200);
 
         assertTrue("form action is not correct.",
-                content.contains("action=\"" + contextPath + "/var/classes.json/j_security_check\""));
+                content.contains("action=\"" + SERVLET_CONTEXT + "/var/classes.json/j_security_check\""));
         assertTrue("sling image reference is not correct.",
-                content.contains("<img border=\"0\" src=\"" + contextPath + "/sling-logo.png\"/>"));
-    }
-
-    private static String getContextPath(String baseURL) {
-        // get the index of the first slash after http:// or https://
-        int idx = baseURL.indexOf('/', 8);
-        if (idx == -1) {
-            return "";
-        } else {
-            return baseURL.substring(idx);
-        }
+                content.contains("<img border=\"0\" src=\"" + SERVLET_CONTEXT + "/sling-logo.png\"/>"));
     }
 
 }