Skip to content

Commit

Permalink
TRUNK-6203: Global properties access should be privileged
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Mar 31, 2024
1 parent 37b5a03 commit 82dea4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/org/openmrs/util/LocaleUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static Locale getDefaultLocale() {
if (defaultLocaleCache == null) {
if (Context.isSessionOpen()) {
try {
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
String locale = Context.getAdministrationService().getGlobalProperty(
OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE);

Expand All @@ -74,6 +75,9 @@ public static Locale getDefaultLocale() {
log.warn("Unable to get locale global property value. " + e.getMessage());
log.trace("Unable to get locale global property value", e);
}
finally {
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
}

// if we weren't able to load the locale from the global property,
// use the default one
Expand Down
9 changes: 7 additions & 2 deletions web/src/main/java/org/openmrs/web/filter/GZIPFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ private boolean isGZIPEnabled() {
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
String gzipEnabled = Context.getAdministrationService().getGlobalProperty(
OpenmrsConstants.GLOBAL_PROPERTY_GZIP_ENABLED, "");
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);

cachedGZipEnabledFlag = Boolean.valueOf(gzipEnabled);
return cachedGZipEnabledFlag;
}
Expand All @@ -140,13 +138,17 @@ private boolean isGZIPEnabled() {

return false;
}
finally {
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
}
}

/**
* Returns true if path matches pattern in gzip.acceptCompressedRequestsForPaths property
*/
private boolean isCompressedRequestForPathAccepted(String path) {
try {
Context.addProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
if (cachedGZipCompressedRequestForPathAccepted == null) {
cachedGZipCompressedRequestForPathAccepted = Context.getAdministrationService().getGlobalProperty(
OpenmrsConstants.GLOBAL_PROPERTY_GZIP_ACCEPT_COMPRESSED_REQUESTS_FOR_PATHS, "");
Expand All @@ -165,5 +167,8 @@ private boolean isCompressedRequestForPathAccepted(String path) {
+ OpenmrsConstants.GLOBAL_PROPERTY_GZIP_ACCEPT_COMPRESSED_REQUESTS_FOR_PATHS, e);
return false;
}
finally {
Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES);
}
}
}

0 comments on commit 82dea4e

Please sign in to comment.