SharedSecrets.java revision 4102
0N/A/*
1879N/A * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1472N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
1879N/A
1879N/Apackage sun.misc;
1879N/A
1879N/Aimport java.util.jar.JarFile;
1879N/Aimport java.io.Console;
1879N/Aimport java.io.FileDescriptor;
1879N/Aimport java.security.ProtectionDomain;
1879N/Aimport javax.security.auth.kerberos.KeyTab;
1879N/A
1879N/Aimport java.security.AccessController;
1879N/A
1879N/A/** A repository of "shared secrets", which are a mechanism for
1879N/A calling implementation-private methods in another package without
1879N/A using reflection. A package-private class implements a public
1879N/A interface and provides the ability to call package-private methods
0N/A within that package; the object implementing that interface is
0N/A provided through a third package to which access is restricted.
0N/A This framework avoids the primary disadvantage of using reflection
0N/A for this purpose, namely the loss of compile-time checking. */
0N/A
0N/Apublic class SharedSecrets {
0N/A private static final Unsafe unsafe = Unsafe.getUnsafe();
0N/A private static JavaUtilJarAccess javaUtilJarAccess;
0N/A private static JavaLangAccess javaLangAccess;
0N/A private static JavaIOAccess javaIOAccess;
0N/A private static JavaNetAccess javaNetAccess;
0N/A private static JavaNioAccess javaNioAccess;
0N/A private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
0N/A private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
0N/A private static JavaSecurityAccess javaSecurityAccess;
0N/A private static JavaxSecurityAuthKerberosAccess javaxSecurityAuthKerberosAccess;
0N/A
0N/A public static JavaUtilJarAccess javaUtilJarAccess() {
0N/A if (javaUtilJarAccess == null) {
0N/A // Ensure JarFile is initialized; we know that that class
0N/A // provides the shared secret
0N/A unsafe.ensureClassInitialized(JarFile.class);
0N/A }
0N/A return javaUtilJarAccess;
0N/A }
0N/A
0N/A public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
0N/A javaUtilJarAccess = access;
0N/A }
0N/A
0N/A public static void setJavaLangAccess(JavaLangAccess jla) {
0N/A javaLangAccess = jla;
0N/A }
0N/A
0N/A public static JavaLangAccess getJavaLangAccess() {
0N/A return javaLangAccess;
0N/A }
0N/A
0N/A public static void setJavaNetAccess(JavaNetAccess jna) {
0N/A javaNetAccess = jna;
0N/A }
0N/A
0N/A public static JavaNetAccess getJavaNetAccess() {
0N/A return javaNetAccess;
0N/A }
0N/A
0N/A public static void setJavaNioAccess(JavaNioAccess jna) {
0N/A javaNioAccess = jna;
0N/A }
0N/A
0N/A public static JavaNioAccess getJavaNioAccess() {
0N/A if (javaNioAccess == null) {
0N/A // Ensure java.nio.ByteOrder is initialized; we know that
0N/A // this class initializes java.nio.Bits that provides the
0N/A // shared secret.
0N/A unsafe.ensureClassInitialized(java.nio.ByteOrder.class);
0N/A }
0N/A return javaNioAccess;
0N/A }
0N/A
0N/A public static void setJavaIOAccess(JavaIOAccess jia) {
0N/A javaIOAccess = jia;
0N/A }
0N/A
0N/A public static JavaIOAccess getJavaIOAccess() {
0N/A if (javaIOAccess == null) {
0N/A unsafe.ensureClassInitialized(Console.class);
0N/A }
0N/A return javaIOAccess;
0N/A }
0N/A
0N/A public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) {
0N/A javaIOFileDescriptorAccess = jiofda;
0N/A }
0N/A
0N/A public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() {
0N/A if (javaIOFileDescriptorAccess == null)
0N/A unsafe.ensureClassInitialized(FileDescriptor.class);
0N/A
0N/A return javaIOFileDescriptorAccess;
0N/A }
0N/A
0N/A public static void setJavaSecurityProtectionDomainAccess
0N/A (JavaSecurityProtectionDomainAccess jspda) {
0N/A javaSecurityProtectionDomainAccess = jspda;
0N/A }
0N/A
0N/A public static JavaSecurityProtectionDomainAccess
0N/A getJavaSecurityProtectionDomainAccess() {
0N/A if (javaSecurityProtectionDomainAccess == null)
0N/A unsafe.ensureClassInitialized(ProtectionDomain.class);
0N/A return javaSecurityProtectionDomainAccess;
0N/A }
0N/A
0N/A public static void setJavaSecurityAccess(JavaSecurityAccess jsa) {
0N/A javaSecurityAccess = jsa;
0N/A }
0N/A
0N/A public static JavaSecurityAccess getJavaSecurityAccess() {
0N/A if (javaSecurityAccess == null) {
0N/A unsafe.ensureClassInitialized(AccessController.class);
0N/A }
0N/A return javaSecurityAccess;
0N/A }
0N/A
0N/A public static void setJavaxSecurityAuthKerberosAccess
0N/A (JavaxSecurityAuthKerberosAccess jsaka) {
0N/A javaxSecurityAuthKerberosAccess = jsaka;
0N/A }
0N/A
0N/A public static JavaxSecurityAuthKerberosAccess
0N/A getJavaxSecurityAuthKerberosAccess() {
0N/A if (javaxSecurityAuthKerberosAccess == null)
0N/A unsafe.ensureClassInitialized(KeyTab.class);
0N/A return javaxSecurityAuthKerberosAccess;
0N/A }
0N/A}
0N/A