< prev index next >

src/java.base/share/classes/jdk/internal/access/SharedSecrets.java

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.access;
  27 
  28 import javax.crypto.SealedObject;
  29 import java.io.ObjectInputFilter;
  30 import java.lang.module.ModuleDescriptor;
  31 import java.util.ResourceBundle;
  32 import java.util.jar.JarFile;
  33 import java.io.Console;
  34 import java.io.FileDescriptor;
  35 import java.io.FilePermission;
  36 import java.io.ObjectInputStream;
  37 import java.io.RandomAccessFile;
  38 import java.security.ProtectionDomain;
  39 import java.security.Signature;
  40 import jdk.internal.misc.Unsafe;
  41 
  42 /** A repository of "shared secrets", which are a mechanism for
  43     calling implementation-private methods in another package without
  44     using reflection. A package-private class implements a public
  45     interface and provides the ability to call package-private methods
  46     within that package; the object implementing that interface is
  47     provided through a third package to which access is restricted.
  48     This framework avoids the primary disadvantage of using reflection
  49     for this purpose, namely the loss of compile-time checking. */
  50 
  51 public class SharedSecrets {
  52     private static final Unsafe unsafe = Unsafe.getUnsafe();
  53     private static JavaUtilJarAccess javaUtilJarAccess;
  54     private static JavaLangAccess javaLangAccess;
  55     private static JavaLangModuleAccess javaLangModuleAccess;
  56     private static JavaLangInvokeAccess javaLangInvokeAccess;
  57     private static JavaLangRefAccess javaLangRefAccess;
  58     private static JavaIOAccess javaIOAccess;
  59     private static JavaNetInetAddressAccess javaNetInetAddressAccess;
  60     private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
  61     private static JavaNetSocketAccess javaNetSocketAccess;
  62     private static JavaNetUriAccess javaNetUriAccess;
  63     private static JavaNetURLAccess javaNetURLAccess;
  64     private static JavaNetURLClassLoaderAccess javaNetURLClassLoaderAccess;
  65     private static JavaNioAccess javaNioAccess;
  66     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
  67     private static JavaIOFilePermissionAccess javaIOFilePermissionAccess;
  68     private static JavaSecurityAccess javaSecurityAccess;
  69     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
  70     private static JavaUtilResourceBundleAccess javaUtilResourceBundleAccess;
  71     private static JavaAWTAccess javaAWTAccess;
  72     private static JavaAWTFontAccess javaAWTFontAccess;
  73     private static JavaBeansAccess javaBeansAccess;
  74     private static JavaObjectInputStreamAccess javaObjectInputStreamAccess;
  75     private static JavaObjectInputFilterAccess javaObjectInputFilterAccess;
  76     private static JavaIORandomAccessFileAccess javaIORandomAccessFileAccess;
  77     private static JavaSecuritySignatureAccess javaSecuritySignatureAccess;
  78     private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
  79 
  80     public static JavaUtilJarAccess javaUtilJarAccess() {
  81         if (javaUtilJarAccess == null) {
  82             // Ensure JarFile is initialized; we know that this class
  83             // provides the shared secret
  84             unsafe.ensureClassInitialized(JarFile.class);
  85         }
  86         return javaUtilJarAccess;
  87     }
  88 
  89     public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
  90         javaUtilJarAccess = access;
  91     }
  92 
  93     public static void setJavaLangAccess(JavaLangAccess jla) {
  94         javaLangAccess = jla;
  95     }
  96 
  97     public static JavaLangAccess getJavaLangAccess() {


 310     public static JavaObjectInputFilterAccess getJavaObjectInputFilterAccess() {
 311         if (javaObjectInputFilterAccess == null) {
 312             unsafe.ensureClassInitialized(ObjectInputFilter.Config.class);
 313         }
 314         return javaObjectInputFilterAccess;
 315     }
 316 
 317     public static void setJavaObjectInputFilterAccess(JavaObjectInputFilterAccess access) {
 318         javaObjectInputFilterAccess = access;
 319     }
 320 
 321     public static void setJavaIORandomAccessFileAccess(JavaIORandomAccessFileAccess jirafa) {
 322         javaIORandomAccessFileAccess = jirafa;
 323     }
 324 
 325     public static JavaIORandomAccessFileAccess getJavaIORandomAccessFileAccess() {
 326         if (javaIORandomAccessFileAccess == null) {
 327             unsafe.ensureClassInitialized(RandomAccessFile.class);
 328         }
 329         return javaIORandomAccessFileAccess;
 330     }
 331 
 332     public static void setJavaSecuritySignatureAccess(JavaSecuritySignatureAccess jssa) {
 333         javaSecuritySignatureAccess = jssa;
 334     }
 335 
 336     public static JavaSecuritySignatureAccess getJavaSecuritySignatureAccess() {
 337         if (javaSecuritySignatureAccess == null) {
 338             unsafe.ensureClassInitialized(Signature.class);
 339         }
 340         return javaSecuritySignatureAccess;
 341     }
 342 
 343     public static void setJavaxCryptoSealedObjectAccess(JavaxCryptoSealedObjectAccess jcsoa) {
 344         javaxCryptoSealedObjectAccess = jcsoa;
 345     }
 346 
 347     public static JavaxCryptoSealedObjectAccess getJavaxCryptoSealedObjectAccess() {
 348         if (javaxCryptoSealedObjectAccess == null) {
 349             unsafe.ensureClassInitialized(SealedObject.class);
 350         }
 351         return javaxCryptoSealedObjectAccess;
 352     }
 353 }


  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.internal.access;
  27 
  28 import javax.crypto.SealedObject;
  29 import java.io.ObjectInputFilter;
  30 import java.lang.module.ModuleDescriptor;
  31 import java.util.ResourceBundle;
  32 import java.util.jar.JarFile;
  33 import java.io.Console;
  34 import java.io.FileDescriptor;
  35 import java.io.FilePermission;
  36 import java.io.ObjectInputStream;
  37 import java.io.RandomAccessFile;
  38 import java.security.ProtectionDomain;

  39 import jdk.internal.misc.Unsafe;
  40 
  41 /** A repository of "shared secrets", which are a mechanism for
  42     calling implementation-private methods in another package without
  43     using reflection. A package-private class implements a public
  44     interface and provides the ability to call package-private methods
  45     within that package; the object implementing that interface is
  46     provided through a third package to which access is restricted.
  47     This framework avoids the primary disadvantage of using reflection
  48     for this purpose, namely the loss of compile-time checking. */
  49 
  50 public class SharedSecrets {
  51     private static final Unsafe unsafe = Unsafe.getUnsafe();
  52     private static JavaUtilJarAccess javaUtilJarAccess;
  53     private static JavaLangAccess javaLangAccess;
  54     private static JavaLangModuleAccess javaLangModuleAccess;
  55     private static JavaLangInvokeAccess javaLangInvokeAccess;
  56     private static JavaLangRefAccess javaLangRefAccess;
  57     private static JavaIOAccess javaIOAccess;
  58     private static JavaNetInetAddressAccess javaNetInetAddressAccess;
  59     private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
  60     private static JavaNetSocketAccess javaNetSocketAccess;
  61     private static JavaNetUriAccess javaNetUriAccess;
  62     private static JavaNetURLAccess javaNetURLAccess;
  63     private static JavaNetURLClassLoaderAccess javaNetURLClassLoaderAccess;
  64     private static JavaNioAccess javaNioAccess;
  65     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
  66     private static JavaIOFilePermissionAccess javaIOFilePermissionAccess;
  67     private static JavaSecurityAccess javaSecurityAccess;
  68     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
  69     private static JavaUtilResourceBundleAccess javaUtilResourceBundleAccess;
  70     private static JavaAWTAccess javaAWTAccess;
  71     private static JavaAWTFontAccess javaAWTFontAccess;
  72     private static JavaBeansAccess javaBeansAccess;
  73     private static JavaObjectInputStreamAccess javaObjectInputStreamAccess;
  74     private static JavaObjectInputFilterAccess javaObjectInputFilterAccess;
  75     private static JavaIORandomAccessFileAccess javaIORandomAccessFileAccess;

  76     private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
  77 
  78     public static JavaUtilJarAccess javaUtilJarAccess() {
  79         if (javaUtilJarAccess == null) {
  80             // Ensure JarFile is initialized; we know that this class
  81             // provides the shared secret
  82             unsafe.ensureClassInitialized(JarFile.class);
  83         }
  84         return javaUtilJarAccess;
  85     }
  86 
  87     public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
  88         javaUtilJarAccess = access;
  89     }
  90 
  91     public static void setJavaLangAccess(JavaLangAccess jla) {
  92         javaLangAccess = jla;
  93     }
  94 
  95     public static JavaLangAccess getJavaLangAccess() {


 308     public static JavaObjectInputFilterAccess getJavaObjectInputFilterAccess() {
 309         if (javaObjectInputFilterAccess == null) {
 310             unsafe.ensureClassInitialized(ObjectInputFilter.Config.class);
 311         }
 312         return javaObjectInputFilterAccess;
 313     }
 314 
 315     public static void setJavaObjectInputFilterAccess(JavaObjectInputFilterAccess access) {
 316         javaObjectInputFilterAccess = access;
 317     }
 318 
 319     public static void setJavaIORandomAccessFileAccess(JavaIORandomAccessFileAccess jirafa) {
 320         javaIORandomAccessFileAccess = jirafa;
 321     }
 322 
 323     public static JavaIORandomAccessFileAccess getJavaIORandomAccessFileAccess() {
 324         if (javaIORandomAccessFileAccess == null) {
 325             unsafe.ensureClassInitialized(RandomAccessFile.class);
 326         }
 327         return javaIORandomAccessFileAccess;











 328     }
 329 
 330     public static void setJavaxCryptoSealedObjectAccess(JavaxCryptoSealedObjectAccess jcsoa) {
 331         javaxCryptoSealedObjectAccess = jcsoa;
 332     }
 333 
 334     public static JavaxCryptoSealedObjectAccess getJavaxCryptoSealedObjectAccess() {
 335         if (javaxCryptoSealedObjectAccess == null) {
 336             unsafe.ensureClassInitialized(SealedObject.class);
 337         }
 338         return javaxCryptoSealedObjectAccess;
 339     }
 340 }
< prev index next >