Package io.cui.tools.lang
Class SecuritySupport
- java.lang.Object
-
- io.cui.tools.lang.SecuritySupport
-
public final class SecuritySupport extends Object
Helper class providing some convenience method for interacting withSecurityManagerrelated stuff. In essence, it usesAccessController.doPrivileged(PrivilegedAction)for its method in case aSecurityManageris set.- Author:
- Oliver Wolff
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,String>accessSystemEnv()static PropertiesaccessSystemProperties()static Optional<String>accessSystemProperty(String propertyName)static Optional<ClassLoader>getContextClassLoader()static <T> Constructor<? extends T>getDeclaredConstructor(Class<T> clazz, Class<?>... paramTypes)static voidsetAccessible(AccessibleObject object, boolean accessible)
-
-
-
Method Detail
-
getContextClassLoader
public static Optional<ClassLoader> getContextClassLoader()
- Returns:
- the context-classloader if obtainable,
Optional.empty()otherwise
-
setAccessible
public static void setAccessible(AccessibleObject object, boolean accessible)
- Parameters:
object- to be set accessibleaccessible- value
-
accessSystemProperty
public static Optional<String> accessSystemProperty(String propertyName)
- Parameters:
propertyName- If is null or empty the method will returnOptional.empty()- Returns:
- an
Optionalon the requested property
-
accessSystemProperties
public static Properties accessSystemProperties()
- Returns:
- the
Propertiesderived bySystem.getProperties(). If this can not be achieved it returns an emptyPropertiesobject.
-
accessSystemEnv
public static Map<String,String> accessSystemEnv()
- Returns:
- the map derived by
System.getenv(). If this can not be achieved it returns an empty map.
-
getDeclaredConstructor
public static <T> Constructor<? extends T> getDeclaredConstructor(Class<T> clazz, Class<?>... paramTypes) throws NoSuchMethodException
- Type Parameters:
T-- Parameters:
clazz- The type of the objectparamTypes- to be used for identifying the constructor- Returns:
- the found constructor.
- Throws:
NoSuchMethodException- to be thrown, if there is no corresponding constructorIllegalStateException- for cases where thePrivilegedActionfails but is not aNoSuchMethodException
-
-