You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2015/03/31 02:16:39 UTC

svn commit: r1670228 - in /manifoldcf/branches/CONNECTORS-1177/framework: api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/ core/src/main/java/org/apache/manifoldcf/core/system/ ui-core/src/main/java/org/apache/manifoldcf/ui/beans/

Author: kwright
Date: Tue Mar 31 00:16:38 2015
New Revision: 1670228

URL: http://svn.apache.org/r1670228
Log:
Use a dedicated bean for API

Added:
    manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java   (with props)
Modified:
    manifoldcf/branches/CONNECTORS-1177/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
    manifoldcf/branches/CONNECTORS-1177/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.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=1670228&r1=1670227&r2=1670228&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 00:16:38 2015
@@ -25,7 +25,7 @@ import org.apache.manifoldcf.crawler.sys
 import org.apache.manifoldcf.crawler.system.Logging;
 import org.apache.manifoldcf.core.util.URLDecoder;
 
-import org.apache.manifoldcf.ui.beans.AdminProfile;
+import org.apache.manifoldcf.ui.beans.APIProfile;
 
 import java.io.*;
 import java.nio.charset.StandardCharsets;
@@ -78,14 +78,14 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("adminprofile");
-      if (x == null || !(x instanceof AdminProfile))
+      Object x = request.getSession().getAttribute("apiprofile");
+      if (x == null || !(x instanceof APIProfile))
       {
         // Not logged in
         response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
-      AdminProfile ap = (AdminProfile)x;
+      APIProfile ap = (APIProfile)x;
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
@@ -124,14 +124,14 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("adminprofile");
-      if (x == null || !(x instanceof AdminProfile))
+      Object x = request.getSession().getAttribute("apiprofile");
+      if (x == null || !(x instanceof APIProfile))
       {
         // Not logged in
         response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
-      AdminProfile ap = (AdminProfile)x;
+      APIProfile ap = (APIProfile)x;
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
@@ -190,8 +190,8 @@ public class APIServlet extends HttpServ
         if (password == null)
           password = "";
         
-        AdminProfile ap = new AdminProfile();
-        request.getSession().setAttribute("adminprofile",ap);
+        APIProfile ap = new APIProfile();
+        request.getSession().setAttribute("apiprofile",ap);
         ap.login(tc,userID,password);
         if (!ap.getLoggedOn())
         {
@@ -205,13 +205,13 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("adminprofile");
-      if (x == null || !(x instanceof AdminProfile))
+      Object x = request.getSession().getAttribute("apiprofile");
+      if (x == null || !(x instanceof APIProfile))
       {
         response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
-      AdminProfile ap = (AdminProfile)x;
+      APIProfile ap = (APIProfile)x;
       if (!ap.getLoggedOn())
       {
         // Login exists but failed
@@ -260,14 +260,14 @@ public class APIServlet extends HttpServ
       }
 
       // Verify session
-      Object x = request.getSession().getAttribute("adminprofile");
-      if (x == null || !(x instanceof AdminProfile))
+      Object x = request.getSession().getAttribute("apiprofile");
+      if (x == null || !(x instanceof APIProfile))
       {
         // Not logged in
         response.sendError(response.SC_UNAUTHORIZED);
         return;
       }
-      AdminProfile ap = (AdminProfile)x;
+      APIProfile ap = (APIProfile)x;
       if (!ap.getLoggedOn())
       {
         // Login exists but failed

Modified: manifoldcf/branches/CONNECTORS-1177/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1177/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java?rev=1670228&r1=1670227&r2=1670228&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1177/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java (original)
+++ manifoldcf/branches/CONNECTORS-1177/framework/core/src/main/java/org/apache/manifoldcf/core/system/ManifoldCF.java Tue Mar 31 00:16:38 2015
@@ -108,6 +108,8 @@ public class ManifoldCF
   // Local member variables
   protected static String loginUserName = null;
   protected static String loginPassword = null;
+  protected static String apiLoginUserName = null;
+  protected static String apiLoginPassword = null;
   protected static String masterDatabaseName = null;
   protected static String masterDatabaseUsername = null;
   protected static String masterDatabasePassword = null;
@@ -131,7 +133,12 @@ public class ManifoldCF
   public static final String loginUserNameProperty = "org.apache.manifoldcf.login.name";
   /** UI login password */
   public static final String loginPasswordProperty = "org.apache.manifoldcf.login.password";
-  
+
+  /** API login user name */
+  public static final String apiLoginUserNameProperty = "org.apache.manifoldcf.apilogin.name";
+  /** API login password */
+  public static final String apiLoginPasswordProperty = "org.apache.manifoldcf.apilogin.password";
+
   // Database access properties
   /** Database name property */
   public static final String masterDatabaseNameProperty = "org.apache.manifoldcf.database.name";
@@ -193,6 +200,8 @@ public class ManifoldCF
         processID = null;
         loginUserName = null;
         loginPassword = null;
+        apiLoginUserName = null;
+        apiLoginPassword = null;
         masterDatabaseName = null;
         masterDatabaseUsername = null;
         masterDatabasePassword = null;
@@ -286,6 +295,9 @@ public class ManifoldCF
           loginUserName = LockManagerFactory.getStringProperty(threadContext,loginUserNameProperty,"admin");
           loginPassword = LockManagerFactory.getPossiblyObfuscatedStringProperty(threadContext,loginPasswordProperty,"admin");
 
+          apiLoginUserName = LockManagerFactory.getStringProperty(threadContext,apiLoginUserNameProperty,"");
+          apiLoginPassword = LockManagerFactory.getPossiblyObfuscatedStringProperty(threadContext,apiLoginPasswordProperty,"");
+
           masterDatabaseName = LockManagerFactory.getStringProperty(threadContext,masterDatabaseNameProperty,"dbname");
           masterDatabaseUsername = LockManagerFactory.getStringProperty(threadContext,masterDatabaseUsernameProperty,"manifoldcf");
           masterDatabasePassword = LockManagerFactory.getPossiblyObfuscatedStringProperty(threadContext,masterDatabasePasswordProperty,"local_pg_passwd");
@@ -695,6 +707,25 @@ public class ManifoldCF
     }
   }
 
+  /** Verify API login.
+  */
+  public static boolean verifyAPILogin(IThreadContext threadContext, String userID, String userPassword)
+    throws ManifoldCFException
+  {
+    if (userID != null && userPassword != null)
+    {
+      /*
+      IDBInterface database = DBInterfaceFactory.make(threadContext,
+        ManifoldCF.getMasterDatabaseName(),
+        ManifoldCF.getMasterDatabaseUsername(),
+        ManifoldCF.getMasterDatabasePassword());
+      */
+      // MHL to use a database table, when we get that sophisticated
+      return userID.equals(apiLoginUserName) &&  userPassword.equals(apiLoginPassword);
+    }
+    return false;
+  }
+
   /** Verify login.
   */
   public static boolean verifyLogin(IThreadContext threadContext, String userID, String userPassword)

Added: manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java?rev=1670228&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java (added)
+++ manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java Tue Mar 31 00:16:38 2015
@@ -0,0 +1,157 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.ui.beans;
+
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.*;
+
+/** The profile object contains an API user's login information, and helps establish the
+* session model for the application.  This particular bean maintains the user (against
+* the IAdminUserManager service).
+*/
+public class APIProfile implements HttpSessionBindingListener
+{
+  public static final String _rcsid = "@(#)$Id$";
+
+  /** Time of login */
+  private long loginTime = -1L;
+  /** Logged in user */
+  private String userID = null;
+  /** Set to "true" if user is logged in. */
+  private boolean isLoggedIn = false;
+
+  /** Session identifier */
+  private String sessionIdentifier = null;
+
+  /** Constructor.
+  */
+  public APIProfile()
+  {
+  }
+
+  // The following methods constitute the "login process" for this bean.
+  // Set the user and the company, then set LoggedOn.
+
+  /** Get the current session identifier.
+  *@return the identifier.
+  */
+  public String session()
+  {
+    return sessionIdentifier;
+  }
+
+  /** Get the admin user id.
+  *@return the last login user id.
+  */
+  public String getUserID()
+  {
+    return userID;
+  }
+
+  /** Log out the current user.
+  */
+  public void logout()
+  {
+    sessionCleanup();
+  }
+
+  /** Log on the user, with the already-set user id and company
+  * description.
+  *@param userPassword is the login password for the user.
+  */
+  public void login(IThreadContext threadContext,
+    String userID, String userPassword)
+  {
+    sessionCleanup();
+    try
+    {
+      // Check if everything is in place.
+      if (ManifoldCF.verifyAPILogin(threadContext,userID,userPassword))
+      {
+        isLoggedIn = true;
+        loginTime = System.currentTimeMillis();
+        this.userID = userID;
+      }
+    }
+    catch (ManifoldCFException e)
+    {
+      Logging.misc.fatal("Exception logging in: "+e.getMessage(),e);
+    }
+  }
+
+  /** Get the logged-in status, which will be false if the log-in did not succeed, or
+  * timed out.
+  *@return the current login status: true if logged in.
+  */
+  public boolean getLoggedOn()
+  {
+    return isLoggedIn;
+  }
+
+  /** Get the current login time as a string.
+  *@return the last login time.
+  */
+  public String getLoginTime()
+  {
+    return new java.util.Date(loginTime).toString();
+  }
+
+  /** Get the current login time as a long.
+  *@return the last login time.
+  */
+  public long getLoginTimeLong()
+  {
+    return loginTime;
+  }
+
+  // Nuke stuff for security and the garbage
+  // collector threads
+  private void sessionCleanup()
+  {
+    // Un-log-in the user
+    isLoggedIn = false;
+    userID = null;
+    loginTime = -1L;
+  }
+
+
+  //*****************************************************************
+  // Bind listener api - support session invalidation
+  // vis logout or timeout
+  public void valueBound(HttpSessionBindingEvent e)
+  {
+    HttpSession ss = e.getSession();
+
+    if (sessionIdentifier==null)
+    {
+      sessionIdentifier = ss.getId();
+    }
+  }
+
+  public void valueUnbound(HttpSessionBindingEvent e)
+  {
+    sessionCleanup();
+    sessionIdentifier = null;
+  }
+
+}

Propchange: manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-1177/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java
------------------------------------------------------------------------------
    svn:keywords = Id