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/06/30 08:14:29 UTC

svn commit: r1688358 - in /manifoldcf/branches/CONNECTORS-1131/framework: api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/ core/src/main/java/org/apache/manifoldcf/core/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf/crawler/syste...

Author: kwright
Date: Tue Jun 30 06:14:29 2015
New Revision: 1688358

URL: http://svn.apache.org/r1688358
Log:
Add authorizer interface and pass it into API code

Added:
    manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java   (with props)
Modified:
    manifoldcf/branches/CONNECTORS-1131/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
    manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuth.java
    manifoldcf/branches/CONNECTORS-1131/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
    manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java
    manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/AdminProfile.java

Modified: manifoldcf/branches/CONNECTORS-1131/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java?rev=1688358&r1=1688357&r2=1688358&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java (original)
+++ manifoldcf/branches/CONNECTORS-1131/framework/api-servlet/src/main/java/org/apache/manifoldcf/apiservlet/APIServlet.java Tue Jun 30 06:14:29 2015
@@ -289,7 +289,7 @@ public class APIServlet extends HttpServ
     
     // There the only response distinction we have here is between exception and no exception.
     Configuration output = new Configuration();
-    int readResult = ManifoldCF.executeReadCommand(tc,output,command,queryParameters);
+    int readResult = ManifoldCF.executeReadCommand(tc,output,command,queryParameters,ap);
 
     // Output
     
@@ -406,7 +406,7 @@ public class APIServlet extends HttpServ
     // Exception vs. no exception
     // OK vs CREATE (both with json response packets)
     Configuration output = new Configuration();
-    int writeResult = ManifoldCF.executeWriteCommand(tc,output,command,input);
+    int writeResult = ManifoldCF.executeWriteCommand(tc,output,command,input,ap);
     
     // Output
     
@@ -569,7 +569,7 @@ public class APIServlet extends HttpServ
 
     
     Configuration output = new Configuration();
-    int writeResult = ManifoldCF.executePostCommand(tc,output,command,input);
+    int writeResult = ManifoldCF.executePostCommand(tc,output,command,input,ap);
     
     // Output
     
@@ -657,7 +657,7 @@ public class APIServlet extends HttpServ
     
     // There the only response distinction we have here is between exception and no exception.
     Configuration output = new Configuration();
-    int result = ManifoldCF.executeDeleteCommand(tc,output,command);
+    int result = ManifoldCF.executeDeleteCommand(tc,output,command,ap);
     
     // Output
     String outputText = null;

Modified: manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuth.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuth.java?rev=1688358&r1=1688357&r2=1688358&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuth.java (original)
+++ manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuth.java Tue Jun 30 06:14:29 2015
@@ -36,6 +36,8 @@ public interface IAuth
   public final static int CAPABILITY_EDIT_CONNECTIONS = 4;
   /** Edit jobs */
   public final static int CAPABILITY_EDIT_JOBS = 5;
+  /** Run jobs */
+  public final static int CAPABILITY_RUN_JOBS = 6;
   
   /** Verify UI login */
   public boolean verifyUILogin(final String userId, final String password)

Added: manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java?rev=1688358&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java (added)
+++ manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java Tue Jun 30 06:14:29 2015
@@ -0,0 +1,45 @@
+/* $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.core.interfaces;
+
+/** An instance of this interface authorizes a user to perform various capabilities within MCF,
+* within the local thread scope.
+*/
+public interface IAuthorizer
+{
+  
+  // User capabilities
+  /** View connections */
+  public final static int CAPABILITY_VIEW_CONNECTIONS = IAuth.CAPABILITY_VIEW_CONNECTIONS;
+  /** View jobs */
+  public final static int CAPABILITY_VIEW_JOBS = IAuth.CAPABILITY_VIEW_JOBS;
+  /** View reports */
+  public final static int CAPABILITY_VIEW_REPORTS = IAuth.CAPABILITY_VIEW_REPORTS;
+  /** Edit connections */
+  public final static int CAPABILITY_EDIT_CONNECTIONS = IAuth.CAPABILITY_EDIT_CONNECTIONS;
+  /** Edit jobs */
+  public final static int CAPABILITY_EDIT_JOBS = IAuth.CAPABILITY_EDIT_JOBS;
+  /** Run jobs */
+  public final static int CAPABILITY_RUN_JOBS = IAuth.CAPABILITY_RUN_JOBS;
+  
+  /** Check user capability */
+  public boolean checkAllowed(final IThreadContext threadContext, final int capability)
+    throws ManifoldCFException;
+  
+}
\ No newline at end of file

Propchange: manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-1131/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IAuthorizer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: manifoldcf/branches/CONNECTORS-1131/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java?rev=1688358&r1=1688357&r2=1688358&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java (original)
+++ manifoldcf/branches/CONNECTORS-1131/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/system/ManifoldCF.java Tue Jun 30 06:14:29 2015
@@ -3161,7 +3161,7 @@ public class ManifoldCF extends org.apac
   *@return read status - either found, not found, or bad args
   */
   public static int executeReadCommand(IThreadContext tc, Configuration output, String path,
-    Map<String,List<String>> queryParameters) throws ManifoldCFException
+    Map<String,List<String>> queryParameters, IAuthorizer authorizer) throws ManifoldCFException
   {
     if (path.equals("jobs"))
     {
@@ -3449,7 +3449,7 @@ public class ManifoldCF extends org.apac
   *@param input is the input object.
   *@return write result - either "not found", "found", or "created".
   */
-  public static int executePostCommand(IThreadContext tc, Configuration output, String path, Configuration input)
+  public static int executePostCommand(IThreadContext tc, Configuration output, String path, Configuration input, IAuthorizer authorizer)
     throws ManifoldCFException
   {
     if (path.equals("jobs"))
@@ -3918,7 +3918,7 @@ public class ManifoldCF extends org.apac
   *@param input is the input object.
   *@return write result - either "not found", "found", or "created".
   */
-  public static int executeWriteCommand(IThreadContext tc, Configuration output, String path, Configuration input)
+  public static int executeWriteCommand(IThreadContext tc, Configuration output, String path, Configuration input, IAuthorizer authorizer)
     throws ManifoldCFException
   {
     if (path.startsWith("start/"))
@@ -4162,7 +4162,7 @@ public class ManifoldCF extends org.apac
   *@param path is the object path.
   *@return delete result code
   */
-  public static int executeDeleteCommand(IThreadContext tc, Configuration output, String path)
+  public static int executeDeleteCommand(IThreadContext tc, Configuration output, String path, IAuthorizer authorizer)
     throws ManifoldCFException
   {
     if (path.startsWith("jobs/"))

Modified: manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java?rev=1688358&r1=1688357&r2=1688358&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java (original)
+++ manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/APIProfile.java Tue Jun 30 06:14:29 2015
@@ -29,7 +29,7 @@ import org.apache.manifoldcf.core.system
 * session model for the application.  This particular bean maintains the user (against
 * the IAdminUserManager service).
 */
-public class APIProfile implements HttpSessionBindingListener
+public class APIProfile implements HttpSessionBindingListener, IAuthorizer
 {
   public static final String _rcsid = "@(#)$Id$";
 
@@ -135,10 +135,22 @@ public class APIProfile implements HttpS
     loginTime = -1L;
   }
 
+  /** Check user capability */
+  @Override
+  public boolean checkAllowed(final IThreadContext threadContext, final int capability)
+    throws ManifoldCFException
+  {
+    if (!isLoggedIn)
+      return false;
+    IAuth auth = AuthFactory.make(threadContext);
+    // Check if everything is in place.
+    return auth.checkCapability(userID,capability);
+  }
 
   //*****************************************************************
   // Bind listener api - support session invalidation
   // vis logout or timeout
+  @Override
   public void valueBound(HttpSessionBindingEvent e)
   {
     HttpSession ss = e.getSession();
@@ -149,6 +161,7 @@ public class APIProfile implements HttpS
     }
   }
 
+  @Override
   public void valueUnbound(HttpSessionBindingEvent e)
   {
     sessionCleanup();

Modified: manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/AdminProfile.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/AdminProfile.java?rev=1688358&r1=1688357&r2=1688358&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/AdminProfile.java (original)
+++ manifoldcf/branches/CONNECTORS-1131/framework/ui-core/src/main/java/org/apache/manifoldcf/ui/beans/AdminProfile.java Tue Jun 30 06:14:29 2015
@@ -30,7 +30,7 @@ import org.apache.manifoldcf.ui.password
 * session model for the application.  This particular bean maintains the user (against
 * the IAdminUserManager service).
 */
-public class AdminProfile implements HttpSessionBindingListener
+public class AdminProfile implements HttpSessionBindingListener, IAuthorizer
 {
   public static final String _rcsid = "@(#)$Id: AdminProfile.java 988245 2010-08-23 18:39:35Z kwright $";
 
@@ -160,10 +160,22 @@ public class AdminProfile implements Htt
     passwordMapper = null;
   }
 
+  /** Check user capability */
+  @Override
+  public boolean checkAllowed(final IThreadContext threadContext, final int capability)
+    throws ManifoldCFException
+  {
+    if (!isLoggedIn)
+      return false;
+    IAuth auth = AuthFactory.make(threadContext);
+    // Check if everything is in place.
+    return auth.checkCapability(userID,capability);
+  }
 
   //*****************************************************************
   // Bind listener api - support session invalidation
   // vis logout or timeout
+  @Override
   public void valueBound(HttpSessionBindingEvent e)
   {
     HttpSession ss = e.getSession();
@@ -174,6 +186,7 @@ public class AdminProfile implements Htt
     }
   }
 
+  @Override
   public void valueUnbound(HttpSessionBindingEvent e)
   {
     sessionCleanup();