author | coleenp |
Wed, 30 Aug 2017 19:18:22 -0400 | |
changeset 47098 | e704f55561c3 |
parent 45434 | 4582657c7260 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
29027
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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 java.security; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
30 |
|
2 | 31 |
import sun.security.util.Debug; |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
32 |
import sun.security.util.FilePermCompat; |
2 | 33 |
import sun.security.util.SecurityConstants; |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
34 |
|
2 | 35 |
|
36 |
/** |
|
37 |
* An AccessControlContext is used to make system resource access decisions |
|
38 |
* based on the context it encapsulates. |
|
39 |
* |
|
40 |
* <p>More specifically, it encapsulates a context and |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
41 |
* has a single method, {@code checkPermission}, |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
42 |
* that is equivalent to the {@code checkPermission} method |
2 | 43 |
* in the AccessController class, with one difference: The AccessControlContext |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
44 |
* {@code checkPermission} method makes access decisions based on the |
2 | 45 |
* context it encapsulates, |
46 |
* rather than that of the current execution thread. |
|
47 |
* |
|
48 |
* <p>Thus, the purpose of AccessControlContext is for those situations where |
|
49 |
* a security check that should be made within a given context |
|
50 |
* actually needs to be done from within a |
|
51 |
* <i>different</i> context (for example, from within a worker thread). |
|
52 |
* |
|
53 |
* <p> An AccessControlContext is created by calling the |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
54 |
* {@code AccessController.getContext} method. |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
55 |
* The {@code getContext} method takes a "snapshot" |
2 | 56 |
* of the current calling context, and places |
57 |
* it in an AccessControlContext object, which it returns. A sample call is |
|
58 |
* the following: |
|
59 |
* |
|
60 |
* <pre> |
|
61 |
* AccessControlContext acc = AccessController.getContext() |
|
62 |
* </pre> |
|
63 |
* |
|
64 |
* <p> |
|
65 |
* Code within a different context can subsequently call the |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
66 |
* {@code checkPermission} method on the |
2 | 67 |
* previously-saved AccessControlContext object. A sample call is the |
68 |
* following: |
|
69 |
* |
|
70 |
* <pre> |
|
71 |
* acc.checkPermission(permission) |
|
72 |
* </pre> |
|
73 |
* |
|
74 |
* @see AccessController |
|
75 |
* |
|
76 |
* @author Roland Schemers |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
41377
diff
changeset
|
77 |
* @since 1.2 |
2 | 78 |
*/ |
79 |
||
80 |
public final class AccessControlContext { |
|
81 |
||
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
82 |
private ProtectionDomain[] context; |
18222 | 83 |
// isPrivileged and isAuthorized are referenced by the VM - do not remove |
84 |
// or change their names |
|
2 | 85 |
private boolean isPrivileged; |
18222 | 86 |
private boolean isAuthorized = false; |
2 | 87 |
|
88 |
// Note: This field is directly used by the virtual machine |
|
89 |
// native codes. Don't touch it. |
|
90 |
private AccessControlContext privilegedContext; |
|
91 |
||
92 |
private DomainCombiner combiner = null; |
|
93 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
94 |
// limited privilege scope |
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
95 |
private Permission[] permissions; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
96 |
private AccessControlContext parent; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
97 |
private boolean isWrapped; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
98 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
99 |
// is constrained by limited privilege scope? |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
100 |
private boolean isLimited; |
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
101 |
private ProtectionDomain[] limitedContext; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
102 |
|
2 | 103 |
private static boolean debugInit = false; |
104 |
private static Debug debug = null; |
|
105 |
||
106 |
static Debug getDebug() |
|
107 |
{ |
|
108 |
if (debugInit) |
|
109 |
return debug; |
|
110 |
else { |
|
111 |
if (Policy.isSet()) { |
|
112 |
debug = Debug.getInstance("access"); |
|
113 |
debugInit = true; |
|
114 |
} |
|
115 |
return debug; |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
/** |
|
476
b23646c026ed
6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
97
diff
changeset
|
120 |
* Create an AccessControlContext with the given array of ProtectionDomains. |
2 | 121 |
* Context must not be null. Duplicate domains will be removed from the |
122 |
* context. |
|
123 |
* |
|
124 |
* @param context the ProtectionDomains associated with this context. |
|
125 |
* The non-duplicate domains are copied from the array. Subsequent |
|
126 |
* changes to the array will not affect this AccessControlContext. |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
127 |
* @throws NullPointerException if {@code context} is {@code null} |
2 | 128 |
*/ |
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
129 |
public AccessControlContext(ProtectionDomain[] context) |
2 | 130 |
{ |
131 |
if (context.length == 0) { |
|
132 |
this.context = null; |
|
133 |
} else if (context.length == 1) { |
|
134 |
if (context[0] != null) { |
|
135 |
this.context = context.clone(); |
|
136 |
} else { |
|
137 |
this.context = null; |
|
138 |
} |
|
139 |
} else { |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
140 |
List<ProtectionDomain> v = new ArrayList<>(context.length); |
2 | 141 |
for (int i =0; i< context.length; i++) { |
142 |
if ((context[i] != null) && (!v.contains(context[i]))) |
|
143 |
v.add(context[i]); |
|
144 |
} |
|
476
b23646c026ed
6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
97
diff
changeset
|
145 |
if (!v.isEmpty()) { |
b23646c026ed
6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
97
diff
changeset
|
146 |
this.context = new ProtectionDomain[v.size()]; |
b23646c026ed
6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
97
diff
changeset
|
147 |
this.context = v.toArray(this.context); |
b23646c026ed
6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
97
diff
changeset
|
148 |
} |
2 | 149 |
} |
150 |
} |
|
151 |
||
152 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
153 |
* Create a new {@code AccessControlContext} with the given |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
154 |
* {@code AccessControlContext} and {@code DomainCombiner}. |
2 | 155 |
* This constructor associates the provided |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
156 |
* {@code DomainCombiner} with the provided |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
157 |
* {@code AccessControlContext}. |
2 | 158 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
159 |
* @param acc the {@code AccessControlContext} associated |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
160 |
* with the provided {@code DomainCombiner}. |
2 | 161 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
162 |
* @param combiner the {@code DomainCombiner} to be associated |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
163 |
* with the provided {@code AccessControlContext}. |
2 | 164 |
* |
165 |
* @exception NullPointerException if the provided |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
166 |
* {@code context} is {@code null}. |
2 | 167 |
* |
168 |
* @exception SecurityException if a security manager is installed and the |
|
169 |
* caller does not have the "createAccessControlContext" |
|
170 |
* {@link SecurityPermission} |
|
171 |
* @since 1.3 |
|
172 |
*/ |
|
173 |
public AccessControlContext(AccessControlContext acc, |
|
174 |
DomainCombiner combiner) { |
|
175 |
||
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
176 |
this(acc, combiner, false); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
177 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
178 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
179 |
/** |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
180 |
* package private to allow calls from ProtectionDomain without performing |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
181 |
* the security check for {@linkplain SecurityConstants#CREATE_ACC_PERMISSION} |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
182 |
* permission |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
183 |
*/ |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
184 |
AccessControlContext(AccessControlContext acc, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
185 |
DomainCombiner combiner, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
186 |
boolean preauthorized) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
187 |
if (!preauthorized) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
188 |
SecurityManager sm = System.getSecurityManager(); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
189 |
if (sm != null) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
190 |
sm.checkPermission(SecurityConstants.CREATE_ACC_PERMISSION); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
191 |
this.isAuthorized = true; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
192 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
25859
diff
changeset
|
193 |
} else { |
18222 | 194 |
this.isAuthorized = true; |
2 | 195 |
} |
196 |
||
197 |
this.context = acc.context; |
|
198 |
||
199 |
// we do not need to run the combine method on the |
|
200 |
// provided ACC. it was already "combined" when the |
|
201 |
// context was originally retrieved. |
|
202 |
// |
|
203 |
// at this point in time, we simply throw away the old |
|
204 |
// combiner and use the newly provided one. |
|
205 |
this.combiner = combiner; |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* package private for AccessController |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
210 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
211 |
* This "argument wrapper" context will be passed as the actual context |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
212 |
* parameter on an internal doPrivileged() call used in the implementation. |
2 | 213 |
*/ |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
214 |
AccessControlContext(ProtectionDomain caller, DomainCombiner combiner, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
215 |
AccessControlContext parent, AccessControlContext context, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
216 |
Permission[] perms) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
217 |
{ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
218 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
219 |
* Combine the domains from the doPrivileged() context into our |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
220 |
* wrapper context, if necessary. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
221 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
222 |
ProtectionDomain[] callerPDs = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
223 |
if (caller != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
224 |
callerPDs = new ProtectionDomain[] { caller }; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
225 |
} |
2 | 226 |
if (context != null) { |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
227 |
if (combiner != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
228 |
this.context = combiner.combine(callerPDs, context.context); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
229 |
} else { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
230 |
this.context = combine(callerPDs, context.context); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
231 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
232 |
} else { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
233 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
234 |
* Call combiner even if there is seemingly nothing to combine. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
235 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
236 |
if (combiner != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
237 |
this.context = combiner.combine(callerPDs, null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
238 |
} else { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
239 |
this.context = combine(callerPDs, null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
240 |
} |
2 | 241 |
} |
242 |
this.combiner = combiner; |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
243 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
244 |
Permission[] tmp = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
245 |
if (perms != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
246 |
tmp = new Permission[perms.length]; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
247 |
for (int i=0; i < perms.length; i++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
248 |
if (perms[i] == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
249 |
throw new NullPointerException("permission can't be null"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
250 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
251 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
252 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
253 |
* An AllPermission argument is equivalent to calling |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
254 |
* doPrivileged() without any limit permissions. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
255 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
256 |
if (perms[i].getClass() == AllPermission.class) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
257 |
parent = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
258 |
} |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
259 |
// Add altPath into permission for compatibility. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
260 |
tmp[i] = FilePermCompat.newPermPlusAltPath(perms[i]); |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
261 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
262 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
263 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
264 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
265 |
* For a doPrivileged() with limited privilege scope, initialize |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
266 |
* the relevant fields. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
267 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
268 |
* The limitedContext field contains the union of all domains which |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
269 |
* are enclosed by this limited privilege scope. In other words, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
270 |
* it contains all of the domains which could potentially be checked |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
271 |
* if none of the limiting permissions implied a requested permission. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
272 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
273 |
if (parent != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
274 |
this.limitedContext = combine(parent.context, parent.limitedContext); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
275 |
this.isLimited = true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
276 |
this.isWrapped = true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
277 |
this.permissions = tmp; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
278 |
this.parent = parent; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
279 |
this.privilegedContext = context; // used in checkPermission2() |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
280 |
} |
18222 | 281 |
this.isAuthorized = true; |
2 | 282 |
} |
283 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
284 |
|
2 | 285 |
/** |
286 |
* package private constructor for AccessController.getContext() |
|
287 |
*/ |
|
288 |
||
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
289 |
AccessControlContext(ProtectionDomain[] context, |
18222 | 290 |
boolean isPrivileged) |
2 | 291 |
{ |
292 |
this.context = context; |
|
293 |
this.isPrivileged = isPrivileged; |
|
18222 | 294 |
this.isAuthorized = true; |
2 | 295 |
} |
296 |
||
297 |
/** |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
298 |
* Constructor for JavaSecurityAccess.doIntersectionPrivilege() |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
299 |
*/ |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
300 |
AccessControlContext(ProtectionDomain[] context, |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
301 |
AccessControlContext privilegedContext) |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
302 |
{ |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
303 |
this.context = context; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
304 |
this.privilegedContext = privilegedContext; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
305 |
this.isPrivileged = true; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
306 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
307 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
308 |
/** |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
309 |
* Returns this context's context. |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
310 |
*/ |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
311 |
ProtectionDomain[] getContext() { |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
312 |
return context; |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
313 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
314 |
|
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
315 |
/** |
2 | 316 |
* Returns true if this context is privileged. |
317 |
*/ |
|
318 |
boolean isPrivileged() |
|
319 |
{ |
|
320 |
return isPrivileged; |
|
321 |
} |
|
322 |
||
323 |
/** |
|
324 |
* get the assigned combiner from the privileged or inherited context |
|
325 |
*/ |
|
326 |
DomainCombiner getAssignedCombiner() { |
|
327 |
AccessControlContext acc; |
|
328 |
if (isPrivileged) { |
|
329 |
acc = privilegedContext; |
|
330 |
} else { |
|
331 |
acc = AccessController.getInheritedAccessControlContext(); |
|
332 |
} |
|
333 |
if (acc != null) { |
|
334 |
return acc.combiner; |
|
335 |
} |
|
336 |
return null; |
|
337 |
} |
|
338 |
||
339 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
340 |
* Get the {@code DomainCombiner} associated with this |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
341 |
* {@code AccessControlContext}. |
2 | 342 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
343 |
* @return the {@code DomainCombiner} associated with this |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18253
diff
changeset
|
344 |
* {@code AccessControlContext}, or {@code null} |
2 | 345 |
* if there is none. |
346 |
* |
|
347 |
* @exception SecurityException if a security manager is installed and |
|
348 |
* the caller does not have the "getDomainCombiner" |
|
349 |
* {@link SecurityPermission} |
|
350 |
* @since 1.3 |
|
351 |
*/ |
|
352 |
public DomainCombiner getDomainCombiner() { |
|
353 |
||
354 |
SecurityManager sm = System.getSecurityManager(); |
|
355 |
if (sm != null) { |
|
356 |
sm.checkPermission(SecurityConstants.GET_COMBINER_PERMISSION); |
|
357 |
} |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
358 |
return getCombiner(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
359 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
360 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
361 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
362 |
* package private for AccessController |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
363 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
364 |
DomainCombiner getCombiner() { |
2 | 365 |
return combiner; |
366 |
} |
|
367 |
||
21321
923ca53e6572
8021191: Add isAuthorized check to limited doPrivileged methods
mullan
parents:
18579
diff
changeset
|
368 |
boolean isAuthorized() { |
923ca53e6572
8021191: Add isAuthorized check to limited doPrivileged methods
mullan
parents:
18579
diff
changeset
|
369 |
return isAuthorized; |
923ca53e6572
8021191: Add isAuthorized check to limited doPrivileged methods
mullan
parents:
18579
diff
changeset
|
370 |
} |
923ca53e6572
8021191: Add isAuthorized check to limited doPrivileged methods
mullan
parents:
18579
diff
changeset
|
371 |
|
2 | 372 |
/** |
373 |
* Determines whether the access request indicated by the |
|
374 |
* specified permission should be allowed or denied, based on |
|
375 |
* the security policy currently in effect, and the context in |
|
376 |
* this object. The request is allowed only if every ProtectionDomain |
|
377 |
* in the context implies the permission. Otherwise the request is |
|
378 |
* denied. |
|
379 |
* |
|
380 |
* <p> |
|
381 |
* This method quietly returns if the access request |
|
382 |
* is permitted, or throws a suitable AccessControlException otherwise. |
|
383 |
* |
|
384 |
* @param perm the requested permission. |
|
385 |
* |
|
386 |
* @exception AccessControlException if the specified permission |
|
387 |
* is not permitted, based on the current security policy and the |
|
388 |
* context encapsulated by this object. |
|
389 |
* @exception NullPointerException if the permission to check for is null. |
|
390 |
*/ |
|
391 |
public void checkPermission(Permission perm) |
|
392 |
throws AccessControlException |
|
393 |
{ |
|
394 |
boolean dumpDebug = false; |
|
395 |
||
396 |
if (perm == null) { |
|
397 |
throw new NullPointerException("permission can't be null"); |
|
398 |
} |
|
399 |
if (getDebug() != null) { |
|
400 |
// If "codebase" is not specified, we dump the info by default. |
|
401 |
dumpDebug = !Debug.isOn("codebase="); |
|
402 |
if (!dumpDebug) { |
|
403 |
// If "codebase" is specified, only dump if the specified code |
|
404 |
// value is in the stack. |
|
405 |
for (int i = 0; context != null && i < context.length; i++) { |
|
406 |
if (context[i].getCodeSource() != null && |
|
407 |
context[i].getCodeSource().getLocation() != null && |
|
408 |
Debug.isOn("codebase=" + context[i].getCodeSource().getLocation().toString())) { |
|
409 |
dumpDebug = true; |
|
410 |
break; |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
||
415 |
dumpDebug &= !Debug.isOn("permission=") || |
|
416 |
Debug.isOn("permission=" + perm.getClass().getCanonicalName()); |
|
417 |
||
418 |
if (dumpDebug && Debug.isOn("stack")) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
419 |
Thread.dumpStack(); |
2 | 420 |
} |
421 |
||
422 |
if (dumpDebug && Debug.isOn("domain")) { |
|
423 |
if (context == null) { |
|
424 |
debug.println("domain (context is null)"); |
|
425 |
} else { |
|
426 |
for (int i=0; i< context.length; i++) { |
|
427 |
debug.println("domain "+i+" "+context[i]); |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
/* |
|
434 |
* iterate through the ProtectionDomains in the context. |
|
435 |
* Stop at the first one that doesn't allow the |
|
436 |
* requested permission (throwing an exception). |
|
437 |
* |
|
438 |
*/ |
|
439 |
||
440 |
/* if ctxt is null, all we had on the stack were system domains, |
|
441 |
or the first domain was a Privileged system domain. This |
|
442 |
is to make the common case for system code very fast */ |
|
443 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
444 |
if (context == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
445 |
checkPermission2(perm); |
2 | 446 |
return; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
447 |
} |
2 | 448 |
|
449 |
for (int i=0; i< context.length; i++) { |
|
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
31538
diff
changeset
|
450 |
if (context[i] != null && !context[i].impliesWithAltFilePerm(perm)) { |
2 | 451 |
if (dumpDebug) { |
452 |
debug.println("access denied " + perm); |
|
453 |
} |
|
454 |
||
97
5c029f131927
6648816: REGRESSION: setting -Djava.security.debug=failure result in NPE in ACC
xuelei
parents:
2
diff
changeset
|
455 |
if (Debug.isOn("failure") && debug != null) { |
2 | 456 |
// Want to make sure this is always displayed for failure, |
457 |
// but do not want to display again if already displayed |
|
458 |
// above. |
|
459 |
if (!dumpDebug) { |
|
460 |
debug.println("access denied " + perm); |
|
461 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
462 |
Thread.dumpStack(); |
2 | 463 |
final ProtectionDomain pd = context[i]; |
464 |
final Debug db = debug; |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
465 |
AccessController.doPrivileged (new PrivilegedAction<>() { |
2 | 466 |
public Void run() { |
467 |
db.println("domain that failed "+pd); |
|
468 |
return null; |
|
469 |
} |
|
470 |
}); |
|
471 |
} |
|
472 |
throw new AccessControlException("access denied "+perm, perm); |
|
473 |
} |
|
474 |
} |
|
475 |
||
476 |
// allow if all of them allowed access |
|
477 |
if (dumpDebug) { |
|
478 |
debug.println("access allowed "+perm); |
|
479 |
} |
|
480 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
481 |
checkPermission2(perm); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
482 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
483 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
484 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
485 |
* Check the domains associated with the limited privilege scope. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
486 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
487 |
private void checkPermission2(Permission perm) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
488 |
if (!isLimited) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
489 |
return; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
490 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
491 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
492 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
493 |
* Check the doPrivileged() context parameter, if present. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
494 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
495 |
if (privilegedContext != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
496 |
privilegedContext.checkPermission2(perm); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
497 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
498 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
499 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
500 |
* Ignore the limited permissions and parent fields of a wrapper |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
501 |
* context since they were already carried down into the unwrapped |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
502 |
* context. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
503 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
504 |
if (isWrapped) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
505 |
return; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
506 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
507 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
508 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
509 |
* Try to match any limited privilege scope. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
510 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
511 |
if (permissions != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
512 |
Class<?> permClass = perm.getClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
513 |
for (int i=0; i < permissions.length; i++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
514 |
Permission limit = permissions[i]; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
515 |
if (limit.getClass().equals(permClass) && limit.implies(perm)) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
516 |
return; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
517 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
518 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
519 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
520 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
521 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
522 |
* Check the limited privilege scope up the call stack or the inherited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
523 |
* parent thread call stack of this ACC. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
524 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
525 |
if (parent != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
526 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
527 |
* As an optimization, if the parent context is the inherited call |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
528 |
* stack context from a parent thread then checking the protection |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
529 |
* domains of the parent context is redundant since they have |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
530 |
* already been merged into the child thread's context by |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
531 |
* optimize(). When parent is set to an inherited context this |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
532 |
* context was not directly created by a limited scope |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
533 |
* doPrivileged() and it does not have its own limited permissions. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
534 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
535 |
if (permissions == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
536 |
parent.checkPermission2(perm); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
537 |
} else { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
538 |
parent.checkPermission(perm); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
539 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
540 |
} |
2 | 541 |
} |
542 |
||
543 |
/** |
|
544 |
* Take the stack-based context (this) and combine it with the |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
545 |
* privileged or inherited context, if need be. Any limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
546 |
* privilege scope is flagged regardless of whether the assigned |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
547 |
* context comes from an immediately enclosing limited doPrivileged(). |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
548 |
* The limited privilege scope can indirectly flow from the inherited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
549 |
* parent thread or an assigned context previously captured by getContext(). |
2 | 550 |
*/ |
551 |
AccessControlContext optimize() { |
|
552 |
// the assigned (privileged or inherited) context |
|
553 |
AccessControlContext acc; |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
554 |
DomainCombiner combiner = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
555 |
AccessControlContext parent = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
556 |
Permission[] permissions = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
557 |
|
2 | 558 |
if (isPrivileged) { |
559 |
acc = privilegedContext; |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
560 |
if (acc != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
561 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
562 |
* If the context is from a limited scope doPrivileged() then |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
563 |
* copy the permissions and parent fields out of the wrapper |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
564 |
* context that was created to hold them. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
565 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
566 |
if (acc.isWrapped) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
567 |
permissions = acc.permissions; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
568 |
parent = acc.parent; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
569 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
570 |
} |
2 | 571 |
} else { |
572 |
acc = AccessController.getInheritedAccessControlContext(); |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
573 |
if (acc != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
574 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
575 |
* If the inherited context is constrained by a limited scope |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
576 |
* doPrivileged() then set it as our parent so we will process |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
577 |
* the non-domain-related state. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
578 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
579 |
if (acc.isLimited) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
580 |
parent = acc; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
581 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
582 |
} |
2 | 583 |
} |
584 |
||
585 |
// this.context could be null if only system code is on the stack; |
|
586 |
// in that case, ignore the stack context |
|
587 |
boolean skipStack = (context == null); |
|
588 |
||
589 |
// acc.context could be null if only system code was involved; |
|
590 |
// in that case, ignore the assigned context |
|
591 |
boolean skipAssigned = (acc == null || acc.context == null); |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
592 |
ProtectionDomain[] assigned = (skipAssigned) ? null : acc.context; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
593 |
ProtectionDomain[] pd; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
594 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
595 |
// if there is no enclosing limited privilege scope on the stack or |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
596 |
// inherited from a parent thread |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
597 |
boolean skipLimited = ((acc == null || !acc.isWrapped) && parent == null); |
2 | 598 |
|
599 |
if (acc != null && acc.combiner != null) { |
|
600 |
// let the assigned acc's combiner do its thing |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
601 |
if (getDebug() != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
602 |
debug.println("AccessControlContext invoking the Combiner"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
603 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
604 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
605 |
// No need to clone current and assigned.context |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
606 |
// combine() will not update them |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
607 |
combiner = acc.combiner; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
608 |
pd = combiner.combine(context, assigned); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
609 |
} else { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
610 |
if (skipStack) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
611 |
if (skipAssigned) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
612 |
calculateFields(acc, parent, permissions); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
613 |
return this; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
614 |
} else if (skipLimited) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
615 |
return acc; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
616 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
617 |
} else if (assigned != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
618 |
if (skipLimited) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
619 |
// optimization: if there is a single stack domain and |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
620 |
// that domain is already in the assigned context; no |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
621 |
// need to combine |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
622 |
if (context.length == 1 && context[0] == assigned[0]) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
623 |
return acc; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
624 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
625 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
626 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
627 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
628 |
pd = combine(context, assigned); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
629 |
if (skipLimited && !skipAssigned && pd == assigned) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
630 |
return acc; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
631 |
} else if (skipAssigned && pd == context) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
632 |
calculateFields(acc, parent, permissions); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
633 |
return this; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
634 |
} |
2 | 635 |
} |
636 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
637 |
// Reuse existing ACC |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
638 |
this.context = pd; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
639 |
this.combiner = combiner; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
640 |
this.isPrivileged = false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
641 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
642 |
calculateFields(acc, parent, permissions); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
643 |
return this; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
644 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
645 |
|
2 | 646 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
647 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
648 |
* Combine the current (stack) and assigned domains. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
649 |
*/ |
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
650 |
private static ProtectionDomain[] combine(ProtectionDomain[] current, |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
651 |
ProtectionDomain[] assigned) { |
2 | 652 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
653 |
// current could be null if only system code is on the stack; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
654 |
// in that case, ignore the stack context |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
655 |
boolean skipStack = (current == null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
656 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
657 |
// assigned could be null if only system code was involved; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
658 |
// in that case, ignore the assigned context |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
659 |
boolean skipAssigned = (assigned == null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
660 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
661 |
int slen = (skipStack) ? 0 : current.length; |
2 | 662 |
|
663 |
// optimization: if there is no assigned context and the stack length |
|
664 |
// is less then or equal to two; there is no reason to compress the |
|
665 |
// stack context, it already is |
|
666 |
if (skipAssigned && slen <= 2) { |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
667 |
return current; |
2 | 668 |
} |
669 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
670 |
int n = (skipAssigned) ? 0 : assigned.length; |
2 | 671 |
|
672 |
// now we combine both of them, and create a new context |
|
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
673 |
ProtectionDomain[] pd = new ProtectionDomain[slen + n]; |
2 | 674 |
|
675 |
// first copy in the assigned context domains, no need to compress |
|
676 |
if (!skipAssigned) { |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
677 |
System.arraycopy(assigned, 0, pd, 0, n); |
2 | 678 |
} |
679 |
||
680 |
// now add the stack context domains, discarding nulls and duplicates |
|
681 |
outer: |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
682 |
for (int i = 0; i < slen; i++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
683 |
ProtectionDomain sd = current[i]; |
2 | 684 |
if (sd != null) { |
685 |
for (int j = 0; j < n; j++) { |
|
686 |
if (sd == pd[j]) { |
|
687 |
continue outer; |
|
688 |
} |
|
689 |
} |
|
690 |
pd[n++] = sd; |
|
691 |
} |
|
692 |
} |
|
693 |
||
694 |
// if length isn't equal, we need to shorten the array |
|
695 |
if (n != pd.length) { |
|
696 |
// optimization: if we didn't really combine anything |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
697 |
if (!skipAssigned && n == assigned.length) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
698 |
return assigned; |
2 | 699 |
} else if (skipAssigned && n == slen) { |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
700 |
return current; |
2 | 701 |
} |
31538
0981099a3e54
8130022: Use Java-style array declarations consistently
igerasim
parents:
30033
diff
changeset
|
702 |
ProtectionDomain[] tmp = new ProtectionDomain[n]; |
2 | 703 |
System.arraycopy(pd, 0, tmp, 0, n); |
704 |
pd = tmp; |
|
705 |
} |
|
706 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
707 |
return pd; |
2 | 708 |
} |
709 |
||
710 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
711 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
712 |
* Calculate the additional domains that could potentially be reached via |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
713 |
* limited privilege scope. Mark the context as being subject to limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
714 |
* privilege scope unless the reachable domains (if any) are already |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
715 |
* contained in this domain context (in which case any limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
716 |
* privilege scope checking would be redundant). |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
717 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
718 |
private void calculateFields(AccessControlContext assigned, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
719 |
AccessControlContext parent, Permission[] permissions) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
720 |
{ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
721 |
ProtectionDomain[] parentLimit = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
722 |
ProtectionDomain[] assignedLimit = null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
723 |
ProtectionDomain[] newLimit; |
2 | 724 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
725 |
parentLimit = (parent != null)? parent.limitedContext: null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
726 |
assignedLimit = (assigned != null)? assigned.limitedContext: null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
727 |
newLimit = combine(parentLimit, assignedLimit); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
728 |
if (newLimit != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
729 |
if (context == null || !containsAllPDs(newLimit, context)) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
730 |
this.limitedContext = newLimit; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
731 |
this.permissions = permissions; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
732 |
this.parent = parent; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
733 |
this.isLimited = true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
734 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
735 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
736 |
} |
2 | 737 |
|
738 |
||
739 |
/** |
|
740 |
* Checks two AccessControlContext objects for equality. |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
29027
diff
changeset
|
741 |
* Checks that {@code obj} is |
2 | 742 |
* an AccessControlContext and has the same set of ProtectionDomains |
743 |
* as this context. |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
29027
diff
changeset
|
744 |
* |
2 | 745 |
* @param obj the object we are testing for equality with this object. |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
29027
diff
changeset
|
746 |
* @return true if {@code obj} is an AccessControlContext, and has the |
2 | 747 |
* same set of ProtectionDomains as this context, false otherwise. |
748 |
*/ |
|
749 |
public boolean equals(Object obj) { |
|
750 |
if (obj == this) |
|
751 |
return true; |
|
752 |
||
753 |
if (! (obj instanceof AccessControlContext)) |
|
754 |
return false; |
|
755 |
||
756 |
AccessControlContext that = (AccessControlContext) obj; |
|
757 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
758 |
if (!equalContext(that)) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
759 |
return false; |
2 | 760 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
761 |
if (!equalLimitedContext(that)) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
762 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
763 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
764 |
return true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
765 |
} |
2 | 766 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
767 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
768 |
* Compare for equality based on state that is free of limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
769 |
* privilege complications. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
770 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
771 |
private boolean equalContext(AccessControlContext that) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
772 |
if (!equalPDs(this.context, that.context)) |
2 | 773 |
return false; |
774 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
775 |
if (this.combiner == null && that.combiner != null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
776 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
777 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
778 |
if (this.combiner != null && !this.combiner.equals(that.combiner)) |
2 | 779 |
return false; |
780 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
781 |
return true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
782 |
} |
2 | 783 |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
784 |
private boolean equalPDs(ProtectionDomain[] a, ProtectionDomain[] b) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
785 |
if (a == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
786 |
return (b == null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
787 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
788 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
789 |
if (b == null) |
2 | 790 |
return false; |
791 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
792 |
if (!(containsAllPDs(a, b) && containsAllPDs(b, a))) |
2 | 793 |
return false; |
794 |
||
795 |
return true; |
|
796 |
} |
|
797 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
798 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
799 |
* Compare for equality based on state that is captured during a |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
800 |
* call to AccessController.getContext() when a limited privilege |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
801 |
* scope is in effect. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
802 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
803 |
private boolean equalLimitedContext(AccessControlContext that) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
804 |
if (that == null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
805 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
806 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
807 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
808 |
* If neither instance has limited privilege scope then we're done. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
809 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
810 |
if (!this.isLimited && !that.isLimited) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
811 |
return true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
812 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
813 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
814 |
* If only one instance has limited privilege scope then we're done. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
815 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
816 |
if (!(this.isLimited && that.isLimited)) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
817 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
818 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
819 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
820 |
* Wrapped instances should never escape outside the implementation |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
821 |
* this class and AccessController so this will probably never happen |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
822 |
* but it only makes any sense to compare if they both have the same |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
823 |
* isWrapped state. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
824 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
825 |
if ((this.isWrapped && !that.isWrapped) || |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
826 |
(!this.isWrapped && that.isWrapped)) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
827 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
828 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
829 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
830 |
if (this.permissions == null && that.permissions != null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
831 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
832 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
833 |
if (this.permissions != null && that.permissions == null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
834 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
835 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
836 |
if (!(this.containsAllLimits(that) && that.containsAllLimits(this))) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
837 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
838 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
839 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
840 |
* Skip through any wrapped contexts. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
841 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
842 |
AccessControlContext thisNextPC = getNextPC(this); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
843 |
AccessControlContext thatNextPC = getNextPC(that); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
844 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
845 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
846 |
* The protection domains and combiner of a privilegedContext are |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
847 |
* not relevant because they have already been included in the context |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
848 |
* of this instance by optimize() so we only care about any limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
849 |
* privilege state they may have. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
850 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
851 |
if (thisNextPC == null && thatNextPC != null && thatNextPC.isLimited) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
852 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
853 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
854 |
if (thisNextPC != null && !thisNextPC.equalLimitedContext(thatNextPC)) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
855 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
856 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
857 |
if (this.parent == null && that.parent != null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
858 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
859 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
860 |
if (this.parent != null && !this.parent.equals(that.parent)) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
861 |
return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
862 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
863 |
return true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
864 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
865 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
866 |
/* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
867 |
* Follow the privilegedContext link making our best effort to skip |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
868 |
* through any wrapper contexts. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
869 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
870 |
private static AccessControlContext getNextPC(AccessControlContext acc) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
871 |
while (acc != null && acc.privilegedContext != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
872 |
acc = acc.privilegedContext; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
873 |
if (!acc.isWrapped) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
874 |
return acc; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
875 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
876 |
return null; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
877 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
878 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
879 |
private static boolean containsAllPDs(ProtectionDomain[] thisContext, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
880 |
ProtectionDomain[] thatContext) { |
2 | 881 |
boolean match = false; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
882 |
|
2 | 883 |
// |
884 |
// ProtectionDomains within an ACC currently cannot be null |
|
885 |
// and this is enforced by the constructor and the various |
|
886 |
// optimize methods. However, historically this logic made attempts |
|
887 |
// to support the notion of a null PD and therefore this logic continues |
|
888 |
// to support that notion. |
|
889 |
ProtectionDomain thisPd; |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
890 |
for (int i = 0; i < thisContext.length; i++) { |
2 | 891 |
match = false; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
892 |
if ((thisPd = thisContext[i]) == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
893 |
for (int j = 0; (j < thatContext.length) && !match; j++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
894 |
match = (thatContext[j] == null); |
2 | 895 |
} |
896 |
} else { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
897 |
Class<?> thisPdClass = thisPd.getClass(); |
2 | 898 |
ProtectionDomain thatPd; |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
899 |
for (int j = 0; (j < thatContext.length) && !match; j++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
900 |
thatPd = thatContext[j]; |
2 | 901 |
|
902 |
// Class check required to avoid PD exposure (4285406) |
|
903 |
match = (thatPd != null && |
|
904 |
thisPdClass == thatPd.getClass() && thisPd.equals(thatPd)); |
|
905 |
} |
|
906 |
} |
|
907 |
if (!match) return false; |
|
908 |
} |
|
909 |
return match; |
|
910 |
} |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
911 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
912 |
private boolean containsAllLimits(AccessControlContext that) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
913 |
boolean match = false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
914 |
Permission thisPerm; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
915 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
916 |
if (this.permissions == null && that.permissions == null) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
917 |
return true; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
918 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
919 |
for (int i = 0; i < this.permissions.length; i++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
920 |
Permission limit = this.permissions[i]; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
921 |
Class <?> limitClass = limit.getClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
922 |
match = false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
923 |
for (int j = 0; (j < that.permissions.length) && !match; j++) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
924 |
Permission perm = that.permissions[j]; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
925 |
match = (limitClass.equals(perm.getClass()) && |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
926 |
limit.equals(perm)); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
927 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
928 |
if (!match) return false; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
929 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
930 |
return match; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
931 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
932 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
933 |
|
2 | 934 |
/** |
935 |
* Returns the hash code value for this context. The hash code |
|
936 |
* is computed by exclusive or-ing the hash code of all the protection |
|
937 |
* domains in the context together. |
|
938 |
* |
|
939 |
* @return a hash code value for this context. |
|
940 |
*/ |
|
941 |
||
942 |
public int hashCode() { |
|
943 |
int hashCode = 0; |
|
944 |
||
945 |
if (context == null) |
|
946 |
return hashCode; |
|
947 |
||
948 |
for (int i =0; i < context.length; i++) { |
|
949 |
if (context[i] != null) |
|
950 |
hashCode ^= context[i].hashCode(); |
|
951 |
} |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
10336
diff
changeset
|
952 |
|
2 | 953 |
return hashCode; |
954 |
} |
|
955 |
} |