WindowsIdentity Constructeurs

Définition

Initialise une nouvelle instance de la classe WindowsIdentity.

Surcharges

WindowsIdentity(IntPtr)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows spécifié.

WindowsIdentity(WindowsIdentity)

Initialise une nouvelle instance de la classe WindowsIdentity à l'aide de l'objet WindowsIdentity spécifié.

WindowsIdentity(String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le nom d'utilisateur principal (UPN, User Principal Name) spécifié.

WindowsIdentity(IntPtr, String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows et le type d'authentification spécifiés.

WindowsIdentity(SerializationInfo, StreamingContext)
Obsolète.

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par des informations dans un flux SerializationInfo.

WindowsIdentity(String, String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le nom d'utilisateur principal (UPN) et le type d'authentification spécifiés.

WindowsIdentity(IntPtr, String, WindowsAccountType)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows, le type d'authentification et le type de compte Windows spécifiés.

WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows, le type d'authentification et le type de compte Windows et l'état d'authentification spécifiés.

WindowsIdentity(IntPtr)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows spécifié.

public:
 WindowsIdentity(IntPtr userToken);
public WindowsIdentity (IntPtr userToken);
new System.Security.Principal.WindowsIdentity : nativeint -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr)

Paramètres

userToken
IntPtr

nativeint

Jeton de compte pour l'utilisateur au nom duquel le code est en cours d'exécution.

Exceptions

userToken est égal à 0.

- ou -

userToken est dupliqué et non valide pour l'emprunt d'identité.

L’appelant n’a pas les autorisations requises.

- ou -

Une erreur Win32 s’est produite.

Remarques

Le tableau suivant montre les valeurs de propriété initiales d’un instance de WindowsIdentity.

Propriété Valeur initiale
AuthenticationType Negotiate
WindowsAccountType Normal
IsAuthenticated false

Notes

Vous pouvez récupérer le jeton représenté par userToken en appelant du code non managé tel que la fonction API LogonUser Windows. Toujours libérer userToken en appelant la fonction API CloseHandle Windows. Pour plus d’informations sur l’appel de code non managé, consultez Consommation de fonctions DLL non managées.

S’applique à

WindowsIdentity(WindowsIdentity)

Initialise une nouvelle instance de la classe WindowsIdentity à l'aide de l'objet WindowsIdentity spécifié.

protected:
 WindowsIdentity(System::Security::Principal::WindowsIdentity ^ identity);
protected WindowsIdentity (System.Security.Principal.WindowsIdentity identity);
new System.Security.Principal.WindowsIdentity : System.Security.Principal.WindowsIdentity -> System.Security.Principal.WindowsIdentity
Protected Sub New (identity As WindowsIdentity)

Paramètres

identity
WindowsIdentity

Objet à partir duquel la nouvelle instance de WindowsIdentity doit être créée.

S’applique à

WindowsIdentity(String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le nom d'utilisateur principal (UPN, User Principal Name) spécifié.

public:
 WindowsIdentity(System::String ^ sUserPrincipalName);
public WindowsIdentity (string sUserPrincipalName);
new System.Security.Principal.WindowsIdentity : string -> System.Security.Principal.WindowsIdentity
Public Sub New (sUserPrincipalName As String)

Paramètres

sUserPrincipalName
String

Nom d'utilisateur principal (UPN) au nom duquel le code est en cours d'exécution.

Exceptions

Windows a retourné le code d’état Windows NT STATUS_ACCESS_DENIED.

Il n’y a pas suffisamment de mémoire disponible.

L’appelant n’a pas les autorisations requises.

- ou -

L'ordinateur n'est pas joint à un domaine Windows 2003 ou ultérieur.

- ou -

L'ordinateur n'exécute pas Windows 2003 ou version ultérieure.

- ou -

L'utilisateur n'est pas un membre du domaine auquel l'ordinateur est attaché.

Remarques

Un UPN a le format nom d’utilisateur@domainname.com, en d’autres termes, une adresse e-mail. L’UPN identifié dans sUserPrincipalName est utilisé pour récupérer un jeton pour cet utilisateur via la fonction API LsaLogonUser Windows. À son tour, ce jeton est utilisé pour identifier l’utilisateur. Une exception peut être retournée en raison de l’impossibilité de se connecter à l’aide de l’UPN fourni.

Notes

Ce constructeur est destiné à être utilisé uniquement sur les ordinateurs joints à Des domaines Windows Server 2003 ou ultérieurs. Une exception est levée pour les types de domaine antérieurs. Cette restriction est due au fait que ce constructeur utilise la structure KERB_S4U_LOGON, qui a été introduite pour la première fois dans Windows Server 2003. En outre, ce constructeur nécessite un accès en lecture à l’attribut token-groups-global-and-universal (TGGAU) sur le compte d’utilisateur cible.

S’applique à

WindowsIdentity(IntPtr, String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows et le type d'authentification spécifiés.

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type);
public WindowsIdentity (IntPtr userToken, string type);
new System.Security.Principal.WindowsIdentity : nativeint * string -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String)

Paramètres

userToken
IntPtr

nativeint

Jeton de compte pour l'utilisateur au nom duquel le code est en cours d'exécution.

type
String

(Utilisation à titre informatif uniquement.) Type d'authentification utilisé pour identifier l'utilisateur.

Exceptions

userToken est égal à 0.

- ou -

userToken est dupliqué et non valide pour l'emprunt d'identité.

L’appelant n’a pas les autorisations requises.

- ou -

Une erreur Win32 s’est produite.

Exemples

Le code suivant montre l’utilisation du WindowsIdentity constructeur pour créer une nouvelle instance de la classe pour l’utilisateur WindowsIdentity représenté par le jeton de compte Windows spécifié et le type d’authentification spécifié. Cet exemple de code fait partie d’un exemple plus grand fourni pour la WindowsIdentity classe .

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 );
}
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 + ".");
}
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

Remarques

Le tableau suivant montre les valeurs de propriété initiales d’un instance de WindowsIdentity.

Propriété Valeur initiale
WindowsAccountType Normal
IsAuthenticated false

La valeur du type paramètre est utilisée pour définir le AuthenticationType paramètre. Si type est null, le système de sécurité définit NegotiateAuthenticationType sur sur Windows Vista et versions ultérieures du système d’exploitation Windows, et Kerberos sur les versions antérieures du système d’exploitation Windows. Le système de sécurité n’utilise pas cette valeur ; il s’agit d’un usage d’information uniquement.

Notes

Vous pouvez récupérer le jeton représenté par userToken en appelant du code non managé tel que la fonction API LogonUser Windows. Toujours libérer userToken en appelant la fonction API CloseHandle Windows. Pour plus d’informations sur l’appel de code non managé, consultez Consommation de fonctions DLL non managées.

S’applique à

WindowsIdentity(SerializationInfo, StreamingContext)

Attention

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par des informations dans un flux SerializationInfo.

public:
 WindowsIdentity(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public WindowsIdentity (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public WindowsIdentity (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
Public Sub New (info As SerializationInfo, context As StreamingContext)

Paramètres

info
SerializationInfo

Objet contenant les informations de compte de l'utilisateur.

context
StreamingContext

Objet qui indique les caractéristiques du flux.

Attributs

Exceptions

Aucun WindowsIdentity ne peut être sérialisé entre les processus.

L’appelant n’a pas les autorisations requises.

- ou -

Une erreur Win32 s’est produite.

Remarques

Important

L’appel de cette méthode avec des données non approuvées est un risque de sécurité. Appelez cette méthode avec des données approuvées uniquement. Pour plus d’informations, consultez Valider toutes les entrées.

S’applique à

WindowsIdentity(String, String)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le nom d'utilisateur principal (UPN) et le type d'authentification spécifiés.

public:
 WindowsIdentity(System::String ^ sUserPrincipalName, System::String ^ type);
public WindowsIdentity (string sUserPrincipalName, string type);
new System.Security.Principal.WindowsIdentity : string * string -> System.Security.Principal.WindowsIdentity
Public Sub New (sUserPrincipalName As String, type As String)

Paramètres

sUserPrincipalName
String

Nom d'utilisateur principal (UPN) au nom duquel le code est en cours d'exécution.

type
String

(Utilisation à titre informatif uniquement.) Type d'authentification utilisé pour identifier l'utilisateur.

Exceptions

Windows a retourné le code d’état Windows NT STATUS_ACCESS_DENIED.

Il n’y a pas suffisamment de mémoire disponible.

L’appelant n’a pas les autorisations requises.

- ou -

L'ordinateur n'est pas joint à un domaine Windows 2003 ou ultérieur.

- ou -

L'ordinateur n'exécute pas Windows 2003 ou version ultérieure.

- ou -

L'utilisateur n'est pas un membre du domaine auquel l'ordinateur est attaché.

Remarques

La valeur du type paramètre est utilisée pour définir le AuthenticationType paramètre . Si type a la valeur null, le système de sécurité définit AuthenticationTypeNegotiate sur sur Windows Vista et versions ultérieures du système d’exploitation Windows, et Kerberos sur les versions antérieures du système d’exploitation Windows. Le système de sécurité n’utilise pas cette valeur ; à des fins d’information uniquement.

L’UPN identifié dans sUserPrincipalName est utilisé pour récupérer un jeton pour cet utilisateur via la fonction API LsaLogonUser Windows. À son tour, ce jeton est utilisé pour identifier l’utilisateur. Une exception peut être retournée en raison de l’impossibilité de se connecter à l’aide de l’UPN fourni.

Notes

Ce constructeur est destiné à être utilisé uniquement sur les ordinateurs joints à des domaines Windows Server 2003 ou ultérieur. Une exception est levée pour les types de domaine antérieurs. Cette restriction est due au fait que ce constructeur utilise la structure KERB_S4U_LOGON, qui a été introduite pour la première fois dans Windows Server 2003. En outre, ce constructeur nécessite un accès en lecture à l’attribut token-groups-global-and-universal (TGGAU) sur le compte d’utilisateur cible.

S’applique à

WindowsIdentity(IntPtr, String, WindowsAccountType)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows, le type d'authentification et le type de compte Windows spécifiés.

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type, System::Security::Principal::WindowsAccountType acctType);
public WindowsIdentity (IntPtr userToken, string type, System.Security.Principal.WindowsAccountType acctType);
new System.Security.Principal.WindowsIdentity : nativeint * string * System.Security.Principal.WindowsAccountType -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String, acctType As WindowsAccountType)

Paramètres

userToken
IntPtr

nativeint

Jeton de compte pour l'utilisateur au nom duquel le code est en cours d'exécution.

type
String

(Utilisation à titre informatif uniquement.) Type d'authentification utilisé pour identifier l'utilisateur.

acctType
WindowsAccountType

Une des valeurs de l'énumération.

Exceptions

userToken est égal à 0.

- ou -

userToken est dupliqué et non valide pour l'emprunt d'identité.

L’appelant n’a pas les autorisations requises.

- ou -

Une erreur Win32 s’est produite.

Exemples

Le code suivant illustre l’utilisation du WindowsIdentity constructeur pour créer un instance de la classe pour l’utilisateur WindowsIdentity représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié et le type de compte Windows spécifié. Cet exemple de code fait partie d’un exemple plus grand fourni pour la WindowsIdentity classe .

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 );
}
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 + ".");
}
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

Remarques

Le tableau suivant montre les valeurs de propriété initiales d’un instance de WindowsIdentity.

Propriété Valeur initiale
IsAuthenticated false

La valeur du type paramètre est utilisée pour définir le AuthenticationType paramètre . Si type a la valeur null, le système de sécurité définit AuthenticationTypeNegotiate sur sur Windows Vista et versions ultérieures du système d’exploitation Windows, et Kerberos sur les versions antérieures du système d’exploitation Windows. Le système de sécurité n’utilise pas cette valeur ; à des fins d’information uniquement.

Notes

Vous pouvez récupérer le jeton représenté par userToken en appelant du code non managé tel que la fonction API LogonUser Windows. Libérez userToken toujours en appelant la fonction API CloseHandle Windows. Pour plus d’informations sur l’appel du code non managé, consultez Consommation de fonctions DLL non managées.

S’applique à

WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

Initialise une nouvelle instance de la classe WindowsIdentity pour l'utilisateur représenté par le jeton de compte Windows, le type d'authentification et le type de compte Windows et l'état d'authentification spécifiés.

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type, System::Security::Principal::WindowsAccountType acctType, bool isAuthenticated);
public WindowsIdentity (IntPtr userToken, string type, System.Security.Principal.WindowsAccountType acctType, bool isAuthenticated);
new System.Security.Principal.WindowsIdentity : nativeint * string * System.Security.Principal.WindowsAccountType * bool -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String, acctType As WindowsAccountType, isAuthenticated As Boolean)

Paramètres

userToken
IntPtr

nativeint

Jeton de compte pour l'utilisateur au nom duquel le code est en cours d'exécution.

type
String

(Utilisation à titre informatif uniquement.) Type d'authentification utilisé pour identifier l'utilisateur.

acctType
WindowsAccountType

Une des valeurs de l'énumération.

isAuthenticated
Boolean

true pour indiquer que l'utilisateur est identifié ; sinon, false.

Exceptions

userToken est égal à 0.

- ou -

userToken est dupliqué et non valide pour l'emprunt d'identité.

L’appelant n’a pas les autorisations requises.

- ou -

Une erreur Win32 s’est produite.

Exemples

Le code suivant illustre l’utilisation du WindowsIdentity constructeur pour créer une nouvelle instance de la classe pour l’utilisateur WindowsIdentity représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié, le type de compte Windows spécifié et le status d’authentification spécifié. Cet exemple de code fait partie d’un exemple plus grand fourni pour la WindowsIdentity classe .

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 );
}
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 + ".");
}
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

Remarques

La valeur du type paramètre est utilisée pour définir le AuthenticationType paramètre . Si type a la valeur null, le système de sécurité définit AuthenticationTypeNegotiate sur sur Windows Vista et versions ultérieures du système d’exploitation Windows, et Kerberos sur les versions antérieures du système d’exploitation Windows. Le système de sécurité n’utilise pas cette valeur ; à des fins d’information uniquement.

Vous pouvez récupérer le jeton représenté par userToken en appelant du code non managé tel que la fonction API LogonUser Windows. Libérez userToken toujours en appelant la fonction API CloseHandle Windows. Pour plus d’informations sur l’appel du code non managé, consultez Consommation de fonctions DLL non managées.

S’applique à