namespace System.Security {
-#if NET_2_0
- public sealed class SecurityContext {
-#else
- internal sealed class SecurityContext {
-#endif
+ public sealed class SecurityContext
+ : IDisposable
+ {
private bool _capture;
private IntPtr _winid;
+
+#if !MOBILE
private CompressedStack _stack;
+#endif
private bool _suppressFlowWindowsIdentity;
private bool _suppressFlow;
internal SecurityContext (SecurityContext sc)
{
_capture = true;
+#if !MOBILE
_winid = sc._winid;
if (sc._stack != null)
_stack = sc._stack.CreateCopy ();
+#endif
}
public SecurityContext CreateCopy ()
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;
+#if !MOBILE
capture._winid = WindowsIdentity.GetCurrentToken ();
capture._stack = CompressedStack.Capture ();
+#endif
return capture;
}
+
+ public void Dispose ()
+ {
+ }
// 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 NET_2_0
+
// if you got the context then you can use it
[SecurityPermission (SecurityAction.Assert, ControlPrincipal = true)]
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
throw new InvalidOperationException (Locale.GetText (
"Null SecurityContext"));
}
-
+#if MOBILE
+ callback (state);
+#else
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
IPrincipal original = Thread.CurrentPrincipal;
try {
if ((original != null) && (sc.IdentityToken != IntPtr.Zero))
Thread.CurrentPrincipal = original;
}
- }
#endif
+ }
+
[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
}
}
}