You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by tu...@apache.org on 2012/12/11 19:38:15 UTC

svn commit: r1420330 - in /oozie/branches/branch-3.3: ./ core/src/main/java/org/apache/oozie/ core/src/main/java/org/apache/oozie/servlet/ core/src/test/java/org/apache/oozie/servlet/

Author: tucu
Date: Tue Dec 11 18:38:14 2012
New Revision: 1420330

URL: http://svn.apache.org/viewvc?rev=1420330&view=rev
Log:
OOZIE-1128 When a user submitting a job is not UNDEF in the request, it should use that user as the submitter (tucu)

Modified:
    oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/ErrorCode.java
    oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobServlet.java
    oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobsServlet.java
    oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/servlet/TestJobsServlet.java
    oozie/branches/branch-3.3/release-log.txt

Modified: oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/ErrorCode.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/ErrorCode.java?rev=1420330&r1=1420329&r2=1420330&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/ErrorCode.java (original)
+++ oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/ErrorCode.java Tue Dec 11 18:38:14 2012
@@ -68,7 +68,6 @@ public enum ErrorCode {
     E0308(XLog.STD, "Could not parse date range parameter [{0}]"),
 
 
-    E0400(XLog.STD, "User mismatch, request user [{0}] configuration user [{1}]"),
     E0401(XLog.STD, "Missing configuration property [{0}]"),
     E0402(XLog.STD, "Invalid callback ID [{0}]"),
     E0403(XLog.STD, "Invalid callback data, {0}"),

Modified: oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobServlet.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobServlet.java?rev=1420330&r1=1420329&r2=1420330&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobServlet.java (original)
+++ oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobServlet.java Tue Dec 11 18:38:14 2012
@@ -106,7 +106,11 @@ public abstract class BaseJobServlet ext
             validateContentType(request, RestConstants.XML_CONTENT_TYPE);
             Configuration conf = new XConfiguration(request.getInputStream());
             stopCron();
-            checkAuthorizationForApp(getUser(request), conf);
+            String requestUser = getUser(request);
+            if (!requestUser.equals(UNDEF)) {
+                conf.set(OozieClient.USER_NAME, requestUser);
+            }
+            BaseJobServlet.checkAuthorizationForApp(conf);
             JobUtils.normalizeAppPath(conf.get(OozieClient.USER_NAME), conf.get(OozieClient.GROUP_NAME), conf);
             reRunJob(request, response, conf);
             startCron();
@@ -145,21 +149,17 @@ public abstract class BaseJobServlet ext
     /**
      * Validate the configuration user/group. <p/>
      *
-     * @param requestUser user in request.
      * @param conf configuration.
      * @throws XServletException thrown if the configuration does not have a property {@link
      * org.apache.oozie.client.OozieClient#USER_NAME}.
      */
-    static void checkAuthorizationForApp(String requestUser, Configuration conf) throws XServletException {
+    static void checkAuthorizationForApp(Configuration conf) throws XServletException {
         String user = conf.get(OozieClient.USER_NAME);
         String acl = ConfigUtils.getWithDeprecatedCheck(conf, OozieClient.GROUP_NAME, OozieClient.JOB_ACL, null);
         try {
             if (user == null) {
                 throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0401, OozieClient.USER_NAME);
             }
-            if (!requestUser.equals(UNDEF) && !user.equals(requestUser)) {
-                throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0400, requestUser, user);
-            }
             AuthorizationService auth = Services.get().get(AuthorizationService.class);
 
             if (acl != null){

Modified: oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobsServlet.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobsServlet.java?rev=1420330&r1=1420329&r2=1420330&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobsServlet.java (original)
+++ oozie/branches/branch-3.3/core/src/main/java/org/apache/oozie/servlet/BaseJobsServlet.java Tue Dec 11 18:38:14 2012
@@ -90,7 +90,11 @@ public abstract class BaseJobsServlet ex
         conf = conf.resolve();
 
         validateJobConfiguration(conf);
-        BaseJobServlet.checkAuthorizationForApp(getUser(request), conf);
+        String requestUser = getUser(request);
+        if (!requestUser.equals(UNDEF)) {
+            conf.set(OozieClient.USER_NAME, requestUser);
+        }
+        BaseJobServlet.checkAuthorizationForApp(conf);
         JobUtils.normalizeAppPath(conf.get(OozieClient.USER_NAME), conf.get(OozieClient.GROUP_NAME), conf);
 
         JSONObject json = submitJob(request, conf);

Modified: oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/servlet/TestJobsServlet.java
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/servlet/TestJobsServlet.java?rev=1420330&r1=1420329&r2=1420330&view=diff
==============================================================================
--- oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/servlet/TestJobsServlet.java (original)
+++ oozie/branches/branch-3.3/core/src/test/java/org/apache/oozie/servlet/TestJobsServlet.java Tue Dec 11 18:38:14 2012
@@ -36,6 +36,7 @@ import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.JSONValue;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
@@ -180,4 +181,41 @@ public class TestJobsServlet extends Dag
         });
     }
 
+    public static class V0JobsServletWithDefUser extends V0JobsServlet {
+
+        protected String getUser(HttpServletRequest request) {
+            return getTestUser2();
+        }
+    }
+
+    public void testDiffUser() throws Exception {
+        //runTest("/jobs", BaseJobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() {
+        runTest("/v0/jobs", V0JobsServletWithDefUser.class, IS_SECURITY_ENABLED, new Callable<Void>() {
+            public Void call() throws Exception {
+                MockDagEngineService.reset();
+
+                String appPath = getFsTestCaseDir().toString() + "/app";
+
+                FileSystem fs = getFileSystem();
+                Path jobXmlPath = new Path(appPath, "workflow.xml");
+                fs.create(jobXmlPath);
+
+                Configuration jobConf = new XConfiguration();
+                jobConf.set(OozieClient.USER_NAME, getTestUser());
+                jobConf.set(OozieClient.APP_PATH, appPath);
+
+                Map<String, String> params = new HashMap<String, String>();
+                URL url = createURL("", params);
+                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+                conn.setRequestMethod("POST");
+                conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE);
+                conn.setDoOutput(true);
+                jobConf.writeXml(conn.getOutputStream());
+                assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode());
+                assertEquals(getTestUser2(), MockDagEngineService.user);
+                return null;
+            }
+        });
+    }
+
 }

Modified: oozie/branches/branch-3.3/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/branches/branch-3.3/release-log.txt?rev=1420330&r1=1420329&r2=1420330&view=diff
==============================================================================
--- oozie/branches/branch-3.3/release-log.txt (original)
+++ oozie/branches/branch-3.3/release-log.txt Tue Dec 11 18:38:14 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.3.1 (unreleased)
 
+OOZIE-1128 When a user submitting a job is not UNDEF in the request, it should use that user as the submitter (tucu)
 OOZIE-1091 workflow functional spec, fs action related issues (virag)
 OOZIE-1116 Create hbaselibs module (virag)
 OOZIE-1093 recursive fs chmod does not change the leaf directory (virag)