Package org.jruby.util
Class SafePropertyAccessor
java.lang.Object
org.jruby.util.SafePropertyAccessor
Utility class to safely access system properties in security-sensitive
environments.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
getBoolean
(String property) An extension overBoolean.getBoolean
method.static boolean
getBoolean
(String property, boolean defValue) An extension overBoolean.getBoolean
method.getenv()
An extension overSystem.getenv
method.static String
An extension overSystem.getenv
method.static int
An extension overSystem.getProperty
method that additionally produces an int value.static int
An extension overSystem.getProperty
method that additionally produces an int value.static String
getProperty
(String property) An extension overSystem.getProperty
method.static String
getProperty
(String property, String defValue) An extension overSystem.getProperty
method.static boolean
isSecurityProtected
(String property) Returnstrue
if the access to the system property is restricted (i.e., when System.getProperty() throws SecurityException).
-
Constructor Details
-
SafePropertyAccessor
public SafePropertyAccessor()
-
-
Method Details
-
getBoolean
An extension overBoolean.getBoolean
method. Returns true if and only if the system property named by the argument exists and is equal to the string "true". If there is no property with the specified name, or if the specified name is empty or null, or if the access to the property is restricted, then false is returned.- Parameters:
property
- The system property name.- Returns:
- The boolean value of the system property.
-
getBoolean
An extension overBoolean.getBoolean
method. Handles security restrictions, and provides default value in case when access to the property is restricted, of when the property does not exist.- Parameters:
property
- The system property name.defValue
- The default value.- Returns:
- The boolean value of the system property, or the default value.
-
getProperty
An extension overSystem.getProperty
method. Handles security restrictions, and returnsnull
if the access to the property is restricted.- Parameters:
property
- The system property name.- Returns:
- The value of the system property, or the default value.
-
getProperty
An extension overSystem.getProperty
method. Handles security restrictions, and returns the default value if the access to the property is restricted.- Parameters:
property
- The system property name.defValue
- The default value.- Returns:
- The value of the system property, or the default value.
-
getInt
An extension overSystem.getProperty
method that additionally produces an int value. Handles security restrictions, and returns0
if the access to the property is restricted.- Parameters:
property
- The system property name.- Returns:
- The value of the system property, or the default value.
-
getInt
An extension overSystem.getProperty
method that additionally produces an int value. Handles security restrictions, and returns the default value if the access to the property is restricted.- Parameters:
property
- The system property name.defValue
- The default value.- Returns:
- The value of the system property, or the default value.
-
isSecurityProtected
Returnstrue
if the access to the system property is restricted (i.e., when System.getProperty() throws SecurityException).- Parameters:
property
- The system property name.- Returns:
true
if the access is restricted,false
otherwise.
-
getenv
An extension overSystem.getenv
method. Handles security restrictions, and returnsnull
if the access to the environment variable is restricted.- Parameters:
name
- The environment variable name.- Returns:
- The value of the environment variable, or null.
-
getenv
An extension overSystem.getenv
method. Handles security restrictions, and returnsnull
if the access to the environment map is restricted.- Returns:
- The map of the environment variables, or null.
-