namespace System.Security {
public sealed class SecurityContext
-#if NET_4_0
: IDisposable
-#endif
{
private bool _capture;
private IntPtr _winid;
+
+#if !MOBILE
private CompressedStack _stack;
+#endif
private bool _suppressFlowWindowsIdentity;
private bool _suppressFlow;
static public SecurityContext Capture ()
{
+#if !MOBILE
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
if (sc.FlowSuppressed)
return null;
+#endif
SecurityContext capture = new SecurityContext ();
capture._capture = true;
return capture;
}
-#if NET_4_0
public void Dispose ()
{
}
-#endif
// internal stuff
set { _suppressFlowWindowsIdentity = value; }
}
+#if !MOBILE
internal CompressedStack CompressedStack {
get { return _stack; }
set { _stack = value; }
}
+#endif
internal IntPtr IdentityToken {
get { return _winid; }
static public bool IsFlowSuppressed ()
{
+#if MOBILE
+ return false;
+#else
return Thread.CurrentThread.ExecutionContext.SecurityContext.FlowSuppressed;
+#endif
}
static public bool IsWindowsIdentityFlowSuppressed ()
{
+#if MOBILE
+ return false;
+#else
return Thread.CurrentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed;
+#endif
}
static public void RestoreFlow ()
{
+#if !MOBILE
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
// if nothing is suppressed then throw
if (!sc.FlowSuppressed && !sc.WindowsIdentityFlowSuppressed)
sc.FlowSuppressed = false;
sc.WindowsIdentityFlowSuppressed = false;
+#endif
}
// if you got the context then you can use it
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
static public AsyncFlowControl SuppressFlow ()
{
+#if MOBILE
+ throw new NotSupportedException ();
+#else
Thread t = Thread.CurrentThread;
// suppress both flows
t.ExecutionContext.SecurityContext.FlowSuppressed = true;
t.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true;
return new AsyncFlowControl (t, AsyncFlowControlType.Security);
+#endif
}
static public AsyncFlowControl SuppressFlowWindowsIdentity ()
{
+#if MOBILE
+ throw new NotSupportedException ();
+#else
Thread t = Thread.CurrentThread;
t.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true;
return new AsyncFlowControl (t, AsyncFlowControlType.Security);
+#endif
}
}
}