aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/sun/security/action/GetPropertyAction.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/sun/security/action/GetPropertyAction.java')
-rw-r--r--src/share/classes/sun/security/action/GetPropertyAction.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/share/classes/sun/security/action/GetPropertyAction.java b/src/share/classes/sun/security/action/GetPropertyAction.java
index 24ecc91a61..59bf32486d 100644
--- a/src/share/classes/sun/security/action/GetPropertyAction.java
+++ b/src/share/classes/sun/security/action/GetPropertyAction.java
@@ -108,4 +108,27 @@ public class GetPropertyAction implements PrivilegedAction<String> {
new GetPropertyAction(theProp));
}
}
+
+ /**
+ * Convenience method to get a property without going through doPrivileged
+ * if no security manager is present. This is unsafe for inclusion in a
+ * public API but allowable here since this class is now encapsulated.
+ *
+ * Note that this method performs a privileged action using caller-provided
+ * inputs. The caller of this method should take care to ensure that the
+ * inputs are not tainted and the returned property is not made accessible
+ * to untrusted code if it contains sensitive information.
+ *
+ * @param theProp the name of the system property.
+ * @param defaultVal the default value.
+ */
+ public static String privilegedGetProperty(String theProp,
+ String defaultVal) {
+ if (System.getSecurityManager() == null) {
+ return System.getProperty(theProp, defaultVal);
+ } else {
+ return AccessController.doPrivileged(
+ new GetPropertyAction(theProp, defaultVal));
+ }
+ }
}