author | chegar |
Fri, 16 Dec 2011 16:09:41 +0000 | |
changeset 11284 | 2750cfd2352c |
parent 10044 | 413c0f8ca341 |
child 11902 | a94ba35d9c4a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8556 | 2 |
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.misc; |
|
27 |
||
28 |
import java.util.jar.JarFile; |
|
29 |
import java.io.Console; |
|
30 |
import java.io.FileDescriptor; |
|
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
|
31 |
import java.security.ProtectionDomain; |
2 | 32 |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
33 |
import java.security.AccessController; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
34 |
|
2 | 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. */ |
|
43 |
||
44 |
public class SharedSecrets { |
|
45 |
private static final Unsafe unsafe = Unsafe.getUnsafe(); |
|
46 |
private static JavaUtilJarAccess javaUtilJarAccess; |
|
47 |
private static JavaLangAccess javaLangAccess; |
|
48 |
private static JavaIOAccess javaIOAccess; |
|
49 |
private static JavaNetAccess javaNetAccess; |
|
11284
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
50 |
private static JavaNetHttpCookieAccess javaNetHttpCookieAccess; |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
51 |
private static JavaNioAccess javaNioAccess; |
2 | 52 |
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
53 |
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess; |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
54 |
private static JavaSecurityAccess javaSecurityAccess; |
2 | 55 |
|
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); |
|
61 |
} |
|
62 |
return javaUtilJarAccess; |
|
63 |
} |
|
64 |
||
65 |
public static void setJavaUtilJarAccess(JavaUtilJarAccess access) { |
|
66 |
javaUtilJarAccess = access; |
|
67 |
} |
|
68 |
||
69 |
public static void setJavaLangAccess(JavaLangAccess jla) { |
|
70 |
javaLangAccess = jla; |
|
71 |
} |
|
72 |
||
73 |
public static JavaLangAccess getJavaLangAccess() { |
|
74 |
return javaLangAccess; |
|
75 |
} |
|
76 |
||
77 |
public static void setJavaNetAccess(JavaNetAccess jna) { |
|
78 |
javaNetAccess = jna; |
|
79 |
} |
|
80 |
||
81 |
public static JavaNetAccess getJavaNetAccess() { |
|
82 |
return javaNetAccess; |
|
83 |
} |
|
84 |
||
11284
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
85 |
public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) { |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
86 |
javaNetHttpCookieAccess = a; |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
87 |
} |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
88 |
|
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
89 |
public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() { |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
90 |
if (javaNetHttpCookieAccess == null) |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
91 |
unsafe.ensureClassInitialized(java.net.HttpCookie.class); |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
92 |
return javaNetHttpCookieAccess; |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
93 |
} |
2750cfd2352c
7095980: Ensure HttpURLConnection (and supporting APIs) don't expose HttpOnly cookies
chegar
parents:
10044
diff
changeset
|
94 |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
95 |
public static void setJavaNioAccess(JavaNioAccess jna) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
96 |
javaNioAccess = jna; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
97 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
98 |
|
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
99 |
public static JavaNioAccess getJavaNioAccess() { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
100 |
if (javaNioAccess == null) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
101 |
// 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
|
102 |
// 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
|
103 |
// shared secret. |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
104 |
unsafe.ensureClassInitialized(java.nio.ByteOrder.class); |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
105 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
106 |
return javaNioAccess; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
107 |
} |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
2
diff
changeset
|
108 |
|
2 | 109 |
public static void setJavaIOAccess(JavaIOAccess jia) { |
110 |
javaIOAccess = jia; |
|
111 |
} |
|
112 |
||
113 |
public static JavaIOAccess getJavaIOAccess() { |
|
114 |
if (javaIOAccess == null) { |
|
115 |
unsafe.ensureClassInitialized(Console.class); |
|
116 |
} |
|
117 |
return javaIOAccess; |
|
118 |
} |
|
119 |
||
120 |
public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { |
|
121 |
javaIOFileDescriptorAccess = jiofda; |
|
122 |
} |
|
123 |
||
124 |
public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { |
|
125 |
if (javaIOFileDescriptorAccess == null) |
|
126 |
unsafe.ensureClassInitialized(FileDescriptor.class); |
|
127 |
||
128 |
return javaIOFileDescriptorAccess; |
|
129 |
} |
|
130 |
||
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
131 |
public static void setJavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
132 |
(JavaSecurityProtectionDomainAccess jspda) { |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
133 |
javaSecurityProtectionDomainAccess = jspda; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
134 |
} |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
135 |
|
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
136 |
public static JavaSecurityProtectionDomainAccess |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
unsafe.ensureClassInitialized(ProtectionDomain.class); |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
140 |
return javaSecurityProtectionDomainAccess; |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2277
diff
changeset
|
141 |
} |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
142 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
143 |
public static void setJavaSecurityAccess(JavaSecurityAccess jsa) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
144 |
javaSecurityAccess = jsa; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
145 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
146 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
147 |
public static JavaSecurityAccess getJavaSecurityAccess() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
148 |
if (javaSecurityAccess == null) { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
149 |
unsafe.ensureClassInitialized(AccessController.class); |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
150 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
151 |
return javaSecurityAccess; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
8556
diff
changeset
|
152 |
} |
2 | 153 |
} |