[System] Process.WaitForExit now triggers event Exited.
[mono.git] / mcs / class / corlib / System.Security / SecurityContext.cs
index 375cdf3eddcb13d06643c071e2ebf23adfa1f23b..7d3f942fc8c473953e535a97bec25ce3065939b1 100644 (file)
@@ -33,14 +33,15 @@ using System.Threading;
 
 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;
 
@@ -52,9 +53,11 @@ namespace System.Security {
                internal SecurityContext (SecurityContext sc)
                {
                        _capture = true;
+#if !MOBILE
                        _winid = sc._winid;
                        if (sc._stack != null)
                                _stack = sc._stack.CreateCopy ();
+#endif
                }
 
                public SecurityContext CreateCopy ()
@@ -69,16 +72,24 @@ namespace System.Security {
 
                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
 
@@ -92,10 +103,12 @@ namespace System.Security {
                        set { _suppressFlowWindowsIdentity = value; }
                }
 
+#if !MOBILE    
                internal CompressedStack CompressedStack {
                        get { return _stack; }
                        set { _stack = value; }
                }
+#endif
 
                internal IntPtr IdentityToken {
                        get { return _winid; }
@@ -106,16 +119,25 @@ namespace System.Security {
 
                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)
@@ -123,18 +145,21 @@ namespace System.Security {
 
                        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)]
-               static public void Run (SecurityContext securityContext, ContextCallback callBack, object state)
+               static public void Run (SecurityContext securityContext, ContextCallback callback, object state)
                {
                        if (securityContext == null) {
                                throw new InvalidOperationException (Locale.GetText (
                                        "Null SecurityContext"));
                        }
-
+#if MOBILE
+                       callback (state);
+#else
                        SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
                        IPrincipal original = Thread.CurrentPrincipal;
                        try {
@@ -145,31 +170,40 @@ namespace System.Security {
                                // FIXME: is the security manager isn't active then we may not have
                                // a compressed stack (bug #78652)
                                if (securityContext.CompressedStack != null)
-                                       CompressedStack.Run (securityContext.CompressedStack, callBack, state);
+                                       CompressedStack.Run (securityContext.CompressedStack, callback, state);
                                else
-                                       callBack (state);
+                                       callback (state);
                        }
                        finally {
                                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
                }
        }
 }