You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2008/03/13 13:22:01 UTC

svn commit: r636738 - /incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java

Author: cziegeler
Date: Thu Mar 13 05:21:57 2008
New Revision: 636738

URL: http://svn.apache.org/viewvc?rev=636738&view=rev
Log:
Add context path to ajax request.

Modified:
    incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java

Modified: incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java?rev=636738&r1=636737&r2=636738&view=diff
==============================================================================
--- incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java (original)
+++ incubator/sling/trunk/sling/httpauth/src/main/java/org/apache/sling/httpauth/impl/LoginServlet.java Thu Mar 13 05:21:57 2008
@@ -27,7 +27,7 @@
 
 /**
  * The <code>LoginServlet</code> TODO
- * 
+ *
  * @scr.component metatype="no"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.property name="service.description" value="HTTP Header Login Servlet"
@@ -47,22 +47,23 @@
 
         prolog(pw);
 
+        final String contexPath = request.getContextPath();
         String authType = request.getAuthType();
         String user = request.getRemoteUser();
 
         if (authType == null) {
-            login(pw);
+            login(pw, contexPath);
         } else {
-            logout(pw, user);
+            logout(pw, contexPath, user);
         }
 
         epilog(pw);
     }
 
-    private void login(PrintWriter pw) {
+    private void login(PrintWriter pw, String contextPath) {
 
         pw.println("<script>");
-        ajax(pw);
+        ajax(pw, contextPath);
         pw.println("function loginuser() {");
         pw.println("    var user = document.forms['login'].usr.value;");
         pw.println("    var pass = document.forms['login'].pwd.value;");
@@ -81,9 +82,9 @@
         pw.println("</form>");
     }
 
-    private void logout(PrintWriter pw, String user) {
+    private void logout(PrintWriter pw, String contextPath, String user) {
         pw.println("<script>");
-        ajax(pw);
+        ajax(pw, contextPath);
         pw.println("function logoutuser() {");
 
         pw.println("    try {");
@@ -144,7 +145,7 @@
         pw.println("<div id=\"main\">");
     }
 
-    private void ajax(PrintWriter pw) {
+    private void ajax(PrintWriter pw, final String contextPath) {
         pw.println("//-----------------------------------------------------------------------------");
         pw.println("// Ajax Support");
 
@@ -181,7 +182,7 @@
         pw.println("             xmlhttp.abort();");
         pw.println("         }");
 
-        pw.println("         xmlhttp.open('GET', '/?"
+        pw.println("         xmlhttp.open('GET', '" + contextPath + "?"
             + AuthorizationHeaderAuthenticationHandler.REQUEST_LOGIN_PARAMETER
             + "=1', false, user, pass);");