From 30a514870ca843372fde0af8e75693b652f7b832 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Thu, 8 Nov 2018 13:20:32 +0000 Subject: [PATCH] Improved: Add the ability to schedule a job to run as a system/service user (OFBIZ-9557) When scheduling a job it automatically schedules it to run as the user that created the schedule. The issue comes up when that users password changes. If your are forced to change your password automatically you have to delete all previously scheduled jobs and recreate them. This adds a checkbox to run a job as system on Schedule Job screen as system user Permissions are used to guarantee security. Thanks: Matthew Mulligan for report and Rohit Koushal for discussion and patch git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1846137 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/ofbiz/webapp/event/CoreEvents.java | 17 ++++++++++++++++- framework/webtools/config/WebtoolsUiLabels.xml | 3 +++ .../data/WebtoolsSecurityGroupDemoData.xml | 1 + .../data/WebtoolsSecurityPermissionSeedData.xml | 3 +++ framework/webtools/widget/ServiceForms.xml | 4 ++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java index e591406dbc..0223a16cd5 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/CoreEvents.java @@ -42,8 +42,11 @@ import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.base.util.UtilProperties; import org.apache.ofbiz.base.util.UtilValidate; +import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.GenericEntity; +import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.util.EntityQuery; import org.apache.ofbiz.security.Security; import org.apache.ofbiz.service.GenericServiceException; import org.apache.ofbiz.service.LocalDispatcher; @@ -107,7 +110,7 @@ public class CoreEvents { Security security = (Security) request.getAttribute("security"); GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - //Delegator delegator = (Delegator) request.getAttribute("delegator"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); Locale locale = UtilHttp.getLocale(request); TimeZone timeZone = UtilHttp.getTimeZone(request); @@ -122,6 +125,7 @@ public class CoreEvents { String serviceIntr = (String) params.remove("SERVICE_INTERVAL"); String serviceCnt = (String) params.remove("SERVICE_COUNT"); String retryCnt = (String) params.remove("SERVICE_MAXRETRY"); + String runAsSystemUser = (String) params.remove("SERVICE_RUN_AS_SYSTEM"); // the frequency map Map freqMap = new HashMap(); @@ -206,6 +210,17 @@ public class CoreEvents { serviceContext.put("userLogin", userLogin); } + // Override the userLogin with system when runAsSystem is Y + if ("Y".equals(runAsSystemUser)) { + try { + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", "system").queryOne(); + serviceContext.put("userLogin", userLogin); + } catch (GenericEntityException e) { + request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); + return "error"; + } + } + if (locale != null) { serviceContext.put("locale", locale); } diff --git a/framework/webtools/config/WebtoolsUiLabels.xml b/framework/webtools/config/WebtoolsUiLabels.xml index b29c3ef384..048ff06bbd 100644 --- a/framework/webtools/config/WebtoolsUiLabels.xml +++ b/framework/webtools/config/WebtoolsUiLabels.xml @@ -4535,6 +4535,9 @@ 结果 結果 + + Run As System + GC starten Run GC diff --git a/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml b/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml index 7a246f0f47..894f5f2239 100644 --- a/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml +++ b/framework/webtools/data/WebtoolsSecurityGroupDemoData.xml @@ -45,6 +45,7 @@ under the License. + diff --git a/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml b/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml index 70cd28b8b6..196acc8d0f 100644 --- a/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml +++ b/framework/webtools/data/WebtoolsSecurityPermissionSeedData.xml @@ -36,6 +36,7 @@ under the License. + @@ -60,6 +61,7 @@ under the License. + @@ -75,4 +77,5 @@ under the License. + diff --git a/framework/webtools/widget/ServiceForms.xml b/framework/webtools/widget/ServiceForms.xml index f9bf6ca86c..252eabad26 100644 --- a/framework/webtools/widget/ServiceForms.xml +++ b/framework/webtools/widget/ServiceForms.xml @@ -23,6 +23,9 @@ under the License.
+ + + @@ -43,6 +46,7 @@ under the License. +