svn commit: r1589589 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/GenericDelegator.java entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1589589 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/GenericDelegator.java entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy

jacopoc
Author: jacopoc
Date: Thu Apr 24 05:19:13 2014
New Revision: 1589589

URL: http://svn.apache.org/r1589589
Log:
Fixes for a bug reported by Pierre Smits in OFBIZ-4130 (and OFBIZ-5319): a tenant user can access, via the delegator, the meta data information of other tenants; for example a tenant user with grants to use the Webtools application could view/edit the database details of all tenants.


Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
    ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1589589&r1=1589588&r2=1589589&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Thu Apr 24 05:19:13 2014
@@ -261,6 +261,12 @@ public class GenericDelegator implements
 
     private void initializeOneGenericHelper(String groupName) {
         GenericHelperInfo helperInfo = this.getGroupHelperInfo(groupName);
+        if (helperInfo == null) {
+            if (Debug.infoOn()) {
+                Debug.logInfo("Delegator \"" + delegatorFullName + "\" NOT initializing helper for entity group \"" + groupName + "\" because the group is not associated to this delegator.", module);
+            }
+            return;
+        }
         String helperBaseName = helperInfo.getHelperBaseName();
 
         if (Debug.infoOn()) {
@@ -476,9 +482,7 @@ public class GenericDelegator implements
         GenericHelperInfo helperInfo = new GenericHelperInfo(entityGroupName, helperBaseName);
 
         // to avoid infinite recursion, and to behave right for shared org.ofbiz.tenant entities, do nothing with the tenantId if the entityGroupName=org.ofbiz.tenant
-        if (UtilValidate.isNotEmpty(this.delegatorTenantId) && !"org.ofbiz.tenant".equals(entityGroupName)) {
-            helperInfo.setTenantId(this.delegatorTenantId);
-
+        if (UtilValidate.isNotEmpty(this.delegatorTenantId)) {
             // get the JDBC parameters from the DB for the entityGroupName and tenantId
             try {
                 // NOTE: instead of caching the GenericHelpInfo object do a cached query here and create a new object each time, will avoid issues when the database data changes during run time
@@ -486,15 +490,12 @@ public class GenericDelegator implements
                 Delegator baseDelegator = DelegatorFactory.getDelegator(this.delegatorBaseName);
                 GenericValue tenantDataSource = baseDelegator.findOne("TenantDataSource", true, "tenantId", this.delegatorTenantId, "entityGroupName", entityGroupName);
                 if (tenantDataSource != null) {
+                    helperInfo.setTenantId(this.delegatorTenantId);
                     helperInfo.setOverrideJdbcUri(tenantDataSource.getString("jdbcUri"));
                     helperInfo.setOverrideUsername(tenantDataSource.getString("jdbcUsername"));
                     helperInfo.setOverridePassword(tenantDataSource.getString("jdbcPassword"));
                 } else {
-                    /* don't log this, happens too many times:
-                    if (Debug.warningOn()) {
-                        Debug.logWarning("Could not find TenantDataSource information for tenantId=[" + this.delegatorTenantId + "] and entityGroupName=[" + entityGroupName + "] in delegator [" + this.delegatorFullName + "]; will be defaulting to settings for the base delegator name [" + this.delegatorBaseName + "]", module);
-                    }
-                     */
+                    return null;
                 }
             } catch (GenericEntityException e) {
                 // don't complain about this too much, just log the error if there is one
@@ -538,7 +539,7 @@ public class GenericDelegator implements
         if (helperInfo != null) {
             return GenericHelperFactory.getHelper(helperInfo);
         } else {
-            throw new GenericEntityException("There is no datasource (Helper) configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; was trying to find datesource (helper) for entity [" + entityName + "]");
+            throw new GenericEntityException("There is no datasource (Helper) configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; was trying to find datasource (helper) for entity [" + entityName + "]");
         }
     }
 

Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=1589589&r1=1589588&r2=1589589&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java (original)
+++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java Thu Apr 24 05:19:13 2014
@@ -273,6 +273,12 @@ public class EntityDataLoadContainer imp
         String delegatorNameToUse = overrideDelegator != null ? overrideDelegator : delegatorName;
         String groupNameToUse = overrideGroup != null ? overrideGroup : entityGroupName;
         Delegator delegator = DelegatorFactory.getDelegator(delegatorNameToUse);
+        Delegator baseDelegator = null;
+        if (delegator.getDelegatorTenantId() != null) {
+            baseDelegator = DelegatorFactory.getDelegator(delegator.getDelegatorBaseName());
+        } else {
+            baseDelegator = delegator;
+        }
         if (delegator == null) {
             throw new ContainerException("Invalid delegator name!");
         }
@@ -295,11 +301,11 @@ public class EntityDataLoadContainer imp
         Collection<ComponentConfig> allComponents = ComponentConfig.getAllComponents();
         for (ComponentConfig config : allComponents) {
             //Debug.logInfo("- Stored component : " + config.getComponentName(), module);
-            GenericValue componentEntry = delegator.makeValue("Component");
+            GenericValue componentEntry = baseDelegator.makeValue("Component");
             componentEntry.set("componentName", config.getComponentName());
             componentEntry.set("rootLocation", config.getRootLocation());
             try {
-                GenericValue componentCheck = delegator.findOne("Component", UtilMisc.toMap("componentName", config.getComponentName()), false);
+                GenericValue componentCheck = baseDelegator.findOne("Component", UtilMisc.toMap("componentName", config.getComponentName()), false);
                 if (UtilValidate.isEmpty(componentCheck)) {
                     componentEntry.create();
                 } else {
@@ -316,7 +322,7 @@ public class EntityDataLoadContainer imp
                 List<EntityExpr> exprs = new ArrayList<EntityExpr>();
                 exprs.add(EntityCondition.makeCondition("rootLocation", EntityOperator.NOT_LIKE, "%hot-deploy%"));
                 EntityCondition cond = EntityCondition.makeCondition(exprs);
-                List<GenericValue> components = delegator.findList("Component", cond , null, UtilMisc.toList("lastUpdatedStamp"), null, false);
+                List<GenericValue> components = baseDelegator.findList("Component", cond , null, UtilMisc.toList("lastUpdatedStamp"), null, false);
                 Debug.logInfo("===== Begin load specify components", module);
                 if (UtilValidate.isEmpty(this.component)) {
                     for (GenericValue component : components) {
@@ -324,14 +330,14 @@ public class EntityDataLoadContainer imp
                         //Debug.logInfo("- loaded default component : " + component.getString("componentName"), module);
                     }
                     Debug.logInfo("- Loaded components by default : " + components.size() + " components", module);
-                    List<GenericValue> tenantComponents = delegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId()), UtilMisc.toList("sequenceNum"), false);
+                    List<GenericValue> tenantComponents = baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId()), UtilMisc.toList("sequenceNum"), false);
                     for (GenericValue tenantComponent : tenantComponents) {
                         loadComponents.add(tenantComponent.getString("componentName"));
                         //Debug.logInfo("- loaded component by tenantId : " + tenantComponent.getString("tenantId") +", component : " + tenantComponent.getString("componentName"), module);
                     }
                     Debug.logInfo("- Loaded components by tenantId : " + delegator.getDelegatorTenantId() + ", " + tenantComponents.size() + " components", module);
                 } else {
-                    List<GenericValue> tenantComponents = delegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId(), "componentName", this.component),
+                    List<GenericValue> tenantComponents = baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId(), "componentName", this.component),
                             UtilMisc.toList("sequenceNum"), false);
                     for (GenericValue tenantComponent : tenantComponents) {
                         loadComponents.add(tenantComponent.getString("componentName"));

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy?rev=1589589&r1=1589588&r2=1589589&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/entity/EntityMaint.groovy Thu Apr 24 05:19:13 2014
@@ -19,14 +19,24 @@
 import javolution.util.FastList;
 
 import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.Delegator
+import org.ofbiz.entity.DelegatorFactory
+import org.ofbiz.entity.GenericValue
+import org.ofbiz.entity.condition.EntityComparisonOperator
+import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelGroupReader;
 import org.ofbiz.entity.model.ModelReader;
 import org.ofbiz.entity.model.ModelEntity;
-import org.ofbiz.entity.model.ModelViewEntity;
+import org.ofbiz.entity.model.ModelViewEntity
+import org.ofbiz.entity.util.EntityUtil;
 
-mgr = delegator.getModelGroupReader();
-entityGroups = mgr.getGroupNames(delegator.getDelegatorBaseName()).iterator();
+if (delegator.getDelegatorTenantId() == null) {
+    mgr = delegator.getModelGroupReader();
+    entityGroups = mgr.getGroupNames(delegator.getDelegatorName()).toArray().sort();
+} else {
+    Delegator baseDelegator = DelegatorFactory.getDelegator(delegator.getDelegatorBaseName());
+    entityGroups = EntityUtil.getFieldListFromEntityList(baseDelegator.findList("TenantDataSource", EntityCondition.makeCondition("tenantId", EntityComparisonOperator.EQUALS, delegator.getDelegatorTenantId()), ['entityGroupName'] as Set, ['entityGroupName'], null, false), 'entityGroupName', false);
+}
 
 filterByGroupName = parameters.filterByGroupName;
 context.filterByGroupName = filterByGroupName;
@@ -42,14 +52,17 @@ int kIdx = 0;
 entitiesList = [];
 entities.each { entityName ->
     entity = reader.getModelEntity(entityName);
+    entityGroupName = delegator.getEntityGroupName(entity.getEntityName());
 
-    if (filterByGroupName && !filterByGroupName.equals(delegator.getEntityGroupName(entity.getEntityName()))) {
+    if (!entityGroups.contains(entityGroupName)) {
+        return;
+    }
+    if (filterByGroupName && !filterByGroupName.equals(entityGroupName)) {
         return;
     }
     if (filterByEntityName && !((String)entity.getEntityName()).toUpperCase().contains(filterByEntityName.toUpperCase())) {
         return;
     }
-
     viewEntity = "N";
     if (entity instanceof ModelViewEntity) {
         viewEntity = "Y";