From f13b921077d83dbc983d3273368be74498d73114 Mon Sep 17 00:00:00 2001 From: Wikum Weerakutti Date: Tue, 30 Jul 2024 10:25:49 +0530 Subject: [PATCH 1/2] TRUNK-6203: Global properties access should be privileged --- .../service/AddressHierarchyServiceImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java index 34cfe83..0d87229 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java @@ -17,6 +17,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -705,7 +706,15 @@ else if (level.getParent() == null){ synchronized public void initializeFullAddressCache() { // generally, this global property should be set to true; it just allows cache load to be disabled to speed startup - if (Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP).equalsIgnoreCase("true")) { + String globalProperty = ""; + try { + Context.addProxyPrivilege("Get Global Properties"); + globalProperty = Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP); + } finally { + Context.removeProxyPrivilege("Get Global Properties"); + } + + if (BooleanUtils.toBoolean(globalProperty)) { // only initialize if necessary (and if we have entries) if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache)) From e39a4e2ac85713d8006671107ab12d1b3e872391 Mon Sep 17 00:00:00 2001 From: Wikum Weerakutti Date: Tue, 30 Jul 2024 15:46:38 +0530 Subject: [PATCH 2/2] TRUNK-6203: Global properties access should be privileged --- .../scheduler/InitializeFullAddressCacheTask.java | 7 ++++++- .../service/AddressHierarchyServiceImpl.java | 11 +---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/scheduler/InitializeFullAddressCacheTask.java b/api/src/main/java/org/openmrs/module/addresshierarchy/scheduler/InitializeFullAddressCacheTask.java index b78397e..aa0962a 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/scheduler/InitializeFullAddressCacheTask.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/scheduler/InitializeFullAddressCacheTask.java @@ -11,6 +11,11 @@ public class InitializeFullAddressCacheTask extends AbstractAddressHierarchyTask @Override public void execute() { - Context.getService(AddressHierarchyService.class).initializeFullAddressCache(); + try { + Context.addProxyPrivilege("Get Global Properties"); + Context.getService(AddressHierarchyService.class).initializeFullAddressCache(); + } finally { + Context.removeProxyPrivilege("Get Global Properties"); + } } } diff --git a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java index 0d87229..34cfe83 100644 --- a/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/addresshierarchy/service/AddressHierarchyServiceImpl.java @@ -17,7 +17,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -706,15 +705,7 @@ else if (level.getParent() == null){ synchronized public void initializeFullAddressCache() { // generally, this global property should be set to true; it just allows cache load to be disabled to speed startup - String globalProperty = ""; - try { - Context.addProxyPrivilege("Get Global Properties"); - globalProperty = Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP); - } finally { - Context.removeProxyPrivilege("Get Global Properties"); - } - - if (BooleanUtils.toBoolean(globalProperty)) { + if (Context.getAdministrationService().getGlobalProperty(AddressHierarchyConstants.GLOBAL_PROP_INITIALIZE_ADDRESS_HIERARCHY_CACHE_ON_STARTUP).equalsIgnoreCase("true")) { // only initialize if necessary (and if we have entries) if ((this.fullAddressCacheInitialized == false || MapUtils.isEmpty(this.fullAddressCache))