Author: kwright
Date: Tue Mar 31 01:16:21 2015
New Revision: 1670234

URL: http://svn.apache.org/r1670234
Log:
Autologin using blank user and password, if nothing is specified

Modified:
    
manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java

Modified: 
manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java?rev=1670234&r1=1670233&r2=1670234&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
 Tue Mar 31 01:16:21 2015
@@ -56,6 +56,20 @@ public class APIServlet extends HttpServ
     super.destroy();
   }
 
+  protected APIProfile getAPISession(IThreadContext tc, HttpServletRequest 
request)
+  {
+    Object x = request.getSession().getAttribute("apiprofile");
+    if (x == null || !(x instanceof APIProfile))
+    {
+      // Basic login
+      APIProfile ap = new APIProfile();
+      request.getSession().setAttribute("apiprofile",ap);
+      ap.login(tc,"","");
+      return ap;
+    }
+    return (APIProfile)x;
+  }
+  
   /** The get method.
   */
   protected void doGet(HttpServletRequest request, HttpServletResponse 
response)
@@ -78,18 +92,11 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("apiprofile");
-      if (x == null || !(x instanceof APIProfile))
-      {
-        // Not logged in
-        response.sendError(response.SC_UNAUTHORIZED);
-        return;
-      }
-      APIProfile ap = (APIProfile)x;
+      APIProfile ap = getAPISession(tc,request);
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
-        response.sendError(response.SC_FORBIDDEN);
+        response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
       
@@ -124,18 +131,11 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("apiprofile");
-      if (x == null || !(x instanceof APIProfile))
-      {
-        // Not logged in
-        response.sendError(response.SC_UNAUTHORIZED);
-        return;
-      }
-      APIProfile ap = (APIProfile)x;
+      APIProfile ap = getAPISession(tc,request);
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
-        response.sendError(response.SC_FORBIDDEN);
+        response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
 
@@ -190,8 +190,7 @@ public class APIServlet extends HttpServ
         if (password == null)
           password = "";
         
-        APIProfile ap = new APIProfile();
-        request.getSession().setAttribute("apiprofile",ap);
+        APIProfile ap = getAPISession(tc,request);
         ap.login(tc,userID,password);
         if (!ap.getLoggedOn())
         {
@@ -205,13 +204,7 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("apiprofile");
-      if (x == null || !(x instanceof APIProfile))
-      {
-        response.sendError(response.SC_UNAUTHORIZED);
-        return;
-      }
-      APIProfile ap = (APIProfile)x;
+      APIProfile ap = getAPISession(tc,request);
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
@@ -260,14 +253,7 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("apiprofile");
-      if (x == null || !(x instanceof APIProfile))
-      {
-        // Not logged in
-        response.sendError(response.SC_UNAUTHORIZED);
-        return;
-      }
-      APIProfile ap = (APIProfile)x;
+      APIProfile ap = getAPISession(tc,request);
       if (!ap.getLoggedOn())
       {
         // Login exists but failed


Reply via email to