WindowsIdentity Klass

Definition

Representerar en Windows användare.

public ref class WindowsIdentity : System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable, System::Security::Principal::IIdentity
public ref class WindowsIdentity : IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable, System::Security::Principal::IIdentity
public ref class WindowsIdentity : System::Security::Claims::ClaimsIdentity, IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
[System.Serializable]
public class WindowsIdentity : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable, System.Security.Principal.IIdentity
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsIdentity : IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable, System.Security.Principal.IIdentity
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsIdentity : System.Security.Claims.ClaimsIdentity, IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[<System.Serializable>]
type WindowsIdentity = class
    interface IIdentity
    interface ISerializable
    interface IDeserializationCallback
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsIdentity = class
    interface IIdentity
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsIdentity = class
    inherit ClaimsIdentity
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
Public Class WindowsIdentity
Implements IDeserializationCallback, IIdentity, ISerializable
Public Class WindowsIdentity
Implements IDeserializationCallback, IDisposable, IIdentity, ISerializable
Public Class WindowsIdentity
Inherits ClaimsIdentity
Implements IDeserializationCallback, IDisposable, ISerializable
Arv
WindowsIdentity
Arv
WindowsIdentity
Attribut
Implementeringar

Exempel

I följande exempel visas användningen av medlemmar i WindowsIdentity klassen. Ett exempel som visar hur du hämtar en Windows kontotoken via ett anrop till den ohanterade win32-LogonUser-funktionen och använder den token för att personifiera en annan användare finns i klassen WindowsImpersonationContext.

using namespace System;
using namespace System::Security::Principal;
void IntPtrConstructor( IntPtr logonToken );
void IntPtrStringConstructor( IntPtr logonToken );
void IntPrtStringTypeBoolConstructor( IntPtr logonToken );
void IntPtrStringTypeConstructor( IntPtr logonToken );
void UseProperties( IntPtr logonToken );
IntPtr LogonUser();
void GetAnonymousUser();
void ImpersonateIdentity( IntPtr logonToken );

[STAThread]
int main()
{
   
   // Retrieve the Windows account token for the current user.
   IntPtr logonToken = LogonUser();
   
   // Constructor implementations.
   IntPtrConstructor( logonToken );
   IntPtrStringConstructor( logonToken );
   IntPtrStringTypeConstructor( logonToken );
   IntPrtStringTypeBoolConstructor( logonToken );
   
   // Property implementations.
   UseProperties( logonToken );
   
   // Method implementations.
   GetAnonymousUser();
   ImpersonateIdentity( logonToken );
   Console::WriteLine( "This sample completed successfully; "
   "press Enter to exit." );
   Console::ReadLine();
}


// Create a WindowsIdentity object for the user represented by the
// specified Windows account token.
void IntPtrConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token.
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Create a WindowsIdentity object for the user represented by the
// specified account token and authentication type.
void IntPtrStringConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token 
   // and the specified authentication type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}



// Create a WindowsIdentity object for the user represented by the
// specified account token, authentication type and Windows account
// type.
void IntPtrStringTypeConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type and Windows account type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Create a WindowsIdentity object for the user represented by the
// specified account token, authentication type, Windows account type and
// Boolean authentication flag.
void IntPrtStringTypeBoolConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type, Windows account type, and
   // authentication flag.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   bool isAuthenticated = true;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount,isAuthenticated );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Access the properties of a WindowsIdentity object.
void UseProperties( IntPtr logonToken )
{
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   String^ propertyDescription = "The windows identity named ";
   
   // Retrieve the Windows logon name from the Windows identity object.
   propertyDescription = String::Concat( propertyDescription, windowsIdentity->Name );
   
   // Verify that the user account is not considered to be an Anonymous
   // account by the system.
   if (  !windowsIdentity->IsAnonymous )
   {
      propertyDescription = String::Concat( propertyDescription, ", is not an Anonymous account" );
   }

   
   // Verify that the user account has been authenticated by Windows.
   if ( windowsIdentity->IsAuthenticated )
   {
      propertyDescription = String::Concat( propertyDescription, ", is authenticated" );
   }
   
   // Verify that the user account is considered to be a System account
   // by the system.
   if ( windowsIdentity->IsSystem )
   {
      propertyDescription = String::Concat( propertyDescription, ", is a System account" );
   }
   
   // Verify that the user account is considered to be a Guest account
   // by the system.
   if ( windowsIdentity->IsGuest )
   {
      propertyDescription = String::Concat( propertyDescription, ", is a Guest account" );
   }
   
   // Retrieve the authentication type for the 
   String^ authenticationType = windowsIdentity->AuthenticationType;
   
   // Append the authenication type to the output message.
   if ( authenticationType != nullptr )
   {
      propertyDescription = String::Format( "{0} and uses {1} authentication type.", propertyDescription, authenticationType );
   }
   
   Console::WriteLine( propertyDescription );
}


// Retrieve the account token from the current WindowsIdentity object
// instead of calling the unmanaged LogonUser method in the advapi32.dll.
IntPtr LogonUser()
{
   
   IntPtr accountToken = WindowsIdentity::GetCurrent()->Token;
   
   return accountToken;
}


// Get the WindowsIdentity object for an Anonymous user.
void GetAnonymousUser()
{
   
   // Retrieve a WindowsIdentity object that represents an anonymous
   // Windows user.
   WindowsIdentity^ windowsIdentity = WindowsIdentity::GetAnonymous();
   
}


// Impersonate a Windows identity.
void ImpersonateIdentity( IntPtr logonToken )
{
   
   // Retrieve the Windows identity using the specified token.
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   
   // Create a WindowsImpersonationContext object by impersonating the
   // Windows identity.
   WindowsImpersonationContext^ impersonationContext = windowsIdentity->Impersonate();
   Console::WriteLine( "Name of the identity after impersonation: {0}.", WindowsIdentity::GetCurrent()->Name );
   
   // Stop impersonating the user.
   impersonationContext->Undo();
   
   // Check the identity name.
   Console::Write( "Name of the identity after performing an Undo on the" );
   Console::WriteLine( " impersonation: {0}", WindowsIdentity::GetCurrent()->Name );
}
using System;
using System.Security.Principal;

class WindowsIdentityMembers
{
    [STAThread]
    static void Main(string[] args)
    {
        // Retrieve the Windows account token for the current user.
        IntPtr logonToken = LogonUser();

        // Constructor implementations.
        IntPtrConstructor(logonToken);
        IntPtrStringConstructor(logonToken);
        IntPtrStringTypeConstructor(logonToken);
        IntPrtStringTypeBoolConstructor(logonToken);

        // Property implementations.
        UseProperties(logonToken);

        // Method implementations.
        GetAnonymousUser();
        ImpersonateIdentity(logonToken);

        Console.WriteLine("This sample completed successfully; " +
            "press Enter to exit.");
        Console.ReadLine();
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified Windows account token.
    private static void IntPtrConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token.
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token and authentication type.
    private static void IntPtrStringConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token 
        // and the specified authentication type.
        string authenticationType = "WindowsAuthentication";
        WindowsIdentity windowsIdentity =
                        new WindowsIdentity(logonToken, authenticationType);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token, authentication type, and Windows account
    // type.
    private static void IntPtrStringTypeConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token,
        // and the specified authentication type, and Windows account type.
        string authenticationType = "WindowsAuthentication";
        WindowsAccountType guestAccount = WindowsAccountType.Guest;
        WindowsIdentity windowsIdentity =
            new WindowsIdentity(logonToken, authenticationType, guestAccount);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token, authentication type, Windows account type, and
    // Boolean authentication flag.
    private static void IntPrtStringTypeBoolConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token,
        // and the specified authentication type, Windows account type, and
        // authentication flag.
        string authenticationType = "WindowsAuthentication";
        WindowsAccountType guestAccount = WindowsAccountType.Guest;
        bool isAuthenticated = true;
        WindowsIdentity windowsIdentity = new WindowsIdentity(
            logonToken, authenticationType, guestAccount, isAuthenticated);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }
    // Access the properties of a WindowsIdentity object.
    private static void UseProperties(IntPtr logonToken)
    {
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);
        string propertyDescription = "The Windows identity named ";

        // Retrieve the Windows logon name from the Windows identity object.
        propertyDescription += windowsIdentity.Name;

        // Verify that the user account is not considered to be an Anonymous
        // account by the system.
        if (!windowsIdentity.IsAnonymous)
        {
            propertyDescription += " is not an Anonymous account";
        }

        // Verify that the user account has been authenticated by Windows.
        if (windowsIdentity.IsAuthenticated)
        {
            propertyDescription += ", is authenticated";
        }

        // Verify that the user account is considered to be a System account
        // by the system.
        if (windowsIdentity.IsSystem)
        {
            propertyDescription += ", is a System account";
        }
        // Verify that the user account is considered to be a Guest account
        // by the system.
        if (windowsIdentity.IsGuest)
        {
            propertyDescription += ", is a Guest account";
        }

        // Retrieve the authentication type for the 
        String authenticationType = windowsIdentity.AuthenticationType;

        // Append the authenication type to the output message.
        if (authenticationType != null)
        {
            propertyDescription += (" and uses " + authenticationType);
            propertyDescription += (" authentication type.");
        }

        Console.WriteLine(propertyDescription);

        // Display the SID for the owner.
        Console.Write("The SID for the owner is : ");
        SecurityIdentifier si = windowsIdentity.Owner;
        Console.WriteLine(si.ToString());
        // Display the SIDs for the groups the current user belongs to.
        Console.WriteLine("Display the SIDs for the groups the current user belongs to.");
        IdentityReferenceCollection irc = windowsIdentity.Groups;
        foreach (IdentityReference ir in irc)
            Console.WriteLine(ir.Value);
        TokenImpersonationLevel token = windowsIdentity.ImpersonationLevel;
        Console.WriteLine("The impersonation level for the current user is : " + token.ToString());
    }

    // Retrieve the account token from the current WindowsIdentity object
    // instead of calling the unmanaged LogonUser method in the advapi32.dll.
    private static IntPtr LogonUser()
    {
        IntPtr accountToken = WindowsIdentity.GetCurrent().Token;
        Console.WriteLine( "Token number is: " + accountToken.ToString());

        return accountToken;
    }

    // Get the WindowsIdentity object for an Anonymous user.
    private static void GetAnonymousUser()
    {
        // Retrieve a WindowsIdentity object that represents an anonymous
        // Windows user.
        WindowsIdentity windowsIdentity = WindowsIdentity.GetAnonymous();
    }

    // Impersonate a Windows identity.
    private static void ImpersonateIdentity(IntPtr logonToken)
    {
        // Retrieve the Windows identity using the specified token.
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

        // Create a WindowsImpersonationContext object by impersonating the
        // Windows identity.
        WindowsImpersonationContext impersonationContext =
            windowsIdentity.Impersonate();

        Console.WriteLine("Name of the identity after impersonation: "
            + WindowsIdentity.GetCurrent().Name + ".");
        Console.WriteLine(windowsIdentity.ImpersonationLevel);
        // Stop impersonating the user.
        impersonationContext.Undo();

        // Check the identity name.
        Console.Write("Name of the identity after performing an Undo on the");
        Console.WriteLine(" impersonation: " +
            WindowsIdentity.GetCurrent().Name);
    }
}
Imports System.Security.Principal

Module Module1

    Sub Main()

        ' Retrieve the Windows account token for the current user.
        Dim logonToken As IntPtr = LogonUser()

        ' Constructor implementations.
        IntPtrConstructor(logonToken)
        IntPtrStringConstructor(logonToken)
        IntPtrStringTypeConstructor(logonToken)
        IntPrtStringTypeBoolConstructor(logonToken)

        ' Property implementations.
        UseProperties(logonToken)

        ' Method implementations.
        GetAnonymousUser()
        ImpersonateIdentity(logonToken)

        ' Align interface and conclude application.
        Console.WriteLine(vbCrLf + "This sample completed " + _
            "successfully; press Enter to exit.")
        Console.ReadLine()

    End Sub
    
    ' Create a WindowsIdentity object for the user represented by the
    ' specified Windows account token.
    Private Sub IntPtrConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token.
        Dim windowsIdentity As New WindowsIdentity(logonToken)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub
    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token and authentication type.
    Private Sub IntPtrStringConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token 
        ' and the specified authentication type
        Dim authenticationType = "WindowsAuthentication"
        Dim windowsIdentity As _
            New WindowsIdentity(logonToken, authenticationType)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub

    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token, authentication type, and Windows account
    ' type.
    Private Sub IntPtrStringTypeConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token,
        ' and the specified authentication type and Windows account type.
        Dim authenticationType As String = "WindowsAuthentication"
        Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
        Dim windowsIdentity As _
            New WindowsIdentity(logonToken, authenticationType, guestAccount)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub

    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token, authentication type, Windows account type,
    ' and Boolean authentication flag.
    Private Sub IntPrtStringTypeBoolConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token,
        ' and the specified authentication type, Windows account type, and
        ' authentication flag.
        Dim authenticationType As String = "WindowsAuthentication"
        Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
        Dim isAuthenticated As Boolean = True
        Dim windowsIdentity As New WindowsIdentity( _
            logonToken, authenticationType, guestAccount, isAuthenticated)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub
        
    ' Access the properties of a WindowsIdentity object.
    Private Sub UseProperties(ByVal logonToken As IntPtr)
        Dim windowsIdentity As New WindowsIdentity(logonToken)
        Dim propertyDescription As String = "The Windows identity named "

        ' Retrieve the Windows logon name from the Windows identity object.
        propertyDescription += windowsIdentity.Name

        ' Verify that the user account is not considered to be an Anonymous
        ' account by the system.
        If Not windowsIdentity.IsAnonymous Then
            propertyDescription += " is not an Anonymous account"
        End If

        ' Verify that the user account has been authenticated by Windows.
        If (windowsIdentity.IsAuthenticated) Then
            propertyDescription += ", is authenticated"
        End If

        ' Verify that the user account is considered to be a System account by
        ' the system.
        If (windowsIdentity.IsSystem) Then
            propertyDescription += ", is a System account"
        End If

        ' Verify that the user account is considered to be a Guest account by
        ' the system.
        If (windowsIdentity.IsGuest) Then
            propertyDescription += ", is a Guest account"
        End If
        Dim authenticationType As String = windowsIdentity.AuthenticationType

        ' Append the authenication type to the output message.
        If (Not authenticationType Is Nothing) Then
            propertyDescription += (" and uses " + authenticationType)
            propertyDescription += (" authentication type.")
        End If

        WriteLine(propertyDescription)

        ' Display the SID for the owner.
        Console.Write("The SID for the owner is : ")
        Dim si As SecurityIdentifier
        si = windowsIdentity.Owner
        Console.WriteLine(si.ToString())
        ' Display the SIDs for the groups the current user belongs to.
        Console.WriteLine("Display the SIDs for the groups the current user belongs to.")
        Dim irc As IdentityReferenceCollection
        Dim ir As IdentityReference
        irc = windowsIdentity.Groups
        For Each ir In irc
            Console.WriteLine(ir.Value)
        Next
        Dim token As TokenImpersonationLevel
        token = windowsIdentity.ImpersonationLevel
        Console.WriteLine("The impersonation level for the current user is : " + token.ToString())
    End Sub
    ' Retrieve the account token from the current WindowsIdentity object
    ' instead of calling the unmanaged LogonUser method in the advapi32.dll.
    Private Function LogonUser() As IntPtr
        Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token

        Return accountToken
    End Function

    ' Get the WindowsIdentity object for an Anonymous user.
    Private Sub GetAnonymousUser()
        ' Retrieve a WindowsIdentity object that represents an anonymous
        ' Windows user.
        Dim windowsIdentity As WindowsIdentity
        windowsIdentity = windowsIdentity.GetAnonymous()
    End Sub

    ' Impersonate a Windows identity.
    Private Sub ImpersonateIdentity(ByVal logonToken As IntPtr)
        ' Retrieve the Windows identity using the specified token.
        Dim windowsIdentity As New WindowsIdentity(logonToken)

        ' Create a WindowsImpersonationContext object by impersonating the
        ' Windows identity.
        Dim impersonationContext As WindowsImpersonationContext
        impersonationContext = windowsIdentity.Impersonate()

        WriteLine("Name of the identity after impersonation: " + _
            windowsIdentity.GetCurrent().Name + ".")

        ' Stop impersonating the user.
        impersonationContext.Undo()

        ' Check the identity.
        WriteLine("Name of the identity after performing an Undo on the " + _
            "impersonation: " + windowsIdentity.GetCurrent().Name + ".")
    End Sub
    ' Write out message with carriage return to output textbox.
    Private Sub WriteLine(ByVal message As String)
        Console.WriteLine(message + vbCrLf)
    End Sub

End Module

Kommentarer

GetCurrent Anropa metoden för att skapa ett WindowsIdentity objekt som representerar den aktuella användaren.

Important

Den här typen implementerar IDisposable gränssnittet. När du har använt typen bör du kassera den på ett direkt eller indirekt sätt. Om du vill ta bort typen direkt anropar du dess Dispose metod i ett try/catch block. Om du vill ta bort det indirekt använder du en språkkonstruktion som using (i C#) eller Using (i Visual Basic). Mer information finns i avsnittet "Använda ett objekt som implementerar IDisposable" i IDisposable gränssnittet.

Konstruktorer

Name Description
WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

Initierar en ny instans av klassen WindowsIdentity för användaren som representeras av den angivna Windows kontotoken, den angivna autentiseringstypen, den angivna Windows kontotypen och den angivna autentiseringsstatusen.

WindowsIdentity(IntPtr, String, WindowsAccountType)

Initierar en ny instans av klassen WindowsIdentity för användaren som representeras av den angivna Windows kontotoken, den angivna autentiseringstypen och den angivna Windows kontotypen.

WindowsIdentity(IntPtr, String)

Initierar en ny instans av klassen WindowsIdentity för användaren som representeras av den angivna Windows kontotoken och den angivna autentiseringstypen.

WindowsIdentity(IntPtr)

Initierar en ny instans av klassen WindowsIdentity för användaren som representeras av den angivna Windows kontotoken.

WindowsIdentity(SerializationInfo, StreamingContext)

Initierar en ny instans av WindowsIdentity klassen för användaren som representeras av information i en SerializationInfo dataström.

WindowsIdentity(String, String)

Initierar en ny instans av WindowsIdentity klassen för användaren som representeras av det angivna UPN (User Principal Name) och den angivna autentiseringstypen.

WindowsIdentity(String)

Initierar en ny instans av WindowsIdentity klassen för användaren som representeras av det angivna UPN (User Principal Name).

WindowsIdentity(WindowsIdentity)

Initierar en ny instans av WindowsIdentity klassen med hjälp av det angivna WindowsIdentity objektet.

Fält

Name Description
DefaultIssuer

Identifierar namnet på standardutfärdaren ClaimsIdentity .

DefaultNameClaimType

Standardnamnets anspråkstyp. Name.

(Ärvd från ClaimsIdentity)
DefaultRoleClaimType

Standardtypen för rollanspråk. Role.

(Ärvd från ClaimsIdentity)

Egenskaper

Name Description
AccessToken

Hämtar detta SafeAccessTokenHandle för den här instansen WindowsIdentity .

Actor

Hämtar eller anger identiteten för den anropande part som har beviljats delegeringsrättigheter.

(Ärvd från ClaimsIdentity)
AuthenticationType

Hämtar den typ av autentisering som används för att identifiera användaren.

BootstrapContext

Hämtar eller anger den token som användes för att skapa den här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
Claims

Hämtar alla anspråk för användaren som representeras av den här Windows identiteten.

CustomSerializationData

Innehåller ytterligare data som tillhandahålls av en härledd typ. Anges vanligtvis när du anropar WriteTo(BinaryWriter, Byte[]).

(Ärvd från ClaimsIdentity)
DeviceClaims

Hämtar anspråk som har egenskapsnyckeln WindowsDeviceClaim .

Groups

Hämtar de grupper som den aktuella Windows användaren tillhör.

ImpersonationLevel

Hämtar personifieringsnivån för användaren.

IsAnonymous

Hämtar ett värde som anger om användarkontot identifieras som ett anonymt konto av systemet.

IsAuthenticated

Hämtar ett värde som anger om användaren har autentiserats av Windows.

IsGuest

Hämtar ett värde som anger om användarkontot identifieras som ett Guest konto av systemet.

IsSystem

Hämtar ett värde som anger om användarkontot identifieras som ett System konto av systemet.

Label

Hämtar eller anger etiketten för den här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
Name

Hämtar användarens Windows inloggningsnamn.

NameClaimType

Hämtar anspråkstypen som används för att avgöra vilka anspråk som anger värdet för egenskapen för den Name här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
Owner

Hämtar säkerhetsidentifieraren (SID) för tokenägaren.

RoleClaimType

Hämtar anspråkstypen som ska tolkas som en .NET roll bland anspråken i den här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
Token

Hämtar Windows kontotoken för användaren.

User

Hämtar säkerhetsidentifieraren (SID) för användaren.

UserClaims

Hämtar anspråk som har egenskapsnyckeln WindowsUserClaim .

Metoder

Name Description
AddClaim(Claim)

Lägger till ett enda anspråk i den här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
AddClaims(IEnumerable<Claim>)

Lägger till en lista över anspråk i den här anspråksidentiteten.

(Ärvd från ClaimsIdentity)
Clone()

Skapar ett nytt objekt som är en kopia av den aktuella instansen.

CreateClaim(BinaryReader)

Tillhandahåller en utökningspunkt för härledda typer för att skapa en anpassad Claim.

(Ärvd från ClaimsIdentity)
Dispose()

Släpper alla resurser som används av WindowsIdentity.

Dispose(Boolean)

Släpper de ohanterade resurser som används av WindowsIdentity och släpper eventuellt de hanterade resurserna.

Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
Finalize()

Frigör de resurser som innehas av den aktuella instansen.

FindAll(Predicate<Claim>)

Hämtar alla anspråk som matchas av det angivna predikatet.

(Ärvd från ClaimsIdentity)
FindAll(String)

Hämtar alla anspråk som har den angivna anspråkstypen.

(Ärvd från ClaimsIdentity)
FindFirst(Predicate<Claim>)

Hämtar det första anspråket som matchas av det angivna predikatet.

(Ärvd från ClaimsIdentity)
FindFirst(String)

Hämtar det första anspråket med den angivna anspråkstypen.

(Ärvd från ClaimsIdentity)
GetAnonymous()

Returnerar ett WindowsIdentity objekt som du kan använda som ett sentinel-värde i koden för att representera en anonym användare. Egenskapsvärdet representerar inte den inbyggda anonyma identitet som används av Windows operativsystem.

GetCurrent()

Returnerar ett WindowsIdentity-objekt som representerar den aktuella Windows användaren.

GetCurrent(Boolean)

Returnerar ett WindowsIdentity-objekt som representerar den Windows identiteten för antingen tråden eller processen, beroende på värdet för parametern ifImpersonating.

GetCurrent(TokenAccessLevels)

Returnerar ett WindowsIdentity-objekt som representerar den aktuella Windows användaren med hjälp av den angivna önskade tokenåtkomstnivån.

GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetObjectData(SerializationInfo, StreamingContext)

Fyller i SerializationInfo med data som behövs för att serialisera det aktuella ClaimsIdentity objektet.

(Ärvd från ClaimsIdentity)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
HasClaim(Predicate<Claim>)

Avgör om anspråksidentiteten har ett anspråk som matchas av det angivna predikatet.

(Ärvd från ClaimsIdentity)
HasClaim(String, String)

Avgör om anspråksidentiteten har ett anspråk med angiven anspråkstyp och värde.

(Ärvd från ClaimsIdentity)
Impersonate()

Personifierar användaren som representeras av WindowsIdentity objektet.

Impersonate(IntPtr)

Personifierar användaren som representeras av den angivna användartoken.

MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
RemoveClaim(Claim)

Försöker ta bort ett anspråk från anspråksidentiteten.

(Ärvd från ClaimsIdentity)
RunImpersonated(SafeAccessTokenHandle, Action)

Kör den angivna åtgärden som den personifierade Windows identiteten. I stället för att använda ett personifierat metodanrop och köra funktionen i WindowsImpersonationContextkan du använda RunImpersonated(SafeAccessTokenHandle, Action) och ange funktionen direkt som en parameter.

RunImpersonated<T>(SafeAccessTokenHandle, Func<T>)

Kör den angivna funktionen som den personifierade Windows identiteten. I stället för att använda ett personifierat metodanrop och köra funktionen i WindowsImpersonationContextkan du använda RunImpersonated(SafeAccessTokenHandle, Action) och ange funktionen direkt som en parameter.

ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)
TryRemoveClaim(Claim)

Försöker ta bort ett anspråk från anspråksidentiteten.

(Ärvd från ClaimsIdentity)
WriteTo(BinaryWriter, Byte[])

Serialiserar med hjälp av en BinaryWriter.

(Ärvd från ClaimsIdentity)
WriteTo(BinaryWriter)

Serialiserar med hjälp av en BinaryWriter.

(Ärvd från ClaimsIdentity)

Explicita gränssnittsimplementeringar

Name Description
IDeserializationCallback.OnDeserialization(Object)

Implementerar ISerializable gränssnittet och anropas tillbaka av deserialiseringshändelsen när deserialiseringen är klar.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Anger objektet SerializationInfo med den logiska kontextinformation som behövs för att återskapa en instans av den här körningskontexten.

Gäller för