using System; using System.Security.Principal; using System.Threading; namespace System.Security { /// Encapsulates and propagates all security-related data for execution contexts transferred across threads. This class cannot be inherited. // Token: 0x020005CA RID: 1482 public sealed class SecurityContext { // Token: 0x06003610 RID: 13840 RVA: 0x000B8EEC File Offset: 0x000B70EC internal SecurityContext() { } // Token: 0x06003611 RID: 13841 RVA: 0x000B8EF4 File Offset: 0x000B70F4 internal SecurityContext(SecurityContext sc) { this._capture = true; this._winid = sc._winid; if (sc._stack != null) { this._stack = sc._stack.CreateCopy(); } } /// Creates a copy of the current security context. /// A object representing the security context for the current thread. /// The current security context has been previously used, was marshaled across application domains, or was not acquired through the method. // Token: 0x06003612 RID: 13842 RVA: 0x000B8F2C File Offset: 0x000B712C public SecurityContext CreateCopy() { if (!this._capture) { throw new InvalidOperationException(); } return new SecurityContext(this); } /// Captures the security context for the current thread. /// A object representing the security context for the current thread. // Token: 0x06003613 RID: 13843 RVA: 0x000B8F48 File Offset: 0x000B7148 public static SecurityContext Capture() { SecurityContext securityContext = Thread.CurrentThread.ExecutionContext.SecurityContext; if (securityContext.FlowSuppressed) { return null; } return new SecurityContext { _capture = true, _winid = WindowsIdentity.GetCurrentToken(), _stack = CompressedStack.Capture() }; } // Token: 0x17000A90 RID: 2704 // (get) Token: 0x06003614 RID: 13844 RVA: 0x000B8F98 File Offset: 0x000B7198 // (set) Token: 0x06003615 RID: 13845 RVA: 0x000B8FA0 File Offset: 0x000B71A0 internal bool FlowSuppressed { get { return this._suppressFlow; } set { this._suppressFlow = value; } } // Token: 0x17000A91 RID: 2705 // (get) Token: 0x06003616 RID: 13846 RVA: 0x000B8FAC File Offset: 0x000B71AC // (set) Token: 0x06003617 RID: 13847 RVA: 0x000B8FB4 File Offset: 0x000B71B4 internal bool WindowsIdentityFlowSuppressed { get { return this._suppressFlowWindowsIdentity; } set { this._suppressFlowWindowsIdentity = value; } } // Token: 0x17000A92 RID: 2706 // (get) Token: 0x06003618 RID: 13848 RVA: 0x000B8FC0 File Offset: 0x000B71C0 // (set) Token: 0x06003619 RID: 13849 RVA: 0x000B8FC8 File Offset: 0x000B71C8 internal CompressedStack CompressedStack { get { return this._stack; } set { this._stack = value; } } // Token: 0x17000A93 RID: 2707 // (get) Token: 0x0600361A RID: 13850 RVA: 0x000B8FD4 File Offset: 0x000B71D4 // (set) Token: 0x0600361B RID: 13851 RVA: 0x000B8FDC File Offset: 0x000B71DC internal IntPtr IdentityToken { get { return this._winid; } set { this._winid = value; } } /// Determines whether the flow of the security context has been suppressed. /// true if the flow has been suppressed; otherwise, false. // Token: 0x0600361C RID: 13852 RVA: 0x000B8FE8 File Offset: 0x000B71E8 public static bool IsFlowSuppressed() { return Thread.CurrentThread.ExecutionContext.SecurityContext.FlowSuppressed; } /// Determines whether the flow of the Windows identity portion of the current security context has been suppressed. /// true if the flow has been suppressed; otherwise, false. // Token: 0x0600361D RID: 13853 RVA: 0x000B9000 File Offset: 0x000B7200 public static bool IsWindowsIdentityFlowSuppressed() { return Thread.CurrentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed; } /// Restores the flow of the security context across asynchronous threads. /// The security context is null or an empty string. // Token: 0x0600361E RID: 13854 RVA: 0x000B9018 File Offset: 0x000B7218 public static void RestoreFlow() { SecurityContext securityContext = Thread.CurrentThread.ExecutionContext.SecurityContext; if (!securityContext.FlowSuppressed && !securityContext.WindowsIdentityFlowSuppressed) { throw new InvalidOperationException(); } securityContext.FlowSuppressed = false; securityContext.WindowsIdentityFlowSuppressed = false; } /// Runs the specified method in the specified security context on the current thread. /// The to set. /// The delegate that represents the method to run in the specified security context. /// The object to pass to the callback method. /// /// is null.-or- was not acquired through a capture operation -or- has already been used as the argument to a method call. /// /// /// // Token: 0x0600361F RID: 13855 RVA: 0x000B9060 File Offset: 0x000B7260 public static void Run(SecurityContext securityContext, ContextCallback callback, object state) { if (securityContext == null) { throw new InvalidOperationException(Locale.GetText("Null SecurityContext")); } SecurityContext securityContext2 = Thread.CurrentThread.ExecutionContext.SecurityContext; IPrincipal currentPrincipal = Thread.CurrentPrincipal; try { if (securityContext2.IdentityToken != IntPtr.Zero) { Thread.CurrentPrincipal = new WindowsPrincipal(new WindowsIdentity(securityContext2.IdentityToken)); } if (securityContext.CompressedStack != null) { CompressedStack.Run(securityContext.CompressedStack, callback, state); } else { callback(state); } } finally { if (currentPrincipal != null && securityContext2.IdentityToken != IntPtr.Zero) { Thread.CurrentPrincipal = currentPrincipal; } } } /// Suppresses the flow of the security context across asynchronous threads. /// An structure for restoring the flow. /// /// /// // Token: 0x06003620 RID: 13856 RVA: 0x000B912C File Offset: 0x000B732C public static AsyncFlowControl SuppressFlow() { Thread currentThread = Thread.CurrentThread; currentThread.ExecutionContext.SecurityContext.FlowSuppressed = true; currentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true; return new AsyncFlowControl(currentThread, AsyncFlowControlType.Security); } /// Suppresses the flow of the Windows identity portion of the current security context across asynchronous threads. /// An structure for restoring the flow. /// /// /// // Token: 0x06003621 RID: 13857 RVA: 0x000B9168 File Offset: 0x000B7368 public static AsyncFlowControl SuppressFlowWindowsIdentity() { Thread currentThread = Thread.CurrentThread; currentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true; return new AsyncFlowControl(currentThread, AsyncFlowControlType.Security); } // Token: 0x04001623 RID: 5667 private bool _capture; // Token: 0x04001624 RID: 5668 private IntPtr _winid; // Token: 0x04001625 RID: 5669 private CompressedStack _stack; // Token: 0x04001626 RID: 5670 private bool _suppressFlowWindowsIdentity; // Token: 0x04001627 RID: 5671 private bool _suppressFlow; } }