45 throw new NotImplementedException();
47 var array =
new List<global::java.security.ProtectionDomain>();
48 var is_privileged = GetProtectionDomains(array, callerID,
new StackTrace(1));
50 if (is_privileged && context ==
null)
53 return CreateAccessControlContext(array, is_privileged, context);
59 static bool GetProtectionDomains(List<global::java.security.ProtectionDomain> array, global::ikvm.@
internal.
CallerID callerID, StackTrace stack)
64 for (; skip < stack.FrameCount; skip++)
66 Type type = stack.GetFrame(skip).GetMethod().DeclaringType;
67 if (type != typeof(
AccessController) && type != typeof(global::java.security.AccessController))
72 global::java.security.ProtectionDomain previous_protection_domain =
null;
73 for (
int i = skip; i < stack.FrameCount; i++)
75 bool is_privileged =
false;
76 global::java.security.ProtectionDomain protection_domain;
77 var method = stack.GetFrame(i).GetMethod();
78 if (method.DeclaringType == typeof(global::java.security.AccessController) && method.Name ==
"doPrivileged")
81 global::java.lang.Class caller = callerID.getCallerClass();
90 protection_domain = GetProtectionDomainFromType(method.DeclaringType);
93 if (previous_protection_domain != protection_domain && protection_domain !=
null)
95 previous_protection_domain = protection_domain;
96 array.Add(protection_domain);
108 static object CreateAccessControlContext(List<global::java.security.ProtectionDomain> context,
bool is_privileged, global::java.security.AccessControlContext privileged_context)
110 var acc =
new global::java.security.AccessControlContext(context ==
null || context.Count == 0 ?
null : context.ToArray(), is_privileged);
111 acc._privilegedContext(privileged_context);
115 static global::java.security.ProtectionDomain GetProtectionDomainFromType(
Type type)
117 if (type ==
null || type.Assembly == typeof(
object).
Assembly || type.Assembly == typeof(AccessController).
Assembly || type.Assembly == typeof(global::java.lang.Thread).Assembly)
136 throw new NotImplementedException();
138 var inheritedAccessControlContext = global::java.lang.Thread.currentThread().inheritedAccessControlContext;
139 var acc = inheritedAccessControlContext as global::java.security.AccessControlContext;
143 var lc = inheritedAccessControlContext as global::java.security.AccessController.LazyContext;
147 var list =
new List<global::java.security.ProtectionDomain>();
150 if (GetProtectionDomains(list, lc.callerID, lc.stackTrace))
151 return CreateAccessControlContext(list,
true, lc.context);
156 return CreateAccessControlContext(list,
false,
null);