Class J2DoPrivHelper

java.lang.Object
org.apache.openjpa.lib.util.J2DoPrivHelper

public abstract class J2DoPrivHelper extends Object
Helper class to obtain the Privilege(Exception)Action object to perform Java 2 doPrivilege security sensitive function call in the following methods:
  • AccessibleObject.setAccessible
  • Class.forName
  • Class.getClassLoader
  • Class.getDeclaredField
  • Class.getDeclaredFields
  • Class.getDeclaredMethod
  • Class.getDeclaredMethods
  • Class.getProtectionDomain
  • Class.getResource
  • Class.newInstance
  • ClassLoader.getParent
  • ClassLoader.getResource
  • ClassLoader.getResources
  • ClassLoader.getSystemClassLoader
  • File.deleteOnExit
  • File.delete
  • File.exists
  • File.getAbsoluteFile
  • File.getAbsolutePath
  • File.getCanonicalPath
  • File.listFiles
  • File.length
  • File.isDirectory
  • File.mkdirs
  • File.renameTo
  • File.toURL
  • FileInputStream new
  • FileOutputStream new
  • System.getProperties
  • InetAddress.getByName
  • MultiClassLoader new
  • ServerSocket new
  • Socket new
  • Socket.accept
  • System.getProperty
  • Thread.getContextClassLoader
  • Thread.setContextClassLoader
  • Thread new
  • TemporaryClassLoader new
  • URL.openStream
  • URLConnection.getContent
  • ZipFile new
  • AnnotatedElement.getAnnotations
  • AnnotatedElement.getDeclaredAnnotations
  • AnnotatedElement.isAnnotationPresent
  • jakarta.validation.Validator.validate
  • jakarta.validation.Validation.buildDefaultValidatorFactory
If these methods are used, the following sample usage patterns should be followed to ensure proper privilege is granted:
1) No security risk method call. E.g.

   private static final String SEP = J2DoPrivHelper.getLineSeparator();

2) Methods with no exception thrown. PrivilegedAction is returned from
   J2DoPrivHelper.*Action(). E.g.

   ClassLoader loader = AccessController.doPrivileged(
                            J2DoPrivHelper.getClassLoaderAction(clazz));

   ClassLoader loader = (ClassLoader) (System.getSecurityManager() == null)
                        ? clazz.getClassLoader()
                        : AccessController.doPrivileged(
                            J2DoPrivHelper.getClassLoaderAction(clazz));
3) Methods with exception thrown. PrivilegedExceptionAction is returned
   from J2DoPrivHelper.*Action(). E.g.

   try {
     method = AccessController.doPrivileged(
       J2DoPrivHelper.getDeclaredMethodAction(clazz, name, parameterType));
   } catch (PrivilegedActionException pae) {
     throw (NoSuchMethodException) pae.getException();
   }

   try {
     method = (System.getSecurityManager() == null)
       ? clazz.getDeclaredMethod(name,parameterType)
       : AccessController.doPrivileged(
           J2DoPrivHelper.getDeclaredMethodAction(
             clazz, name, parameterType));
   } catch (PrivilegedActionException pae) {
       throw (NoSuchMethodException) pae.getException()
   }
Author:
Albert Lee
  • Constructor Details

    • J2DoPrivHelper

      public J2DoPrivHelper()
  • Method Details

    • getLineSeparator

      public static String getLineSeparator()
      Return the value of the "line.separator" system property. Requires security policy: 'permission java.util.PropertyPermission "read";'
    • getPathSeparator

      public static String getPathSeparator()
      Return the value of the "path.separator" system property. Requires security policy: 'permission java.util.PropertyPermission "read";'
    • newInstance

      public static <T> T newInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException
      Return a new object for clazz.newInstance().
      Returns:
      A new instance of the provided class.
      Throws:
      IllegalAccessException
      InstantiationException
    • newDeamonThread

      public static Thread newDeamonThread(Runnable target, String name)
      Returns a new daemon Thread.
      Returns:
      Thread