You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mr...@apache.org on 2026/10/26 11:51:51 UTC

(ofbiz-framework) branch release24.09 updated (0a899c8bc0 -> 038d6575ba)

This is an automated email from the ASF dual-hosted git repository.

mridulpathak pushed a change to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


    from 0a899c8bc0 Run internal balanceInventoryItems and createCostComponent calls as the system user
     new 65af260f96 Added: permission checks to order CustRequest/Quote/Requirement services
     new 038d6575ba Fix internal callers and a test fixture broken by the new createRequirement permission check

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/ofbiz/manufacturing/mrp/ProposedOrder.java    |  7 ++++++-
 .../testdef/data/ManufacturingTestsData.xml              |  1 +
 .../order/minilang/request/CustRequestServices.xml       |  4 ++++
 applications/order/servicedef/services.xml               |  3 +++
 applications/order/servicedef/services_quote.xml         | 12 ++++++++++++
 applications/order/servicedef/services_request.xml       | 12 ++++++++++++
 applications/order/servicedef/services_requirement.xml   |  3 +++
 .../java/org/apache/ofbiz/order/order/OrderServices.java | 16 ++++++++++++++++
 applications/workeffort/servicedef/secas.xml             |  4 ++--
 9 files changed, 59 insertions(+), 3 deletions(-)


(ofbiz-framework) 02/02: Fix internal callers and a test fixture broken by the new createRequirement permission check

Posted by mr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 038d6575bab603d431726553c725ed21e9a6fa33
Author: Mridul Pathak <mr...@gmail.com>
AuthorDate: Mon Oct 26 13:47:00 2026 +0530

    Fix internal callers and a test fixture broken by the new createRequirement permission check
    
    - ProductionRunTests#testCreateProductionRunForRequirement calls createRequirement as TestSupplyAdmin, whose SUPPLYADMIN test security group lacked ORDERMGR_CREATE; added it, matching the group's stated scope of executing requirement-based manufacturing tasks
    - ProposedOrder.java (MRP) now runs its internal createRequirement call as the system user, since auto-generating a requirement during an MRP run is a trusted side effect, not an action on behalf of a specific user
    - workeffort/servicedef/secas.xml: createWorkEffortRequestItem and createWorkRequirementFulfillment now run their createCustRequestItem/createRequirement ECA actions as the system user
---
 .../java/org/apache/ofbiz/manufacturing/mrp/ProposedOrder.java     | 7 ++++++-
 applications/manufacturing/testdef/data/ManufacturingTestsData.xml | 1 +
 applications/workeffort/servicedef/secas.xml                       | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/ProposedOrder.java b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/ProposedOrder.java
index bf1ceab2ca..69fe65e23a 100644
--- a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/ProposedOrder.java
+++ b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/ProposedOrder.java
@@ -33,6 +33,7 @@ import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.entity.Delegator;
 import org.apache.ofbiz.entity.GenericEntityException;
 import org.apache.ofbiz.entity.GenericValue;
+import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.entity.util.EntityUtil;
 import org.apache.ofbiz.manufacturing.bom.BOMNode;
 import org.apache.ofbiz.manufacturing.bom.BOMTree;
@@ -265,6 +266,10 @@ public class ProposedOrder {
             parameters.put("description", "Automatically generated by MRP");
         }
         try {
+            // createRequirement requires ORDERMGR_CREATE; run as the "system" user since this is a trusted side effect of
+            // an already-permitted MRP run, not an action taken on behalf of the caller
+            parameters.put("userLogin", EntityQuery.use(delegator).from("UserLogin")
+                    .where("userLoginId", "system").cache().queryOne());
             Map<String, Object> result = dispatcher.runSync("createRequirement", parameters);
             if (ServiceUtil.isError(result)) {
                 String errorMessage = ServiceUtil.getErrorMessage(result);
@@ -272,7 +277,7 @@ public class ProposedOrder {
                 return null;
             }
             return (String) result.get("requirementId");
-        } catch (GenericServiceException e) {
+        } catch (GenericServiceException | GenericEntityException e) {
             Debug.logError(e, "Error : createRequirement with parameters = " + parameters + "--" + e.getMessage(), MODULE);
             return null;
         }
diff --git a/applications/manufacturing/testdef/data/ManufacturingTestsData.xml b/applications/manufacturing/testdef/data/ManufacturingTestsData.xml
index 97be258d37..1ae3dfd68e 100644
--- a/applications/manufacturing/testdef/data/ManufacturingTestsData.xml
+++ b/applications/manufacturing/testdef/data/ManufacturingTestsData.xml
@@ -41,6 +41,7 @@ under the License.
     <SecurityGroupPermission fromDate="2001-05-13 12:00:00.0" groupId="SUPPLYADMIN" permissionId="WORKEFFORTMGR_CREATE"/>
     <SecurityGroupPermission fromDate="2001-05-13 12:00:00.0" groupId="SUPPLYADMIN" permissionId="WORKEFFORTMGR_UPDATE"/>
     <SecurityGroupPermission fromDate="2001-05-13 12:00:00.0" groupId="SUPPLYADMIN" permissionId="ACCOUNTING_CREATE"/>
+    <SecurityGroupPermission fromDate="2001-05-13 12:00:00.0" groupId="SUPPLYADMIN" permissionId="ORDERMGR_CREATE"/>
     <Party partyId="TestSupplyAdmin" partyTypeId="PERSON"/>
     <Person partyId="TestSupplyAdmin" firstName="Supply" lastName="Admin"/>
     <UserLogin partyId="TestSupplyAdmin" userLoginId="TestSupplyAdmin"/>
diff --git a/applications/workeffort/servicedef/secas.xml b/applications/workeffort/servicedef/secas.xml
index 80e08c3fcb..b9a2281267 100644
--- a/applications/workeffort/servicedef/secas.xml
+++ b/applications/workeffort/servicedef/secas.xml
@@ -52,7 +52,7 @@ under the License.
     </eca>
     <eca service="createWorkEffortRequestItem" event="invoke">
         <condition field-name="custRequestItemExists" operator="is-empty"/>
-        <action service="createCustRequestItem" mode="sync"/>
+        <action service="createCustRequestItem" mode="sync" run-as-user="system"/>
     </eca>
     <eca service="createWorkEffortQuote" event="invoke">
         <condition field-name="quoteId" operator="is-empty"/>
@@ -60,7 +60,7 @@ under the License.
     </eca>
     <eca service="createWorkRequirementFulfillment" event="invoke">
         <condition field-name="requirementId" operator="is-empty"/>
-        <action service="createRequirement" mode="sync"/>
+        <action service="createRequirement" mode="sync" run-as-user="system"/>
     </eca>
     <eca service="createShoppingListWorkEffort" event="invoke">
         <condition field-name="shoppingListId" operator="is-empty"/>


(ofbiz-framework) 01/02: Added: permission checks to order CustRequest/Quote/Requirement services

Posted by mr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 65af260f966614103482bf3d494822fc87fb352a
Author: Mridul Pathak <mr...@gmail.com>
AuthorDate: Fri Oct 23 11:48:48 2026 +0530

    Added: permission checks to order CustRequest/Quote/Requirement services
    
    Several order-component services had no permission check at all, letting any authenticated user create, modify, or delete customer-request, quote, requirement, and order-shipgroup data regardless of their assigned permissions.
    
    - createCustRequestItem, createCustRequestParty, updateCustRequest, updateCustRequestItem, expireCustRequestContent now require ORDERMGR_CRQ via a new custRequestChildPermissionCheck, since the existing custRequestPermissionCheck's self-service escape hatch is unsafe to reuse for updates to an existing record
    - createQuoteTerm, updateQuoteTerm, deleteQuoteTerm, createQuoteNote, createRequirement, updateAllocationPlanItems now require ORDERMGR via the native required-permissions/check-permission declaration, matching the sibling createRequirementRole convention
    - setGiftMessage, setShippingInstructions now reuse the existing OrderServices.hasPermission(orderId, ...) order-update check
---
 .../order/minilang/request/CustRequestServices.xml       |  4 ++++
 applications/order/servicedef/services.xml               |  3 +++
 applications/order/servicedef/services_quote.xml         | 12 ++++++++++++
 applications/order/servicedef/services_request.xml       | 12 ++++++++++++
 applications/order/servicedef/services_requirement.xml   |  3 +++
 .../java/org/apache/ofbiz/order/order/OrderServices.java | 16 ++++++++++++++++
 6 files changed, 50 insertions(+)

diff --git a/applications/order/minilang/request/CustRequestServices.xml b/applications/order/minilang/request/CustRequestServices.xml
index 8f8bf0e2e5..ac6b16d3e5 100644
--- a/applications/order/minilang/request/CustRequestServices.xml
+++ b/applications/order/minilang/request/CustRequestServices.xml
@@ -47,6 +47,10 @@ under the License.
         </if>
         <field-to-result field="hasPermission"/>
     </simple-method>
+    <simple-method method-name="custRequestChildPermissionCheck" short-description="Unconditional ORDERMGR_CRQ permission check for updating an existing customer request or its child records">
+        <set field="primaryPermission" value="ORDERMGR_CRQ"/>
+        <call-simple-method method-name="genericBasePermissionCheck" xml-resource="component://common/minilang/permission/CommonPermissionServices.xml"/>
+    </simple-method>
 
     <simple-method method-name="createCustRequest" short-description="Create Customer Request">
         <make-value entity-name="CustRequest" value-field="newEntity"/>
diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml
index 5096204b31..8c31c07c9c 100644
--- a/applications/order/servicedef/services.xml
+++ b/applications/order/servicedef/services.xml
@@ -1738,6 +1738,9 @@ under the License.
     <service name="updateAllocationPlanItems" engine="java" auth="true"
              location="org.apache.ofbiz.order.order.OrderServices" invoke="updateAllocationPlanItems">
         <description>Update Allocation Plan Items</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_UPDATE"/>
+        </required-permissions>
         <attribute name="planId" type="String" mode="IN"/>
         <attribute name="orderIdMap" type="Map" mode="IN" string-map-prefix="oim_"/>
         <attribute name="orderItemSeqIdMap" type="Map" mode="IN" string-map-prefix="oisim_"/>
diff --git a/applications/order/servicedef/services_quote.xml b/applications/order/servicedef/services_quote.xml
index eb893431bb..07d053b817 100644
--- a/applications/order/servicedef/services_quote.xml
+++ b/applications/order/servicedef/services_quote.xml
@@ -185,6 +185,9 @@ under the License.
         <description>
             Create a new Quate term.
         </description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_CREATE"/>
+        </required-permissions>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true"/>
         <override name="quoteItemSeqId" type="String" mode="IN" default-value="_NA_"/>
@@ -193,6 +196,9 @@ under the License.
         <description>
             Edit the Quate term.
         </description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_UPDATE"/>
+        </required-permissions>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true"/>
     </service>
@@ -200,6 +206,9 @@ under the License.
         <description>
             delete the Quate term.
         </description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_DELETE"/>
+        </required-permissions>
         <auto-attributes mode="IN" include="pk" optional="false"/>
     </service>
     <!-- Specialized Quote services -->
@@ -330,6 +339,9 @@ under the License.
     <service name="createQuoteNote" engine="groovy"
             location="component://order/src/main/groovy/org/apache/ofbiz/order/quote/QuoteServicesScript.groovy" invoke="createQuoteNote" auth="true">
         <description>Create a note item and associate with a quote</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_CREATE"/>
+        </required-permissions>
         <attribute name="quoteId" type="String" mode="IN"/>
         <attribute name="noteInfo" type="String" mode="IN" allow-html="safe">
             <type-validate>
diff --git a/applications/order/servicedef/services_request.xml b/applications/order/servicedef/services_request.xml
index 9982545586..b46cecfb9a 100644
--- a/applications/order/servicedef/services_request.xml
+++ b/applications/order/servicedef/services_request.xml
@@ -34,6 +34,13 @@ under the License.
         <implements service="permissionInterface"/>
         <attribute name="fromPartyId" type="String" mode="IN" optional="true"/>
     </service>
+    <service name="custRequestChildPermissionCheck" engine="simple"
+            location="component://order/minilang/request/CustRequestServices.xml" invoke="custRequestChildPermissionCheck">
+        <description>Unconditional ORDERMGR_CRQ permission check, for updating an existing customer request or its child
+            records (item, party, content) where the caller-supplied fromPartyId (if any) can't be trusted to reflect
+            the actual owner of the existing record, unlike custRequestPermissionCheck's use on create</description>
+        <implements service="permissionInterface"/>
+    </service>
     <service name="createCustRequest" engine="simple" default-entity-name="CustRequest"
             location="component://order/minilang/request/CustRequestServices.xml" invoke="createCustRequest" auth="true">
         <description>Create a custRequest record and optionally create a custRequest item.</description>
@@ -49,6 +56,7 @@ under the License.
     <service name="updateCustRequest" engine="simple" default-entity-name="CustRequest"
             location="component://order/minilang/request/CustRequestServices.xml" invoke="updateCustRequest" auth="true">
         <description>Update a custRequest record</description>
+        <permission-service service-name="custRequestChildPermissionCheck" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <attribute name="oldStatusId" type="String" mode="OUT"/>
@@ -84,6 +92,7 @@ under the License.
     <!-- CustRequestItem services -->
     <service name="createCustRequestItem" engine="entity-auto" default-entity-name="CustRequestItem" invoke="create" auth="true">
         <description>Create a CustRequestItem record</description>
+        <permission-service service-name="custRequestChildPermissionCheck" main-action="CREATE"/>
         <auto-attributes include="pk" mode="INOUT" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <override name="custRequestItemSeqId" optional="true"/>
@@ -93,6 +102,7 @@ under the License.
     </service>
     <service name="updateCustRequestItem" engine="entity-auto" default-entity-name="CustRequestItem" invoke="update" auth="true">
         <description>Update a CustRequestItem record</description>
+        <permission-service service-name="custRequestChildPermissionCheck" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
         <override name="story" allow-html="safe"/>
@@ -110,6 +120,7 @@ under the License.
     <!-- CustRequestParty services -->
     <service name="createCustRequestParty" engine="entity-auto" default-entity-name="CustRequestParty" invoke="create" auth="true">
         <description>Create a CustRequestParty record</description>
+        <permission-service service-name="custRequestChildPermissionCheck" main-action="CREATE"/>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true"/>
         <override name="fromDate" mode="IN" type="Timestamp" optional="true" default-value="${date:nowTimestamp()}"/>
@@ -229,6 +240,7 @@ under the License.
     </service>
     <service name="expireCustRequestContent" engine="entity-auto" invoke="expire" default-entity-name="CustRequestContent" auth="true">
         <description>Expire a Customer Request Content</description>
+        <permission-service service-name="custRequestChildPermissionCheck" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
     </service>
diff --git a/applications/order/servicedef/services_requirement.xml b/applications/order/servicedef/services_requirement.xml
index 5af1e62795..0980bdb89f 100644
--- a/applications/order/servicedef/services_requirement.xml
+++ b/applications/order/servicedef/services_requirement.xml
@@ -37,6 +37,9 @@ under the License.
     <service name="createRequirement" engine="simple"
             location="component://order/minilang/requirement/RequirementServices.xml" invoke="createRequirement">
         <description>Create a new requirement</description>
+        <required-permissions join-type="AND">
+            <check-permission permission="ORDERMGR" action="_CREATE"/>
+        </required-permissions>
         <implements service="requirementInterface"/>
         <attribute name="requirementTypeId" type="String" mode="IN" optional="false"/>
         <attribute name="custRequestId" type="String" mode="IN" optional="true"/>
diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
index 11cf7609bb..8041dfc9ce 100644
--- a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
+++ b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
@@ -6486,9 +6486,17 @@ public class OrderServices {
 
     public static Map<String, Object> setShippingInstructions(DispatchContext dctx, Map<String, ? extends Object> context) {
         Delegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
         String orderId = (String) context.get("orderId");
         String shipGroupSeqId = (String) context.get("shipGroupSeqId");
         String shippingInstructions = (String) context.get("shippingInstructions");
+        Security security = dctx.getSecurity();
+
+        if (!OrderServices.hasPermission(orderId, userLogin, "UPDATE", security, delegator)) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR,
+                    "OrderYouDoNotHavePermissionToChangeThisOrdersStatus", locale));
+        }
         try {
             GenericValue orderItemShipGroup = EntityQuery.use(delegator).from("OrderItemShipGroup").where("orderId", orderId, "shipGroupSeqId",
                     shipGroupSeqId).queryFirst();
@@ -6502,9 +6510,17 @@ public class OrderServices {
 
     public static Map<String, Object> setGiftMessage(DispatchContext dctx, Map<String, ? extends Object> context) {
         Delegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
         String orderId = (String) context.get("orderId");
         String shipGroupSeqId = (String) context.get("shipGroupSeqId");
         String giftMessage = (String) context.get("giftMessage");
+        Security security = dctx.getSecurity();
+
+        if (!OrderServices.hasPermission(orderId, userLogin, "UPDATE", security, delegator)) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR,
+                    "OrderYouDoNotHavePermissionToChangeThisOrdersStatus", locale));
+        }
         try {
             GenericValue orderItemShipGroup = EntityQuery.use(delegator).from("OrderItemShipGroup").where("orderId", orderId, "shipGroupSeqId",
                     shipGroupSeqId).queryFirst();