2
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
28
import java.util.jar.JarFile;
29
import java.io.Console;
30
import java.security.ProtectionDomain;
31
import javax.security.auth.kerberos.KeyTab;
33
import java.security.AccessController;
35
/** A repository of "shared secrets", which are a mechanism for
36
calling implementation-private methods in another package without
37
using reflection. A package-private class implements a public
38
interface and provides the ability to call package-private methods
39
within that package; the object implementing that interface is
40
provided through a third package to which access is restricted.
41
This framework avoids the primary disadvantage of using reflection
42
for this purpose, namely the loss of compile-time checking. */
44
public class SharedSecrets {
45
private static final Unsafe unsafe = Unsafe.getUnsafe();
46
private static JavaUtilJarAccess javaUtilJarAccess;
47
private static JavaLangAccess javaLangAccess = LangHelper.getJavaLangAccess();
48
private static JavaIOAccess javaIOAccess;
49
private static JavaNetAccess javaNetAccess;
50
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
51
private static JavaNioAccess javaNioAccess;
52
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
53
private static JavaSecurityAccess javaSecurityAccess;
54
private static JavaxSecurityAuthKerberosAccess javaxSecurityAuthKerberosAccess;
56
public static JavaUtilJarAccess javaUtilJarAccess() {
57
if (javaUtilJarAccess == null) {
58
// Ensure JarFile is initialized; we know that that class
59
// provides the shared secret
60
unsafe.ensureClassInitialized(JarFile.class);
62
return javaUtilJarAccess;
65
public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
66
javaUtilJarAccess = access;
69
public static JavaLangAccess getJavaLangAccess() {
70
return javaLangAccess;
73
public static void setJavaNetAccess(JavaNetAccess jna) {
77
public static JavaNetAccess getJavaNetAccess() {
81
public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) {
82
javaNetHttpCookieAccess = a;
85
public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() {
86
if (javaNetHttpCookieAccess == null)
87
unsafe.ensureClassInitialized(java.net.HttpCookie.class);
88
return javaNetHttpCookieAccess;
91
public static void setJavaNioAccess(JavaNioAccess jna) {
95
public static JavaNioAccess getJavaNioAccess() {
96
if (javaNioAccess == null) {
97
// [IKVM] OpenJDK initializes java.nio.ByteOrder here, but that doesn't work
98
java.nio.ByteOrder.nativeOrder();
100
return javaNioAccess;
103
public static void setJavaIOAccess(JavaIOAccess jia) {
107
public static JavaIOAccess getJavaIOAccess() {
108
if (javaIOAccess == null) {
109
unsafe.ensureClassInitialized(Console.class);
114
public static void setJavaSecurityProtectionDomainAccess
115
(JavaSecurityProtectionDomainAccess jspda) {
116
javaSecurityProtectionDomainAccess = jspda;
119
public static JavaSecurityProtectionDomainAccess
120
getJavaSecurityProtectionDomainAccess() {
121
if (javaSecurityProtectionDomainAccess == null)
122
unsafe.ensureClassInitialized(ProtectionDomain.class);
123
return javaSecurityProtectionDomainAccess;
126
public static void setJavaSecurityAccess(JavaSecurityAccess jsa) {
127
javaSecurityAccess = jsa;
130
public static JavaSecurityAccess getJavaSecurityAccess() {
131
if (javaSecurityAccess == null) {
132
// [IKVM] OpenJDK initializes AccessController here, but that's a bug
133
unsafe.ensureClassInitialized(ProtectionDomain.class);
135
return javaSecurityAccess;
138
public static void setJavaxSecurityAuthKerberosAccess
139
(JavaxSecurityAuthKerberosAccess jsaka) {
140
javaxSecurityAuthKerberosAccess = jsaka;
143
public static JavaxSecurityAuthKerberosAccess
144
getJavaxSecurityAuthKerberosAccess() {
145
if (javaxSecurityAuthKerberosAccess == null)
146
unsafe.ensureClassInitialized(KeyTab.class);
147
return javaxSecurityAuthKerberosAccess;