Skip to content

Commit f44e5b7

Browse files
committed
TRUNK-6203: Global properties access should be privileged
1 parent a6dda61 commit f44e5b7

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

api/src/main/java/org/openmrs/module/referenceapplication/ReferenceApplicationActivator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.openmrs.scheduler.TaskDefinition;
5151
import org.openmrs.scheduler.tasks.ProcessHL7InQueueTask;
5252
import org.openmrs.ui.framework.resource.ResourceFactory;
53+
import org.openmrs.util.PrivilegeConstants;
5354

5455
/**
5556
* This class contains the logic that is run every time this module is either started or stopped.
@@ -167,7 +168,13 @@ private void setupRegistrationcoreGlobalProperties(AdministrationService adminis
167168
}
168169

169170
private void setGlobalProperty(AdministrationService administrationService, String propertyName, String propertyValue) {
170-
GlobalProperty gp = administrationService.getGlobalPropertyObject(propertyName);
171+
GlobalProperty gp;
172+
try {
173+
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
174+
gp = administrationService.getGlobalPropertyObject(propertyName);
175+
} finally {
176+
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
177+
}
171178
if (gp == null) {
172179
gp = new GlobalProperty(propertyName, propertyValue);
173180
}

omod/src/main/java/org/openmrs/module/referenceapplication/page/controller/LoginPageController.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.openmrs.ui.framework.annotation.SpringBean;
3434
import org.openmrs.ui.framework.page.PageModel;
3535
import org.openmrs.ui.framework.page.PageRequest;
36+
import org.openmrs.util.PrivilegeConstants;
3637
import org.openmrs.web.user.CurrentUsers;
3738
import org.springframework.stereotype.Controller;
3839
import org.springframework.web.bind.annotation.CookieValue;
@@ -150,10 +151,16 @@ public String get(PageModel model, UiUtils ui, PageRequest pageRequest,
150151
}
151152

152153
private boolean isLocationUserPropertyAvailable(AdministrationService administrationService) {
153-
String locationUserPropertyName = administrationService
154-
.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME);
155-
156-
return StringUtils.isNotBlank(locationUserPropertyName);
154+
try {
155+
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
156+
String locationUserPropertyName = administrationService
157+
.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME);
158+
159+
return StringUtils.isNotBlank(locationUserPropertyName);
160+
} finally {
161+
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
162+
}
163+
157164
}
158165

159166
private boolean isUrlWithinOpenmrs(PageRequest pageRequest, String redirectUrl) {
@@ -376,8 +383,14 @@ private boolean isSameUser(PageRequest pageRequest, String username) {
376383
}
377384

378385
private List<Location> getUserLocations(AdministrationService adminService, LocationService locationService) {
379-
String locationUserPropertyName = adminService
380-
.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME);
386+
String locationUserPropertyName;
387+
try {
388+
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
389+
locationUserPropertyName = adminService.getGlobalProperty(ReferenceApplicationConstants.LOCATION_USER_PROPERTY_NAME);
390+
}
391+
finally {
392+
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
393+
}
381394
List<Location> locations = new ArrayList();
382395
String locationUuids = Context.getAuthenticatedUser().getUserProperty(locationUserPropertyName);
383396
if (StringUtils.isNotBlank(locationUuids)) {

0 commit comments

Comments
 (0)