Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Security.​Principal.​WindowsIdentity
Assembly: System.Security.Principal.Windows
Inheritance: object → Claims.​ClaimsIdentity → WindowsIdentity
Implemented Interfaces
- IIdentity Implemented by: ClaimsIdentity
- IDisposable
- Runtime.​Serialization.​IDeserializationCallback
- Runtime.​Serialization.​ISerializable
Represents a Windows user.
Fields and Constants
public const
string
DefaultIssuer
Identifies the name of the default <see cref="T:System.Security.Claims.ClaimsIdentity" /> issuer.
Properties
public
Microsoft.​Win32.​SafeHandles.​SafeAccessTokenHandle
AccessToken
Gets this <see cref="T:Microsoft.Win32.SafeHandles.SafeAccessTokenHandle" /> for this <see cref="T:System.Security.Principal.WindowsIdentity" /> instance.
public
string
AuthenticationType
Gets the type of authentication used to identify the user.
public
Collections.​Generic.​IEnumerable<​Claims.​Claim>
Claims
Gets all claims for the user represented by this Windows identity.
public
Collections.​Generic.​IEnumerable<​Claims.​Claim>
DeviceClaims
Gets claims that have the <see cref="F:System.Security.Claims.ClaimTypes.WindowsDeviceClaim" /> property key.
public
IdentityReferenceCollection
Groups
Gets the groups the current Windows user belongs to.
public
TokenImpersonationLevel
ImpersonationLevel
Gets the impersonation level for the user.
public
bool
IsAnonymous
Gets a value that indicates whether the user account is identified as an anonymous account by the system.
public
bool
IsAuthenticated
Gets a value indicating whether the user has been authenticated by Windows.
public
bool
IsGuest
Gets a value indicating whether the user account is identified as a <see cref="F:System.Security.Principal.WindowsAccountType.Guest" /> account by the system.
public
bool
IsSystem
Gets a value indicating whether the user account is identified as a <see cref="F:System.Security.Principal.WindowsAccountType.System" /> account by the system.
public
string
Name
Gets the user's Windows logon name.
public
SecurityIdentifier
Owner
Gets the security identifier (SID) for the token owner.
public
nint
Token
Gets the Windows account token for the user.
public
SecurityIdentifier
User
Gets the security identifier (SID) for the user.
public
Collections.​Generic.​IEnumerable<​Claims.​Claim>
UserClaims
Gets claims that have the <see cref="F:System.Security.Claims.ClaimTypes.WindowsUserClaim" /> property key.
Actor
public
object
BootstrapContext
protected
byte[]
CustomSerializationData
public
string
Label
public
string
NameClaimType
public
string
RoleClaimType
Methods
Clone​()
Creates a new object that is a copy of the current instance.
Returns A copy of the current instance.
public
void
Dispose​()
Releases all resources used by the <see cref="T:System.Security.Principal.WindowsIdentity" /> .
protected
void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Security.Principal.WindowsIdentity" /> and optionally releases the managed resources.
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public static
WindowsIdentity
GetAnonymous​()
Returns a <see cref="T:System.Security.Principal.WindowsIdentity" /> object that you can use as a sentinel value in your code to represent an anonymous user. The property value does not represent the built-in anonymous identity used by the Windows operating system.
Returns An object that represents an anonymous user.
public static
WindowsIdentity
GetCurrent​()
Returns a <see cref="T:System.Security.Principal.WindowsIdentity" /> object that represents the current Windows user.
Returns An object that represents the current user.
public static
WindowsIdentity
GetCurrent​(bool ifImpersonating)
Returns a <see cref="T:System.Security.Principal.WindowsIdentity" /> object that represents the Windows identity for either the thread or the process, depending on the value of the <paramref name="ifImpersonating" /> parameter.
Returns An object that represents a Windows user.
ifImpersonating
<see langword="true" /> to return the <see cref="T:System.Security.Principal.WindowsIdentity" /> only if the thread is currently impersonating; <see langword="false" /> to return the <see cref="T:System.Security.Principal.WindowsIdentity" /> of the thread if it is impersonating or the <see cref="T:System.Security.Principal.WindowsIdentity" /> of the process if the thread is not currently impersonating.
public static
WindowsIdentity
GetCurrent​(TokenAccessLevels desiredAccess)
Returns a <see cref="T:System.Security.Principal.WindowsIdentity" /> object that represents the current Windows user, using the specified desired token access level.
Returns An object that represents the current user.
desiredAccess
A bitwise combination of the enumeration values.
public static
void
RunImpersonated​(Microsoft.​Win32.​SafeHandles.​SafeAccessTokenHandle safeAccessTokenHandle,
Action action)
Runs the specified action as the impersonated Windows identity. Instead of using an impersonated method call and running your function in <see cref="T:System.Security.Principal.WindowsImpersonationContext" /> , you can use <see cref="M:System.Security.Principal.WindowsIdentity.RunImpersonated(Microsoft.Win32.SafeHandles.SafeAccessTokenHandle,System.Action)" /> and provide your function directly as a parameter.
safeAccessTokenHandle
The SafeAccessTokenHandle of the impersonated Windows identity.
action
The System.Action to run.
public static
Threading.​Tasks.​Task
RunImpersonatedAsync​(Microsoft.​Win32.​SafeHandles.​SafeAccessTokenHandle safeAccessTokenHandle,
Func<​Threading.​Tasks.​Task> func)
Runs the specified asynchronous action as the impersonated Windows identity.
Returns A task that represents the asynchronous operation of the provided <see cref="T:System.Func`1" /> .
safeAccessTokenHandle
The handle of the impersonated Windows identity.
func
The function to run.
public static
Threading.​Tasks.​Task<​T>
RunImpersonatedAsync​(Microsoft.​Win32.​SafeHandles.​SafeAccessTokenHandle safeAccessTokenHandle,
Func<​Threading.​Tasks.​Task<​T>> func)
Runs the specified asynchronous action as the impersonated Windows identity.
Returns A task that represents the asynchronous operation of <paramref name="func" /> .
safeAccessTokenHandle
The handle of the impersonated Windows identity.
func
The function to run.
public static
T
RunImpersonated​(Microsoft.​Win32.​SafeHandles.​SafeAccessTokenHandle safeAccessTokenHandle,
Func<​T> func)
Runs the specified function as the impersonated Windows identity. Instead of using an impersonated method call and running your function in <see cref="T:System.Security.Principal.WindowsImpersonationContext" /> , you can use <see cref="M:System.Security.Principal.WindowsIdentity.RunImpersonated(Microsoft.Win32.SafeHandles.SafeAccessTokenHandle,System.Action)" /> and provide your function directly as a parameter.
Returns The result of the function.
safeAccessTokenHandle
The SafeAccessTokenHandle of the impersonated Windows identity.
func
The System.Func to run.
public
void
AddClaim​(Claims.​Claim claim)
Inherited from Claims.​ClaimsIdentity
public
void
AddClaims​(Collections.​Generic.​IEnumerable<​Claims.​Claim> claims)
Inherited from Claims.​ClaimsIdentity
protected
Claims.​Claim
CreateClaim​(IO.​BinaryReader reader)
Inherited from Claims.​ClaimsIdentity
public
Collections.​Generic.​IEnumerable<​Claims.​Claim>
FindAll​(Predicate<​Claims.​Claim> match)
Inherited from Claims.​ClaimsIdentity
public
Collections.​Generic.​IEnumerable<​Claims.​Claim>
FindAll​(string type)
Inherited from Claims.​ClaimsIdentity
public
Claims.​Claim
FindFirst​(Predicate<​Claims.​Claim> match)
Inherited from Claims.​ClaimsIdentity
public
Claims.​Claim
FindFirst​(string type)
Inherited from Claims.​ClaimsIdentity
protected
void
GetObjectData​(Runtime.​Serialization.​SerializationInfo info,
Runtime.​Serialization.​StreamingContext context)
Inherited from Claims.​ClaimsIdentity
public
bool
HasClaim​(Predicate<​Claims.​Claim> match)
Inherited from Claims.​ClaimsIdentity
public
bool
HasClaim​(string type,
string value)
Inherited from Claims.​ClaimsIdentity
public
void
RemoveClaim​(Claims.​Claim claim)
Inherited from Claims.​ClaimsIdentity
public
bool
TryRemoveClaim​(Claims.​Claim claim)
Inherited from Claims.​ClaimsIdentity
public
void
WriteTo​(IO.​BinaryWriter writer)
Inherited from Claims.​ClaimsIdentity
protected
void
WriteTo​(IO.​BinaryWriter writer,
byte[] userData)
Inherited from Claims.​ClaimsIdentity
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object