author | dlong |
Tue, 06 Nov 2018 16:04:50 -0800 | |
changeset 52431 | b0af758a092c |
parent 52427 | 3c6aa484536c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49588
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, 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 |
||
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
28 |
import java.util.ArrayList; |
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
29 |
import java.util.Collections; |
2 | 30 |
import java.util.Enumeration; |
31 |
import java.util.List; |
|
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
32 |
import java.util.Map; |
42153
d57f354dd0ab
8043252: Debug of access control is obfuscated - NullPointerException in ProtectionDomain
jnimeh
parents:
41596
diff
changeset
|
33 |
import java.util.Objects; |
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
34 |
import java.util.WeakHashMap; |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
49588
diff
changeset
|
35 |
import jdk.internal.access.JavaSecurityAccess; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
49588
diff
changeset
|
36 |
import jdk.internal.access.SharedSecrets; |
43803
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
37 |
import sun.security.action.GetPropertyAction; |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
38 |
import sun.security.provider.PolicyFile; |
2 | 39 |
import sun.security.util.Debug; |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
40 |
import sun.security.util.FilePermCompat; |
2 | 41 |
import sun.security.util.SecurityConstants; |
42 |
||
43 |
/** |
|
30687
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
44 |
* The ProtectionDomain class encapsulates the characteristics of a domain, |
2 | 45 |
* which encloses a set of classes whose instances are granted a set |
46 |
* of permissions when being executed on behalf of a given set of Principals. |
|
47 |
* <p> |
|
48 |
* A static set of permissions can be bound to a ProtectionDomain when it is |
|
49 |
* constructed; such permissions are granted to the domain regardless of the |
|
50 |
* Policy in force. However, to support dynamic security policies, a |
|
51 |
* ProtectionDomain can also be constructed such that it is dynamically |
|
52 |
* mapped to a set of permissions by the current Policy whenever a permission |
|
53 |
* is checked. |
|
54 |
* |
|
55 |
* @author Li Gong |
|
56 |
* @author Roland Schemers |
|
57 |
* @author Gary Ellison |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
43803
diff
changeset
|
58 |
* @since 1.2 |
2 | 59 |
*/ |
60 |
||
61 |
public class ProtectionDomain { |
|
30687
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
62 |
|
43803
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
63 |
/** |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
64 |
* If true, {@link #impliesWithAltFilePerm} will try to be compatible on |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
65 |
* FilePermission checking even if a 3rd-party Policy implementation is set. |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
66 |
*/ |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
67 |
private static final boolean filePermCompatInPD = |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
68 |
"true".equals(GetPropertyAction.privilegedGetProperty( |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
69 |
"jdk.security.filePermCompat")); |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
70 |
|
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
71 |
private static class JavaSecurityAccessImpl implements JavaSecurityAccess { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
72 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
73 |
private JavaSecurityAccessImpl() { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
74 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
75 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
76 |
@Override |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
77 |
public <T> T doIntersectionPrivilege( |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
78 |
PrivilegedAction<T> action, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
79 |
final AccessControlContext stack, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
80 |
final AccessControlContext context) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
81 |
if (action == null) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
82 |
throw new NullPointerException(); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
83 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
84 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
85 |
return AccessController.doPrivileged( |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
86 |
action, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
87 |
getCombinedACC(context, stack) |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
88 |
); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
89 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
90 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
91 |
@Override |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
92 |
public <T> T doIntersectionPrivilege( |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
93 |
PrivilegedAction<T> action, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
94 |
AccessControlContext context) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
95 |
return doIntersectionPrivilege(action, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
96 |
AccessController.getContext(), context); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
97 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
98 |
|
41596
a6382b6ba29d
8165271: Fix use of reflection to gain access to private fields
ddehaven
parents:
41377
diff
changeset
|
99 |
@Override |
a6382b6ba29d
8165271: Fix use of reflection to gain access to private fields
ddehaven
parents:
41377
diff
changeset
|
100 |
public ProtectionDomain[] getProtectDomains(AccessControlContext context) { |
a6382b6ba29d
8165271: Fix use of reflection to gain access to private fields
ddehaven
parents:
41377
diff
changeset
|
101 |
return context.getContext(); |
a6382b6ba29d
8165271: Fix use of reflection to gain access to private fields
ddehaven
parents:
41377
diff
changeset
|
102 |
} |
a6382b6ba29d
8165271: Fix use of reflection to gain access to private fields
ddehaven
parents:
41377
diff
changeset
|
103 |
|
30687
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
104 |
private static AccessControlContext getCombinedACC( |
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
105 |
AccessControlContext context, AccessControlContext stack) { |
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
106 |
AccessControlContext acc = |
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
107 |
new AccessControlContext(context, stack.getCombiner(), true); |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
108 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
109 |
return new AccessControlContext(stack.getContext(), acc).optimize(); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
110 |
} |
49588
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
111 |
|
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
112 |
@Override |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
113 |
public ProtectionDomainCache getProtectionDomainCache() { |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
114 |
return new ProtectionDomainCache() { |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
115 |
private final Map<Key, PermissionCollection> map = |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
116 |
Collections.synchronizedMap(new WeakHashMap<>()); |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
117 |
public void put(ProtectionDomain pd, |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
118 |
PermissionCollection pc) { |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
119 |
map.put((pd == null ? null : pd.key), pc); |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
120 |
} |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
121 |
public PermissionCollection get(ProtectionDomain pd) { |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
122 |
return pd == null ? map.get(null) : map.get(pd.key); |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
123 |
} |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
124 |
}; |
ae568aefc5aa
8152821: Merge jdk.internal.misc.JavaSecurityAccess and jdk.internal.misc.JavaSecurityProtectionDomainAccess shared secrets
redestad
parents:
48207
diff
changeset
|
125 |
} |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
126 |
} |
2 | 127 |
|
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
128 |
static { |
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
129 |
// Set up JavaSecurityAccess in SharedSecrets |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
27181
diff
changeset
|
130 |
SharedSecrets.setJavaSecurityAccess(new JavaSecurityAccessImpl()); |
8816
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
131 |
} |
29f983feda95
6907662: System clipboard should ensure access restrictions
denis
parents:
7970
diff
changeset
|
132 |
|
2 | 133 |
/* CodeSource */ |
134 |
private CodeSource codesource ; |
|
135 |
||
136 |
/* ClassLoader the protection domain was consed from */ |
|
137 |
private ClassLoader classloader; |
|
138 |
||
139 |
/* Principals running-as within this protection domain */ |
|
140 |
private Principal[] principals; |
|
141 |
||
142 |
/* the rights this protection domain is granted */ |
|
143 |
private PermissionCollection permissions; |
|
144 |
||
145 |
/* if the permissions object has AllPermission */ |
|
146 |
private boolean hasAllPerm = false; |
|
147 |
||
148 |
/* the PermissionCollection is static (pre 1.4 constructor) |
|
149 |
or dynamic (via a policy refresh) */ |
|
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
150 |
private final boolean staticPermissions; |
2 | 151 |
|
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
152 |
/* |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
153 |
* An object used as a key when the ProtectionDomain is stored in a Map. |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
154 |
*/ |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
155 |
final Key key = new Key(); |
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
156 |
|
2 | 157 |
/** |
158 |
* Creates a new ProtectionDomain with the given CodeSource and |
|
159 |
* Permissions. If the permissions object is not null, then |
|
37880 | 160 |
* {@code setReadOnly()} will be called on the passed in |
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
161 |
* Permissions object. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
162 |
* <p> |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
163 |
* The permissions granted to this domain are static, i.e. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
164 |
* invoking the {@link #staticPermissionsOnly()} method returns true. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
165 |
* They contain only the ones passed to this constructor and |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
166 |
* the current Policy will not be consulted. |
2 | 167 |
* |
168 |
* @param codesource the codesource associated with this domain |
|
169 |
* @param permissions the permissions granted to this domain |
|
170 |
*/ |
|
171 |
public ProtectionDomain(CodeSource codesource, |
|
172 |
PermissionCollection permissions) { |
|
173 |
this.codesource = codesource; |
|
174 |
if (permissions != null) { |
|
175 |
this.permissions = permissions; |
|
176 |
this.permissions.setReadOnly(); |
|
177 |
if (permissions instanceof Permissions && |
|
178 |
((Permissions)permissions).allPermission != null) { |
|
179 |
hasAllPerm = true; |
|
180 |
} |
|
181 |
} |
|
182 |
this.classloader = null; |
|
183 |
this.principals = new Principal[0]; |
|
184 |
staticPermissions = true; |
|
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* Creates a new ProtectionDomain qualified by the given CodeSource, |
|
189 |
* Permissions, ClassLoader and array of Principals. If the |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18222
diff
changeset
|
190 |
* permissions object is not null, then {@code setReadOnly()} |
2 | 191 |
* will be called on the passed in Permissions object. |
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
192 |
* <p> |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
193 |
* The permissions granted to this domain are dynamic, i.e. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
194 |
* invoking the {@link #staticPermissionsOnly()} method returns false. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
195 |
* They include both the static permissions passed to this constructor, |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
196 |
* and any permissions granted to this domain by the current Policy at the |
2 | 197 |
* time a permission is checked. |
198 |
* <p> |
|
199 |
* This constructor is typically used by |
|
200 |
* {@link SecureClassLoader ClassLoaders} |
|
201 |
* and {@link DomainCombiner DomainCombiners} which delegate to |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
18222
diff
changeset
|
202 |
* {@code Policy} to actively associate the permissions granted to |
2 | 203 |
* this domain. This constructor affords the |
204 |
* Policy provider the opportunity to augment the supplied |
|
205 |
* PermissionCollection to reflect policy changes. |
|
206 |
* |
|
207 |
* @param codesource the CodeSource associated with this domain |
|
208 |
* @param permissions the permissions granted to this domain |
|
209 |
* @param classloader the ClassLoader associated with this domain |
|
210 |
* @param principals the array of Principals associated with this |
|
211 |
* domain. The contents of the array are copied to protect against |
|
212 |
* subsequent modification. |
|
213 |
* @see Policy#refresh |
|
214 |
* @see Policy#getPermissions(ProtectionDomain) |
|
215 |
* @since 1.4 |
|
216 |
*/ |
|
217 |
public ProtectionDomain(CodeSource codesource, |
|
218 |
PermissionCollection permissions, |
|
219 |
ClassLoader classloader, |
|
220 |
Principal[] principals) { |
|
221 |
this.codesource = codesource; |
|
222 |
if (permissions != null) { |
|
223 |
this.permissions = permissions; |
|
224 |
this.permissions.setReadOnly(); |
|
225 |
if (permissions instanceof Permissions && |
|
226 |
((Permissions)permissions).allPermission != null) { |
|
227 |
hasAllPerm = true; |
|
228 |
} |
|
229 |
} |
|
230 |
this.classloader = classloader; |
|
231 |
this.principals = (principals != null ? principals.clone(): |
|
232 |
new Principal[0]); |
|
233 |
staticPermissions = false; |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* Returns the CodeSource of this domain. |
|
238 |
* @return the CodeSource of this domain which may be null. |
|
239 |
* @since 1.2 |
|
240 |
*/ |
|
241 |
public final CodeSource getCodeSource() { |
|
242 |
return this.codesource; |
|
243 |
} |
|
244 |
||
245 |
||
246 |
/** |
|
247 |
* Returns the ClassLoader of this domain. |
|
248 |
* @return the ClassLoader of this domain which may be null. |
|
249 |
* |
|
250 |
* @since 1.4 |
|
251 |
*/ |
|
252 |
public final ClassLoader getClassLoader() { |
|
253 |
return this.classloader; |
|
254 |
} |
|
255 |
||
256 |
||
257 |
/** |
|
258 |
* Returns an array of principals for this domain. |
|
259 |
* @return a non-null array of principals for this domain. |
|
260 |
* Returns a new array each time this method is called. |
|
261 |
* |
|
262 |
* @since 1.4 |
|
263 |
*/ |
|
264 |
public final Principal[] getPrincipals() { |
|
265 |
return this.principals.clone(); |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* Returns the static permissions granted to this domain. |
|
270 |
* |
|
271 |
* @return the static set of permissions for this domain which may be null. |
|
272 |
* @see Policy#refresh |
|
273 |
* @see Policy#getPermissions(ProtectionDomain) |
|
274 |
*/ |
|
275 |
public final PermissionCollection getPermissions() { |
|
276 |
return permissions; |
|
277 |
} |
|
278 |
||
279 |
/** |
|
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
280 |
* Returns true if this domain contains only static permissions |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
281 |
* and does not check the current {@code Policy} at the time of |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
282 |
* permission checking. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
283 |
* |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
284 |
* @return true if this domain contains only static permissions. |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
285 |
* |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
286 |
* @since 9 |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
287 |
*/ |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
288 |
public final boolean staticPermissionsOnly() { |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
289 |
return this.staticPermissions; |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
290 |
} |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
291 |
|
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
292 |
/** |
2 | 293 |
* Check and see if this ProtectionDomain implies the permissions |
294 |
* expressed in the Permission object. |
|
295 |
* <p> |
|
296 |
* The set of permissions evaluated is a function of whether the |
|
297 |
* ProtectionDomain was constructed with a static set of permissions |
|
298 |
* or it was bound to a dynamically mapped set of permissions. |
|
299 |
* <p> |
|
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
300 |
* If the {@link #staticPermissionsOnly()} method returns |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
301 |
* true, then the permission will only be checked against the |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
302 |
* PermissionCollection supplied at construction. |
2 | 303 |
* <p> |
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
304 |
* Otherwise, the permission will be checked against the combination |
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
305 |
* of the PermissionCollection supplied at construction and |
2 | 306 |
* the current Policy binding. |
307 |
* |
|
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
308 |
* @param perm the Permission object to check. |
2 | 309 |
* |
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
310 |
* @return true if {@code perm} is implied by this ProtectionDomain. |
2 | 311 |
*/ |
39747
2d542b973871
8138811: Construction of static protection domains
valeriep
parents:
37882
diff
changeset
|
312 |
public boolean implies(Permission perm) { |
2 | 313 |
|
314 |
if (hasAllPerm) { |
|
315 |
// internal permission collection already has AllPermission - |
|
316 |
// no need to go to policy |
|
317 |
return true; |
|
318 |
} |
|
319 |
||
320 |
if (!staticPermissions && |
|
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
321 |
Policy.getPolicyNoCheck().implies(this, perm)) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
322 |
return true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
323 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
324 |
if (permissions != null) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
325 |
return permissions.implies(perm); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
326 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
327 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
328 |
return false; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
329 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
330 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
331 |
/** |
43803
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
332 |
* This method has almost the same logic flow as {@link #implies} but |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
333 |
* it ensures some level of FilePermission compatibility after JDK-8164705. |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
334 |
* |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
335 |
* This method is called by {@link AccessControlContext#checkPermission} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
336 |
* and not intended to be called by an application. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
337 |
*/ |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
338 |
boolean impliesWithAltFilePerm(Permission perm) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
339 |
|
43803
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
340 |
// If FilePermCompat.compat is set (default value), FilePermission |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
341 |
// checking compatibility should be considered. |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
342 |
|
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
343 |
// If filePermCompatInPD is set, this method checks for alternative |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
344 |
// FilePermission to keep compatibility for any Policy implementation. |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
345 |
// When set to false (default value), implies() is called since |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
346 |
// the PolicyFile implementation already supports compatibility. |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
347 |
|
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
348 |
// If this is a subclass of ProtectionDomain, call implies() |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
349 |
// because most likely user has overridden it. |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
350 |
|
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
351 |
if (!filePermCompatInPD || !FilePermCompat.compat || |
e1881d258206
8168410: Multiple JCK tests are failing due to SecurityException is not thrown.
weijun
parents:
42153
diff
changeset
|
352 |
getClass() != ProtectionDomain.class) { |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
353 |
return implies(perm); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
354 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
355 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
356 |
if (hasAllPerm) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
357 |
// internal permission collection already has AllPermission - |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
358 |
// no need to go to policy |
2 | 359 |
return true; |
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
360 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
361 |
|
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
362 |
Permission p2 = null; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
363 |
boolean p2Calculated = false; |
2 | 364 |
|
41377
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
365 |
if (!staticPermissions) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
366 |
Policy policy = Policy.getPolicyNoCheck(); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
367 |
if (policy instanceof PolicyFile) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
368 |
// The PolicyFile implementation supports compatibility |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
369 |
// inside and it also covers the static permissions. |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
370 |
return policy.implies(this, perm); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
371 |
} else { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
372 |
if (policy.implies(this, perm)) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
373 |
return true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
374 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
375 |
p2 = FilePermCompat.newPermUsingAltPath(perm); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
376 |
p2Calculated = true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
377 |
if (p2 != null && policy.implies(this, p2)) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
378 |
return true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
379 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
380 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
381 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
382 |
if (permissions != null) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
383 |
if (permissions.implies(perm)) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
384 |
return true; |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
385 |
} else { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
386 |
if (!p2Calculated) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
387 |
p2 = FilePermCompat.newPermUsingAltPath(perm); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
388 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
389 |
if (p2 != null) { |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
390 |
return permissions.implies(p2); |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
391 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
392 |
} |
271ee055cb31
8164705: Remove pathname canonicalization from FilePermission
weijun
parents:
39747
diff
changeset
|
393 |
} |
2 | 394 |
return false; |
395 |
} |
|
396 |
||
397 |
/** |
|
398 |
* Convert a ProtectionDomain to a String. |
|
399 |
*/ |
|
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
400 |
@Override public String toString() { |
2 | 401 |
String pals = "<no principals>"; |
402 |
if (principals != null && principals.length > 0) { |
|
403 |
StringBuilder palBuf = new StringBuilder("(principals "); |
|
404 |
||
405 |
for (int i = 0; i < principals.length; i++) { |
|
406 |
palBuf.append(principals[i].getClass().getName() + |
|
407 |
" \"" + principals[i].getName() + |
|
408 |
"\""); |
|
409 |
if (i < principals.length-1) |
|
410 |
palBuf.append(",\n"); |
|
411 |
else |
|
412 |
palBuf.append(")\n"); |
|
413 |
} |
|
414 |
pals = palBuf.toString(); |
|
415 |
} |
|
416 |
||
417 |
// Check if policy is set; we don't want to load |
|
418 |
// the policy prematurely here |
|
419 |
PermissionCollection pc = Policy.isSet() && seeAllp() ? |
|
420 |
mergePermissions(): |
|
421 |
getPermissions(); |
|
422 |
||
423 |
return "ProtectionDomain "+ |
|
424 |
" "+codesource+"\n"+ |
|
425 |
" "+classloader+"\n"+ |
|
426 |
" "+pals+"\n"+ |
|
427 |
" "+pc+"\n"; |
|
428 |
} |
|
429 |
||
37882
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
430 |
/* |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
431 |
* holder class for the static field "debug" to delay its initialization |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
432 |
*/ |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
433 |
private static class DebugHolder { |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
434 |
private static final Debug debug = Debug.getInstance("domain"); |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
435 |
} |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
436 |
|
2 | 437 |
/** |
438 |
* Return true (merge policy permissions) in the following cases: |
|
439 |
* |
|
440 |
* . SecurityManager is null |
|
441 |
* |
|
442 |
* . SecurityManager is not null, |
|
443 |
* debug is not null, |
|
444 |
* SecurityManager impelmentation is in bootclasspath, |
|
445 |
* Policy implementation is in bootclasspath |
|
446 |
* (the bootclasspath restrictions avoid recursion) |
|
447 |
* |
|
448 |
* . SecurityManager is not null, |
|
449 |
* debug is null, |
|
450 |
* caller has Policy.getPolicy permission |
|
451 |
*/ |
|
452 |
private static boolean seeAllp() { |
|
453 |
SecurityManager sm = System.getSecurityManager(); |
|
454 |
||
455 |
if (sm == null) { |
|
456 |
return true; |
|
457 |
} else { |
|
37882
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
37880
diff
changeset
|
458 |
if (DebugHolder.debug != null) { |
2 | 459 |
if (sm.getClass().getClassLoader() == null && |
460 |
Policy.getPolicyNoCheck().getClass().getClassLoader() |
|
461 |
== null) { |
|
462 |
return true; |
|
463 |
} |
|
464 |
} else { |
|
465 |
try { |
|
466 |
sm.checkPermission(SecurityConstants.GET_POLICY_PERMISSION); |
|
467 |
return true; |
|
468 |
} catch (SecurityException se) { |
|
469 |
// fall thru and return false |
|
470 |
} |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
return false; |
|
475 |
} |
|
476 |
||
477 |
private PermissionCollection mergePermissions() { |
|
478 |
if (staticPermissions) |
|
479 |
return permissions; |
|
480 |
||
481 |
PermissionCollection perms = |
|
482 |
java.security.AccessController.doPrivileged |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
483 |
(new java.security.PrivilegedAction<>() { |
2 | 484 |
public PermissionCollection run() { |
485 |
Policy p = Policy.getPolicyNoCheck(); |
|
486 |
return p.getPermissions(ProtectionDomain.this); |
|
487 |
} |
|
488 |
}); |
|
489 |
||
490 |
Permissions mergedPerms = new Permissions(); |
|
491 |
int swag = 32; |
|
492 |
int vcap = 8; |
|
493 |
Enumeration<Permission> e; |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
494 |
List<Permission> pdVector = new ArrayList<>(vcap); |
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
495 |
List<Permission> plVector = new ArrayList<>(swag); |
2 | 496 |
|
497 |
// |
|
498 |
// Build a vector of domain permissions for subsequent merge |
|
499 |
if (permissions != null) { |
|
500 |
synchronized (permissions) { |
|
501 |
e = permissions.elements(); |
|
502 |
while (e.hasMoreElements()) { |
|
503 |
pdVector.add(e.nextElement()); |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
// |
|
509 |
// Build a vector of Policy permissions for subsequent merge |
|
510 |
if (perms != null) { |
|
511 |
synchronized (perms) { |
|
512 |
e = perms.elements(); |
|
513 |
while (e.hasMoreElements()) { |
|
514 |
plVector.add(e.nextElement()); |
|
515 |
vcap++; |
|
516 |
} |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
if (perms != null && permissions != null) { |
|
521 |
// |
|
522 |
// Weed out the duplicates from the policy. Unless a refresh |
|
21278 | 523 |
// has occurred since the pd was consed this should result in |
2 | 524 |
// an empty vector. |
525 |
synchronized (permissions) { |
|
526 |
e = permissions.elements(); // domain vs policy |
|
527 |
while (e.hasMoreElements()) { |
|
528 |
Permission pdp = e.nextElement(); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
529 |
Class<?> pdpClass = pdp.getClass(); |
2 | 530 |
String pdpActions = pdp.getActions(); |
531 |
String pdpName = pdp.getName(); |
|
532 |
for (int i = 0; i < plVector.size(); i++) { |
|
533 |
Permission pp = plVector.get(i); |
|
534 |
if (pdpClass.isInstance(pp)) { |
|
535 |
// The equals() method on some permissions |
|
536 |
// have some side effects so this manual |
|
537 |
// comparison is sufficient. |
|
538 |
if (pdpName.equals(pp.getName()) && |
|
42153
d57f354dd0ab
8043252: Debug of access control is obfuscated - NullPointerException in ProtectionDomain
jnimeh
parents:
41596
diff
changeset
|
539 |
Objects.equals(pdpActions, pp.getActions())) { |
2 | 540 |
plVector.remove(i); |
541 |
break; |
|
542 |
} |
|
543 |
} |
|
544 |
} |
|
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
if (perms !=null) { |
|
550 |
// the order of adding to merged perms and permissions |
|
551 |
// needs to preserve the bugfix 4301064 |
|
552 |
||
553 |
for (int i = plVector.size()-1; i >= 0; i--) { |
|
554 |
mergedPerms.add(plVector.get(i)); |
|
555 |
} |
|
556 |
} |
|
557 |
if (permissions != null) { |
|
558 |
for (int i = pdVector.size()-1; i >= 0; i--) { |
|
559 |
mergedPerms.add(pdVector.get(i)); |
|
560 |
} |
|
561 |
} |
|
562 |
||
563 |
return mergedPerms; |
|
564 |
} |
|
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
565 |
|
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
566 |
/** |
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
567 |
* Used for storing ProtectionDomains as keys in a Map. |
5183
7825d97c4cf2
6633872: Policy/PolicyFile leak dynamic ProtectionDomains.
mullan
parents:
2
diff
changeset
|
568 |
*/ |
48207
acfac57f4c35
8193156: Need to backout fixes for JDK-8058547, JDK-8055753, JDK-8085903
igerasim
parents:
47216
diff
changeset
|
569 |
final class Key {} |
30687
eb40445ce6d7
8055753: Use ConcurrentHashMap to map ProtectionDomain to PermissionCollection
mullan
parents:
30033
diff
changeset
|
570 |
|
2 | 571 |
} |