76 |
DEFAULT_CONTEXT = new AccessControlContext(domain); |
DEFAULT_CONTEXT = new AccessControlContext(domain); |
77 |
} |
} |
78 |
|
|
79 |
private static final boolean DEBUG = false; |
private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG; |
80 |
private static void debug(String msg) |
private static void debug(String msg) |
81 |
{ |
{ |
82 |
System.err.print(">>> VMAccessController: "); |
System.err.print(">>> VMAccessController: "); |
108 |
LinkedList stack = (LinkedList) contexts.get(); |
LinkedList stack = (LinkedList) contexts.get(); |
109 |
if (stack == null) |
if (stack == null) |
110 |
{ |
{ |
111 |
|
if (DEBUG) |
112 |
|
debug("no stack... creating "); |
113 |
stack = new LinkedList(); |
stack = new LinkedList(); |
114 |
contexts.set(stack); |
contexts.set(stack); |
115 |
} |
} |
136 |
if (stack.isEmpty()) |
if (stack.isEmpty()) |
137 |
contexts.set(null); |
contexts.set(null); |
138 |
} |
} |
139 |
|
else if (DEBUG) |
140 |
|
{ |
141 |
|
debug("no stack during pop?????"); |
142 |
|
} |
143 |
} |
} |
144 |
|
|
145 |
/** |
/** |
172 |
String[] methods = (String[]) stack[1]; |
String[] methods = (String[]) stack[1]; |
173 |
|
|
174 |
if (DEBUG) |
if (DEBUG) |
175 |
debug(">>> got trace of length " + classes.length); |
debug("got trace of length " + classes.length); |
176 |
|
|
177 |
HashSet domains = new HashSet(); |
HashSet domains = new HashSet(); |
178 |
HashSet seenDomains = new HashSet(); |
HashSet seenDomains = new HashSet(); |
191 |
|
|
192 |
if (DEBUG) |
if (DEBUG) |
193 |
{ |
{ |
194 |
debug(">>> checking " + clazz + "." + method); |
debug("checking " + clazz + "." + method); |
195 |
debug(">>> loader = " + clazz.getClassLoader()); |
// subject to getClassLoader RuntimePermission |
196 |
|
debug("loader = " + clazz.getClassLoader()); |
197 |
} |
} |
198 |
|
|
199 |
// If the previous frame was a call to doPrivileged, then this is |
// If the previous frame was a call to doPrivileged, then this is |
205 |
&& method.equals ("doPrivileged")) |
&& method.equals ("doPrivileged")) |
206 |
{ |
{ |
207 |
// If there was a call to doPrivileged with a supplied context, |
// If there was a call to doPrivileged with a supplied context, |
208 |
// return that context. |
// return that context. If using JAAS doAs*, it should be |
209 |
|
// a context with a SubjectDomainCombiner |
210 |
LinkedList l = (LinkedList) contexts.get(); |
LinkedList l = (LinkedList) contexts.get(); |
211 |
if (l != null) |
if (l != null) |
212 |
context = (AccessControlContext) l.getFirst(); |
context = (AccessControlContext) l.getFirst(); |
213 |
privileged = 1; |
privileged = 1; |
214 |
} |
} |
215 |
|
|
216 |
ProtectionDomain domain = clazz.getProtectionDomain(); |
// subject to getProtectionDomain RuntimePermission |
217 |
|
ProtectionDomain domain = clazz.getProtectionDomain(); |
218 |
|
|
219 |
if (domain == null) |
if (domain == null) |
220 |
continue; |
continue; |
234 |
ProtectionDomain[] result = (ProtectionDomain[]) |
ProtectionDomain[] result = (ProtectionDomain[]) |
235 |
domains.toArray(new ProtectionDomain[domains.size()]); |
domains.toArray(new ProtectionDomain[domains.size()]); |
236 |
|
|
|
// Intersect the derived protection domain with the context supplied |
|
|
// to doPrivileged. |
|
237 |
if (context != null) |
if (context != null) |
238 |
context = new AccessControlContext(result, context, |
{ |
239 |
IntersectingDomainCombiner.SINGLETON); |
DomainCombiner dc = context.getDomainCombiner (); |
240 |
|
// If the supplied context had no explicit DomainCombiner, use |
241 |
|
// our private version, which computes the intersection of the |
242 |
|
// context's domains with the derived set. |
243 |
|
if (dc == null) |
244 |
|
context = new AccessControlContext |
245 |
|
(IntersectingDomainCombiner.SINGLETON.combine |
246 |
|
(result, context.getProtectionDomains ())); |
247 |
|
// Use the supplied DomainCombiner. This should be secure, |
248 |
|
// because only trusted code may create an |
249 |
|
// AccessControlContext with a custom DomainCombiner. |
250 |
|
else |
251 |
|
context = new AccessControlContext (result, context, dc); |
252 |
|
} |
253 |
// No context was supplied. Return the derived one. |
// No context was supplied. Return the derived one. |
254 |
else |
else |
255 |
context = new AccessControlContext(result); |
context = new AccessControlContext (result); |
256 |
|
|
257 |
inGetContext.set(Boolean.FALSE); |
inGetContext.set(Boolean.FALSE); |
258 |
return context; |
return context; |