public class PrivilegedAccessHelper
extends java.lang.Object
Constructor and Description |
---|
PrivilegedAccessHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Class |
getClassForName(java.lang.String className)
Execute a java Class.forName().
|
static java.lang.Class |
getClassForName(java.lang.String className,
boolean initialize,
java.lang.ClassLoader loader)
Execute a java Class.forName() wrap the call in a doPrivileged block if necessary.
|
static java.lang.ClassLoader |
getClassLoaderForClass(java.lang.Class clazz)
Gets the class loader for a given class.
|
static java.lang.reflect.Constructor |
getConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
Get the public constructor for the given class and given arguments and wrap it in doPrivileged if
necessary.
|
static java.lang.ClassLoader |
getContextClassLoader(java.lang.Thread thread)
Get the context ClassLoader for a thread.
|
static java.lang.reflect.Constructor |
getDeclaredConstructorFor(java.lang.Class javaClass,
java.lang.Class[] args,
boolean shouldSetAccessible)
Get the constructor for the given class and given arguments (regardless of whether it is public
or private))and wrap it in doPrivileged if necessary.
|
static java.lang.reflect.Field |
getDeclaredField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
Get a field actually declared in a class and wrap the call in doPrivileged if necessary.
|
static java.lang.reflect.Field[] |
getDeclaredFields(java.lang.Class clazz)
Get the list of fields in a class.
|
static java.lang.reflect.Method |
getDeclaredMethod(java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes)
Return a method on a given class with the given method name and parameter
types.
|
static java.lang.reflect.Method[] |
getDeclaredMethods(java.lang.Class clazz)
Get the list of methods in a class.
|
static java.lang.reflect.Field |
getField(java.lang.Class javaClass,
java.lang.String fieldName,
boolean shouldSetAccessible)
Get a field in a class or its superclasses and wrap the call in doPrivileged if necessary.
|
static java.lang.reflect.Field[] |
getFields(java.lang.Class clazz)
Get the list of public fields in a class.
|
static java.lang.Class |
getFieldType(java.lang.reflect.Field field)
Get the return type for a given method.
|
static java.lang.String |
getLineSeparator()
Get the line separator character.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class javaClass,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes,
boolean shouldSetAccessible)
Get a method declared in the given class.
|
static java.lang.Class[] |
getMethodParameterTypes(java.lang.reflect.Method method)
Get the list of parameter types for a given method.
|
static java.lang.Class |
getMethodReturnType(java.lang.reflect.Method method)
Get the return type for a given method.
|
static java.lang.reflect.Method[] |
getMethods(java.lang.Class clazz)
Get the list of methods in a class.
|
static java.lang.reflect.Method |
getPublicMethod(java.lang.Class javaClass,
java.lang.String methodName,
java.lang.Class[] methodParameterTypes,
boolean shouldSetAccessible)
Get a public method declared in the given class.
|
static java.lang.String |
getSystemProperty(java.lang.String key)
INTERNAL:
Get the
System property indicated by the specified key . |
static java.lang.String |
getSystemProperty(java.lang.String key,
java.lang.String def)
INTERNAL:
Get the
System property indicated by the specified key . |
static boolean |
getSystemPropertyBoolean(java.lang.String key,
boolean def)
INTERNAL:
Get boolean value of the
System property indicated by the specified key . |
static java.lang.Object |
getValueFromField(java.lang.reflect.Field field,
java.lang.Object object)
Get the value of the given field in the given object.
|
static java.lang.Object |
invokeConstructor(java.lang.reflect.Constructor constructor,
java.lang.Object[] args)
Construct an object with the given Constructor and the given array of arguments.
|
static java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object object)
Invoke the givenMethod on a givenObject.
|
static java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object object,
java.lang.Object[] parameters)
Invoke the givenMethod on a givenObject using the array of parameters given.
|
static java.lang.Object |
newInstanceFromClass(java.lang.Class clazz)
Get a new instance of a class using the default constructor.
|
static java.lang.ClassLoader |
privilegedGetClassLoaderForClass(java.lang.Class clazz)
Gets the class loader for a given class.
|
static void |
setDefaultUseDoPrivilegedValue(boolean def)
INTERNAL
It will be used to set default value of property "eclipselink.security.usedoprivileged"
if not passed as system property.
|
static void |
setValueInField(java.lang.reflect.Field field,
java.lang.Object object,
java.lang.Object value)
Set the value of a given field in the given object with the value given.
|
static boolean |
shouldUsePrivilegedAccess()
This method checks to see if calls should be made to doPrivileged.
|
public static void setDefaultUseDoPrivilegedValue(boolean def)
public static java.lang.Class getClassForName(java.lang.String className) throws java.lang.ClassNotFoundException
className
- java.lang.ClassNotFoundException
public static java.lang.Class getClassForName(java.lang.String className, boolean initialize, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public static java.lang.ClassLoader getClassLoaderForClass(java.lang.Class clazz)
public static java.lang.ClassLoader privilegedGetClassLoaderForClass(java.lang.Class clazz)
public static java.lang.reflect.Constructor getConstructorFor(java.lang.Class javaClass, java.lang.Class[] args, boolean shouldSetAccessible) throws java.lang.NoSuchMethodException
javaClass
- The class to get the Constructor forargs
- An array of classes representing the argument types of the constructorshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchMethodException
public static java.lang.ClassLoader getContextClassLoader(java.lang.Thread thread)
public static java.lang.reflect.Constructor getDeclaredConstructorFor(java.lang.Class javaClass, java.lang.Class[] args, boolean shouldSetAccessible) throws java.lang.NoSuchMethodException
javaClass
- The class to get the Constructor forargs
- An array of classes representing the argument types of the constructorshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchMethodException
public static java.lang.reflect.Field getField(java.lang.Class javaClass, java.lang.String fieldName, boolean shouldSetAccessible) throws java.lang.NoSuchFieldException
javaClass
- The class to get the field fromfieldName
- The name of the fieldshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchFieldException
public static java.lang.reflect.Field getDeclaredField(java.lang.Class javaClass, java.lang.String fieldName, boolean shouldSetAccessible) throws java.lang.NoSuchFieldException
javaClass
- The class to get the field fromfieldName
- The name of the fieldshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchFieldException
public static java.lang.reflect.Field[] getDeclaredFields(java.lang.Class clazz)
clazz
- the class to get the fields from.public static java.lang.reflect.Field[] getFields(java.lang.Class clazz)
clazz
- the class to get the fields from.public static java.lang.reflect.Method getDeclaredMethod(java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] methodParameterTypes) throws java.lang.NoSuchMethodException
method
- the class to get the method frommethodName
- the name of the method to getmethodParameters
- a list of classes representing the classes of the
parameters of the method.java.lang.NoSuchMethodException
public static java.lang.reflect.Method getMethod(java.lang.Class javaClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes, boolean shouldSetAccessible) throws java.lang.NoSuchMethodException
javaClass
- The class to get the method frommethodName
- The name of the method to getmethodParameterTypes
- A list of classes representing the classes of the parameters of the mthodshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchMethodException
public static java.lang.reflect.Method getPublicMethod(java.lang.Class javaClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes, boolean shouldSetAccessible) throws java.lang.NoSuchMethodException
javaClass
- The class to get the method frommethodName
- The name of the method to getmethodParameterTypes
- A list of classes representing the classes of the parameters of the methodshouldSetAccessible
- whether or not to call the setAccessible APIjava.lang.NoSuchMethodException
public static java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class clazz)
clazz
- the class to get the methods from.public static java.lang.Class getFieldType(java.lang.reflect.Field field)
field
- public static final java.lang.String getSystemProperty(java.lang.String key)
System
property indicated by the specified key
.key
- The name of the System
property.String
value of the system property or null
if property identified by key
does not exist.public static final java.lang.String getSystemProperty(java.lang.String key, java.lang.String def)
System
property indicated by the specified key
.key
- The name of the System
property.String
value of the system property or def
if property identified by key
does not exist.public static final boolean getSystemPropertyBoolean(java.lang.String key, boolean def)
System
property indicated by the specified key
.key
- The name of the System
property.def
- The default value.true
if the property value is "true"
(case insensitive)
or the property is not defined and def
is true
;
false
otherwise.public static java.lang.String getLineSeparator()
public static java.lang.Class[] getMethodParameterTypes(java.lang.reflect.Method method)
method
- The method to get the parameter types ofpublic static java.lang.Class getMethodReturnType(java.lang.reflect.Method method)
method
- public static java.lang.reflect.Method[] getMethods(java.lang.Class clazz)
clazz
- the class to get the methods from.public static java.lang.Object getValueFromField(java.lang.reflect.Field field, java.lang.Object object) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public static java.lang.Object invokeConstructor(java.lang.reflect.Constructor constructor, java.lang.Object[] args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
public static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object object) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object[] parameters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
public static java.lang.Object newInstanceFromClass(java.lang.Class clazz) throws java.lang.IllegalAccessException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.InstantiationException
public static void setValueInField(java.lang.reflect.Field field, java.lang.Object object, java.lang.Object value) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public static boolean shouldUsePrivilegedAccess()
Note: it is not possible to run EclipseLink using doPrivileged blocks when there is no SecurityManager enabled.
EclipseLink 2.6.3, "build v20160428-59c81c5" API Reference