jdk/src/share/classes/sun/misc/SharedSecrets.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 5462 cb614e59f7f9
child 8556 d3d6e4643560
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
     2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5462
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Console;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileDescriptor;
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
    31
import java.security.CodeSigner;
5288
e91651d24b2a 6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents: 5183
diff changeset
    32
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/** A repository of "shared secrets", which are a mechanism for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    calling implementation-private methods in another package without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    using reflection. A package-private class implements a public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    interface and provides the ability to call package-private methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    within that package; the object implementing that interface is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    provided through a third package to which access is restricted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    This framework avoids the primary disadvantage of using reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    for this purpose, namely the loss of compile-time checking. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class SharedSecrets {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final Unsafe unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static JavaUtilJarAccess javaUtilJarAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static JavaLangAccess javaLangAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static JavaIOAccess javaIOAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static JavaNetAccess javaNetAccess;
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    49
    private static JavaNioAccess javaNioAccess;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
    51
    private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
    52
    private static JavaSecurityCodeSignerAccess javaSecurityCodeSignerAccess;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static JavaUtilJarAccess javaUtilJarAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (javaUtilJarAccess == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            // Ensure JarFile is initialized; we know that that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            // provides the shared secret
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            unsafe.ensureClassInitialized(JarFile.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return javaUtilJarAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        javaUtilJarAccess = access;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static void setJavaLangAccess(JavaLangAccess jla) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        javaLangAccess = jla;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static JavaLangAccess getJavaLangAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return javaLangAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static void setJavaNetAccess(JavaNetAccess jna) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        javaNetAccess = jna;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static JavaNetAccess getJavaNetAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return javaNetAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
1143
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    83
    public static void setJavaNioAccess(JavaNioAccess jna) {
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    84
        javaNioAccess = jna;
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    85
    }
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    86
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    87
    public static JavaNioAccess getJavaNioAccess() {
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    88
        if (javaNioAccess == null) {
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    89
            // Ensure java.nio.ByteOrder is initialized; we know that
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    90
            // this class initializes java.nio.Bits that provides the
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    91
            // shared secret.
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    92
            unsafe.ensureClassInitialized(java.nio.ByteOrder.class);
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    93
        }
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    94
        return javaNioAccess;
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    95
    }
645d4b930f93 6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents: 2
diff changeset
    96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static void setJavaIOAccess(JavaIOAccess jia) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        javaIOAccess = jia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static JavaIOAccess getJavaIOAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (javaIOAccess == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            unsafe.ensureClassInitialized(Console.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return javaIOAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        javaIOFileDescriptorAccess = jiofda;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (javaIOFileDescriptorAccess == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            unsafe.ensureClassInitialized(FileDescriptor.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return javaIOFileDescriptorAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   119
    public static void setJavaSecurityProtectionDomainAccess
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   120
        (JavaSecurityProtectionDomainAccess jspda) {
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   121
            javaSecurityProtectionDomainAccess = jspda;
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   122
    }
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   123
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   124
    public static JavaSecurityProtectionDomainAccess
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   125
        getJavaSecurityProtectionDomainAccess() {
5288
e91651d24b2a 6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents: 5183
diff changeset
   126
            if (javaSecurityProtectionDomainAccess == null)
e91651d24b2a 6909281: 6u19 b99(pit):Error loading first applet in browser session( both FF && IE, windows ): NPE is thrown
mullan
parents: 5183
diff changeset
   127
                unsafe.ensureClassInitialized(ProtectionDomain.class);
5183
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   128
            return javaSecurityProtectionDomainAccess;
7825d97c4cf2 6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents: 2277
diff changeset
   129
    }
5462
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   130
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   131
    public static void setJavaSecurityCodeSignerAccess
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   132
            (JavaSecurityCodeSignerAccess jscsa) {
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   133
        javaSecurityCodeSignerAccess = jscsa;
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   134
    }
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   135
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   136
    public static JavaSecurityCodeSignerAccess
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   137
            getJavaSecurityCodeSignerAccess() {
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   138
        if (javaSecurityCodeSignerAccess == null)
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   139
            unsafe.ensureClassInitialized(CodeSigner.class);
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   140
        return javaSecurityCodeSignerAccess;
cb614e59f7f9 6890876: jarsigner can add CRL info into signed jar
weijun
parents: 5288
diff changeset
   141
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}