public void WindowsIdentity_() { Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); SecurityContext sc = SecurityContext.Capture(); Assert.IsNotNull(sc, "Capture"); }
internal static ExecutionContext Capture(bool captureSyncContext, bool nullOnEmpty) { ExecutionContext ec = Current; if (ec.FlowSuppressed) { return(null); } if (nullOnEmpty #if !MOBILE && ec._sc == null #endif && (ec._lcc == null || !ec._lcc.HasInfo)) { return(null); } ExecutionContext capture = new ExecutionContext(ec); #if !MOBILE if (SecurityManager.SecurityEnabled) { capture.SecurityContext = SecurityContext.Capture(); } #endif return(capture); }
public static void Run(ContextBody callback) { callback(); return; //WindowsIdentity.RunImpersonated(SafeAccessTokenHandle.InvalidHandle, () => callback()); return; SecurityContext.Run(SecurityContext.Capture(), delegate(object state) { WindowsImpersonationContext context = null; try { try { context = WindowsIdentity.Impersonate(IntPtr.Zero); callback(); } finally { if (context != null) { context.Undo(); } } } catch { throw; } }, null); }
public void Capture() { SecurityContext sc = SecurityContext.Capture(); Assert.IsNotNull(sc, "Capture"); AsyncFlowControl afc = SecurityContext.SuppressFlow(); Assert.IsTrue(SecurityContext.IsFlowSuppressed(), "IsFlowSuppressed-1"); try { sc = SecurityContext.Capture(); Assert.IsNull(sc, "Capture with SuppressFlow"); } finally { afc.Undo(); } afc = SecurityContext.SuppressFlowWindowsIdentity(); Assert.IsTrue(SecurityContext.IsWindowsIdentityFlowSuppressed(), "IsWindowsIdentityFlowSuppressed-1"); try { sc = SecurityContext.Capture(); Assert.IsNotNull(sc, "Capture with SuppressFlowWindowsIdentity"); } finally { afc.Undo(); } }
public static void RunFromRestrictedCasContext(ContextBody callback) { callback(); return; SecurityContext.Run(SecurityContext.Capture(), delegate(object state) { new SecurityPermission(SecurityPermissionFlag.ControlPrincipal | SecurityPermissionFlag.UnmanagedCode).Assert(); WindowsImpersonationContext context = null; try { try { context = WindowsIdentity.Impersonate(IntPtr.Zero); CodeAccessPermission.RevertAssert(); callback(); } finally { if (context != null) { context.Undo(); } } } catch { throw; } }, null); return; SecurityContext.Run(SecurityContext.Capture(), delegate(object state) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode | SecurityPermissionFlag.ControlPrincipal).Assert(); //WindowsImpersonationContext windowsImpersonationContext = null; try { try { WindowsIdentity.Impersonate(IntPtr.Zero); //windowsImpersonationContext = WindowsIdentity.Impersonate(IntPtr.Zero); //CodeAccessPermission.RevertAssert(); //WindowsIdentity.RunImpersonated(SafeAccessTokenHandle.InvalidHandle, () => callback()); //callback(); } finally { //if (windowsImpersonationContext != null) //{ // windowsImpersonationContext.Undo(); //} } } catch { throw; } }, null); }
internal static SecurityContext CaptureSecurityContextNoIdentityFlow() { if (SecurityContext.IsWindowsIdentityFlowSuppressed()) { return(SecurityContext.Capture()); } using (SecurityContext.SuppressFlowWindowsIdentity()) { return(SecurityContext.Capture()); } }
public void Run_SuppressFlow() { Assert.IsFalse(SecurityContext.IsFlowSuppressed()); AsyncFlowControl afc = SecurityContext.SuppressFlow(); Assert.IsTrue(SecurityContext.IsFlowSuppressed()); try { SecurityContext.Run(SecurityContext.Capture(), new ContextCallback(Callback), "Hello world."); } finally { afc.Undo(); } }
public void ExecutionContext_SuppressFlow() { Assert.IsFalse(ExecutionContext.IsFlowSuppressed(), "IsFlowSuppressed-1"); AsyncFlowControl afc = ExecutionContext.SuppressFlow(); try { Assert.IsTrue(ExecutionContext.IsFlowSuppressed(), "IsFlowSuppressed-2"); Assert.IsFalse(SecurityContext.IsFlowSuppressed(), "IsFlowSuppressed-3"); Assert.IsNotNull(SecurityContext.Capture(), "Capture"); } finally { afc.Undo(); } }
internal static SecurityContext CaptureSecurityContextNoIdentityFlow() { // capture the security context but never flow windows identity if (SecurityContext.IsWindowsIdentityFlowSuppressed()) { return(SecurityContext.Capture()); } else { using (SecurityContext.SuppressFlowWindowsIdentity()) { return(SecurityContext.Capture()); } } }
/// <summary>Captures the execution context from the current thread.</summary> /// <returns>An <see cref="T:System.Threading.ExecutionContext" /> object representing the execution context for the current thread.</returns> /// <filterpriority>1</filterpriority> public static ExecutionContext Capture() { ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext; if (executionContext.FlowSuppressed) { return(null); } ExecutionContext executionContext2 = new ExecutionContext(executionContext); if (SecurityManager.SecurityEnabled) { executionContext2.SecurityContext = SecurityContext.Capture(); } return(executionContext2); }
public void Copy() { SecurityContext sc = SecurityContext.Capture(); Assert.IsNotNull(sc, "Capture"); SecurityContext copy = sc.CreateCopy(); Assert.IsNotNull(copy, "Copy of Capture"); Assert.IsFalse(sc.Equals(copy)); Assert.IsFalse(copy.Equals(sc)); Assert.IsFalse(Object.ReferenceEquals(sc, copy)); SecurityContext copy2nd = copy.CreateCopy(); Assert.IsNotNull(copy2nd, "2nd level copy of Capture"); }
public static ExecutionContext Capture() { ExecutionContext ec = Thread.CurrentThread.ExecutionContext; if (ec.FlowSuppressed) { return(null); } ExecutionContext capture = new ExecutionContext(ec); #if (!NET_2_1 || MONOTOUCH) && !DISABLE_SECURITY if (SecurityManager.SecurityEnabled) { capture.SecurityContext = SecurityContext.Capture(); } #endif return(capture); }
public static ExecutionContext Capture() { ExecutionContext ec = Thread.CurrentThread.ExecutionContext; if (ec.FlowSuppressed) { return(null); } ExecutionContext capture = new ExecutionContext(ec); #if !MOONLIGHT if (SecurityManager.SecurityEnabled) { capture.SecurityContext = SecurityContext.Capture(); } #endif return(capture); }
internal static SecurityContext CaptureSecurityContextNoIdentityFlow() { SecurityContext securityContext; if (SecurityContext.IsWindowsIdentityFlowSuppressed()) { return(SecurityContext.Capture()); } AsyncFlowControl asyncFlowControl = SecurityContext.SuppressFlowWindowsIdentity(); try { securityContext = SecurityContext.Capture(); } finally { ((IDisposable)asyncFlowControl).Dispose(); } return(securityContext); }
public static ExecutionContext Capture() { ExecutionContext ec = Thread.CurrentThread.ExecutionContext; if (ec.FlowSuppressed) { return(null); } ExecutionContext capture = new ExecutionContext(ec); #if NOT_PFX if (SecurityManager.SecurityEnabled) { capture.SecurityContext = SecurityContext.Capture(); } // TODO: investigate this case #endif return(capture); }
internal static ExecutionContext Capture(bool captureSyncContext) { ExecutionContext ec = Thread.CurrentThread.ExecutionContext; if (ec.FlowSuppressed) { return(null); } ExecutionContext capture = new ExecutionContext(ec); #if !MOBILE if (SecurityManager.SecurityEnabled) { capture.SecurityContext = SecurityContext.Capture(); } #endif #if !MONOTOUCH capture.LogicalCallContext = CallContext.CreateLogicalCallContext(false); #endif return(capture); }
public void Run() { Assert.IsFalse(success, "pre-check"); SecurityContext.Run(SecurityContext.Capture(), new ContextCallback(Callback), true); Assert.IsTrue(success, "post-check"); }
static void Main() { SecurityContext.Run(SecurityContext.Capture(), new ContextCallback(Callback), "Hello world."); }
private SecurityContext GetSecurityContextUnmanaged() { return(SecurityContext.Capture()); // the Deny disappears with this stack frame but we got a capture of it }
private void Thread_Run_Empty() { Assert.IsFalse(success, "pre-check"); SecurityContext.Run(SecurityContext.Capture(), new ContextCallback(Callback), true); Assert.IsTrue(success, "post-check"); }
internal CimAsyncCancellationDisposable(CimOperation operation) { this._disposeThreadSafetyLock = new object(); this._securityContext = SecurityContext.Capture(); this._operation = operation; }