Files
Dec2017-Script-Dump/mscorlib/System/Security/SecurityContext.cs
T
2026-06-04 11:42:34 +02:00

233 lines
8.9 KiB
C#

using System;
using System.Security.Principal;
using System.Threading;
namespace System.Security
{
/// <summary>Encapsulates and propagates all security-related data for execution contexts transferred across threads. This class cannot be inherited.</summary>
// 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();
}
}
/// <summary>Creates a copy of the current security context.</summary>
/// <returns>A <see cref="T:System.Security.SecurityContext" /> object representing the security context for the current thread.</returns>
/// <exception cref="T:System.InvalidOperationException">The current security context has been previously used, was marshaled across application domains, or was not acquired through the <see cref="M:System.Security.SecurityContext.Capture" /> method.</exception>
// Token: 0x06003612 RID: 13842 RVA: 0x000B8F2C File Offset: 0x000B712C
public SecurityContext CreateCopy()
{
if (!this._capture)
{
throw new InvalidOperationException();
}
return new SecurityContext(this);
}
/// <summary>Captures the security context for the current thread.</summary>
/// <returns>A <see cref="T:System.Security.SecurityContext" /> object representing the security context for the current thread.</returns>
// 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;
}
}
/// <summary>Determines whether the flow of the security context has been suppressed.</summary>
/// <returns>true if the flow has been suppressed; otherwise, false. </returns>
// Token: 0x0600361C RID: 13852 RVA: 0x000B8FE8 File Offset: 0x000B71E8
public static bool IsFlowSuppressed()
{
return Thread.CurrentThread.ExecutionContext.SecurityContext.FlowSuppressed;
}
/// <summary>Determines whether the flow of the Windows identity portion of the current security context has been suppressed.</summary>
/// <returns>true if the flow has been suppressed; otherwise, false. </returns>
// Token: 0x0600361D RID: 13853 RVA: 0x000B9000 File Offset: 0x000B7200
public static bool IsWindowsIdentityFlowSuppressed()
{
return Thread.CurrentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed;
}
/// <summary>Restores the flow of the security context across asynchronous threads.</summary>
/// <exception cref="T:System.InvalidOperationException">The security context is null or an empty string.</exception>
// 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;
}
/// <summary>Runs the specified method in the specified security context on the current thread.</summary>
/// <param name="securityContext">The <see cref="T:System.Security.SecurityContext" /> to set.</param>
/// <param name="callback">The <see cref="T:System.Threading.ContextCallback" /> delegate that represents the method to run in the specified security context.</param>
/// <param name="state">The object to pass to the callback method.</param>
/// <exception cref="T:System.InvalidOperationException">
/// <paramref name="securityContext" /> is null.-or-<paramref name="securityContext" /> was not acquired through a capture operation -or-<paramref name="securityContext" /> has already been used as the argument to a <see cref="M:System.Security.SecurityContext.Run(System.Security.SecurityContext,System.Threading.ContextCallback,System.Object)" /> method call.</exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
/// </PermissionSet>
// 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;
}
}
}
/// <summary>Suppresses the flow of the security context across asynchronous threads.</summary>
/// <returns>An <see cref="T:System.Threading.AsyncFlowControl" /> structure for restoring the flow.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
/// </PermissionSet>
// 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);
}
/// <summary>Suppresses the flow of the Windows identity portion of the current security context across asynchronous threads.</summary>
/// <returns>An <see cref="T:System.Threading.AsyncFlowControl" /> structure for restoring the flow.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
/// </PermissionSet>
// 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;
}
}