History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/misc/SharedSecrets.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/misc/SharedSecrets.java+156−0
@@ -0,0 +1,156 @@
1/*
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.
4 *
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.
10 *
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).
16 *
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.
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
26package sun.misc;
27
28import java.util.jar.JarFile;
29import java.io.Console;
30import java.io.FileDescriptor;
31import java.security.ProtectionDomain;
32import javax.security.auth.kerberos.KeyTab;
33
34import java.security.AccessController;
35
36/** A repository of "shared secrets", which are a mechanism for
37 calling implementation-private methods in another package without
38 using reflection. A package-private class implements a public
39 interface and provides the ability to call package-private methods
40 within that package; the object implementing that interface is
41 provided through a third package to which access is restricted.
42 This framework avoids the primary disadvantage of using reflection
43 for this purpose, namely the loss of compile-time checking. */
44
45public class SharedSecrets {
46 private static final Unsafe unsafe = Unsafe.getUnsafe();
47 private static JavaUtilJarAccess javaUtilJarAccess;
48 private static JavaLangAccess javaLangAccess;
49 private static JavaIOAccess javaIOAccess;
50 private static JavaNetAccess javaNetAccess;
51 private static JavaNioAccess javaNioAccess;
52 private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
53 private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
54 private static JavaSecurityAccess javaSecurityAccess;
55 private static JavaxSecurityAuthKerberosAccess javaxSecurityAuthKerberosAccess;
56
57 public static JavaUtilJarAccess javaUtilJarAccess() {
58 if (javaUtilJarAccess == null) {
59 // Ensure JarFile is initialized; we know that that class
60 // provides the shared secret
61 unsafe.ensureClassInitialized(JarFile.class);
62 }
63 return javaUtilJarAccess;
64 }
65
66 public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
67 javaUtilJarAccess = access;
68 }
69
70 public static void setJavaLangAccess(JavaLangAccess jla) {
71 javaLangAccess = jla;
72 }
73
74 public static JavaLangAccess getJavaLangAccess() {
75 return javaLangAccess;
76 }
77
78 public static void setJavaNetAccess(JavaNetAccess jna) {
79 javaNetAccess = jna;
80 }
81
82 public static JavaNetAccess getJavaNetAccess() {
83 return javaNetAccess;
84 }
85
86 public static void setJavaNioAccess(JavaNioAccess jna) {
87 javaNioAccess = jna;
88 }
89
90 public static JavaNioAccess getJavaNioAccess() {
91 if (javaNioAccess == null) {
92 // Ensure java.nio.ByteOrder is initialized; we know that
93 // this class initializes java.nio.Bits that provides the
94 // shared secret.
95 unsafe.ensureClassInitialized(java.nio.ByteOrder.class);
96 }
97 return javaNioAccess;
98 }
99
100 public static void setJavaIOAccess(JavaIOAccess jia) {
101 javaIOAccess = jia;
102 }
103
104 public static JavaIOAccess getJavaIOAccess() {
105 if (javaIOAccess == null) {
106 unsafe.ensureClassInitialized(Console.class);
107 }
108 return javaIOAccess;
109 }
110
111 public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) {
112 javaIOFileDescriptorAccess = jiofda;
113 }
114
115 public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() {
116 if (javaIOFileDescriptorAccess == null)
117 unsafe.ensureClassInitialized(FileDescriptor.class);
118
119 return javaIOFileDescriptorAccess;
120 }
121
122 public static void setJavaSecurityProtectionDomainAccess
123 (JavaSecurityProtectionDomainAccess jspda) {
124 javaSecurityProtectionDomainAccess = jspda;
125 }
126
127 public static JavaSecurityProtectionDomainAccess
128 getJavaSecurityProtectionDomainAccess() {
129 if (javaSecurityProtectionDomainAccess == null)
130 unsafe.ensureClassInitialized(ProtectionDomain.class);
131 return javaSecurityProtectionDomainAccess;
132 }
133
134 public static void setJavaSecurityAccess(JavaSecurityAccess jsa) {
135 javaSecurityAccess = jsa;
136 }
137
138 public static JavaSecurityAccess getJavaSecurityAccess() {
139 if (javaSecurityAccess == null) {
140 unsafe.ensureClassInitialized(AccessController.class);
141 }
142 return javaSecurityAccess;
143 }
144
145 public static void setJavaxSecurityAuthKerberosAccess
146 (JavaxSecurityAuthKerberosAccess jsaka) {
147 javaxSecurityAuthKerberosAccess = jsaka;
148 }
149
150 public static JavaxSecurityAuthKerberosAccess
151 getJavaxSecurityAuthKerberosAccess() {
152 if (javaxSecurityAuthKerberosAccess == null)
153 unsafe.ensureClassInitialized(KeyTab.class);
154 return javaxSecurityAuthKerberosAccess;
155 }
156}