public static AccessControlContext getContext() {
// duplicates (if any) will be removed in ACC constructor
ProtectionDomain[] stack = getStackDomains();
Thread currThread = Thread.currentThread();
if (currThread == null || contexts == null) {
// Big boo time. No need to check anything ?
return new AccessControlContext(stack);
}
ArrayList< AccessControlContext > threadContexts;
synchronized (contexts) {
threadContexts = contexts.get(currThread);
}
AccessControlContext that;
if ((threadContexts == null) || (threadContexts.size() == 0)) {
// We were not in doPrivileged method, so
// have inherited context here
that = SecurityUtils.getContext(currThread);
} else {
// We were in doPrivileged method, so
// Use context passed to the doPrivileged()
that = threadContexts.get(threadContexts.size() - 1);
}
if (that != null && that.combiner != null) {
ProtectionDomain[] assigned = null;
if (that.context != null && that.context.length != 0) {
assigned = new ProtectionDomain[that.context.length];
System.arraycopy(that.context, 0, assigned, 0,
assigned.length);
}
ProtectionDomain[] allpds = that.combiner.combine(stack, assigned);
if (allpds == null) {
allpds = new ProtectionDomain[0];
}
return new AccessControlContext(allpds, that.combiner);
}
return new AccessControlContext(stack, that);
}
|