WindowsIdentity Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe WindowsIdentity.
Surcharges
| Nom | Description |
|---|---|
| WindowsIdentity(IntPtr) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié. |
| WindowsIdentity(WindowsIdentity) |
Initialise une nouvelle instance de la WindowsIdentity classe à l’aide de l’objet spécifié WindowsIdentity . |
| WindowsIdentity(String) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le nom d’utilisateur principal (UPN) spécifié. |
| WindowsIdentity(IntPtr, String) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié et le type d’authentification spécifié. |
| WindowsIdentity(SerializationInfo, StreamingContext) |
Obsolète.
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par des informations dans un SerializationInfo flux. |
| WindowsIdentity(String, String) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le nom d’utilisateur principal (UPN) spécifié et le type d’authentification spécifié. |
| WindowsIdentity(IntPtr, String, WindowsAccountType) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié et le type de compte Windows spécifié. |
| WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean) |
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié, le type d’authentification spécifié, le type de compte Windows spécifié et l’état d’authentification spécifié. |
WindowsIdentity(IntPtr)
Initialise une nouvelle instance de la WindowsIdentity classe 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 dont le code est en cours d’exécution.
Exceptions
userToken est 0.
- ou -
userToken est dupliqué et non valide pour l’emprunt d’identité.
L’appelant n’a pas les autorisations appropriées.
- ou -
Une erreur Win32 s’est produite.
Remarques
Le tableau suivant présente les valeurs de propriété initiales d’une instance de WindowsIdentity.
| Propriété | Valeur initiale |
|---|---|
| AuthenticationType | Negotiate |
| WindowsAccountType | Normal |
| IsAuthenticated | false |
Note
Vous pouvez récupérer le jeton représenté par userToken l’appel de 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 WindowsIdentity classe à l’aide de l’objet spécifié WindowsIdentity .
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 construire la nouvelle instance de WindowsIdentity.
S’applique à
WindowsIdentity(String)
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le nom d’utilisateur principal (UPN) 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
UPN pour l’utilisateur dont le code est en cours d’exécution.
Exceptions
Windows a retourné le code d’état Windows NT STATUS_ACCESS_DENIED.
La mémoire est insuffisante.
L’appelant n’a pas les autorisations appropriées.
- ou -
L’ordinateur n’est pas attaché à 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 membre du domaine auquel l’ordinateur est attaché.
Remarques
Un UPN a le formatnom de domaine dunom d’utilisateur@.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’incapacité de se connecter à l’aide de l’UPN fournie.
Note
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. De plus, ce constructeur nécessite un accès en lecture à l’attribut TGGAU (token-groups-global-and-universal) sur le compte d’utilisateur cible.
S’applique à
WindowsIdentity(IntPtr, String)
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié et le type d’authentification spécifié.
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 dont le code est en cours d’exécution.
- type
- String
(Utilisation d’informations uniquement.) Type d’authentification utilisé pour identifier l’utilisateur.
Exceptions
userToken est 0.
- ou -
userToken est dupliqué et non valide pour l’emprunt d’identité.
L’appelant n’a pas les autorisations appropriées.
- ou -
Une erreur Win32 s’est produite.
Exemples
Le code suivant montre l’utilisation du WindowsIdentity constructeur pour créer une instance de la WindowsIdentity classe pour l’utilisateur 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 présente les valeurs de propriété initiales d’une 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 c’est nullle cas, le système de sécurité est défini AuthenticationTypeNegotiate sur Windows Vista et les versions ultérieures du système d’exploitation Windows, ainsi Kerberos que 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 uniquement d’une utilisation informationnelle.
Note
Vous pouvez récupérer le jeton représenté par userToken l’appel de 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 WindowsIdentity classe pour l’utilisateur représenté par des informations dans un SerializationInfo flux.
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);
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}")>]
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
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 pour l’utilisateur.
- context
- StreamingContext
Objet qui indique les caractéristiques du flux.
- Attributs
Exceptions
Impossible WindowsIdentity de sérialiser un processus à l’autre.
L’appelant n’a pas les autorisations appropriées.
- 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 uniquement avec des données approuvées. Pour plus d’informations, consultez Valider toutes les entrées.
S’applique à
WindowsIdentity(String, String)
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le nom d’utilisateur principal (UPN) spécifié et le type d’authentification spécifié.
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
UPN pour l’utilisateur dont le code est en cours d’exécution.
- type
- String
(Utilisation d’informations uniquement.) Type d’authentification utilisé pour identifier l’utilisateur.
Exceptions
Windows a retourné le code d’état Windows NT STATUS_ACCESS_DENIED.
La mémoire est insuffisante.
L’appelant n’a pas les autorisations appropriées.
- ou -
L’ordinateur n’est pas attaché à 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 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 c’est nullle cas, le système de sécurité est défini AuthenticationTypeNegotiate sur Windows Vista et les versions ultérieures du système d’exploitation Windows, ainsi Kerberos que 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 uniquement d’une utilisation informationnelle.
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’incapacité de se connecter à l’aide de l’UPN fournie.
Note
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. De plus, ce constructeur nécessite un accès en lecture à l’attribut TGGAU (token-groups-global-and-universal) sur le compte d’utilisateur cible.
S’applique à
WindowsIdentity(IntPtr, String, WindowsAccountType)
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié et le type de compte Windows spécifié.
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 dont le code est en cours d’exécution.
- type
- String
(Utilisation d’informations uniquement.) Type d’authentification utilisé pour identifier l’utilisateur.
- acctType
- WindowsAccountType
Une des valeurs d’énumération.
Exceptions
userToken est 0.
- ou -
userToken est dupliqué et non valide pour l’emprunt d’identité.
L’appelant n’a pas les autorisations appropriées.
- ou -
Une erreur Win32 s’est produite.
Exemples
Le code suivant montre l’utilisation du constructeur pour créer une instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification WindowsIdentity 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 présente les valeurs de propriété initiales d’une 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 c’est nullle cas, le système de sécurité est défini AuthenticationTypeNegotiate sur Windows Vista et les versions ultérieures du système d’exploitation Windows, ainsi Kerberos que 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 uniquement d’une utilisation informationnelle.
Note
Vous pouvez récupérer le jeton représenté par userToken l’appel de 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(IntPtr, String, WindowsAccountType, Boolean)
Initialise une nouvelle instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification spécifié, le type d’authentification spécifié, le type de compte Windows spécifié et l’état d’authentification spécifié.
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 dont le code est en cours d’exécution.
- type
- String
(Utilisation d’informations uniquement.) Type d’authentification utilisé pour identifier l’utilisateur.
- acctType
- WindowsAccountType
Une des valeurs d’énumération.
- isAuthenticated
- Boolean
true pour indiquer que l’utilisateur est authentifié ; sinon, false.
Exceptions
userToken est 0.
- ou -
userToken est dupliqué et non valide pour l’emprunt d’identité.
L’appelant n’a pas les autorisations appropriées.
- ou -
Une erreur Win32 s’est produite.
Exemples
Le code suivant montre l’utilisation du constructeur pour créer une instance de la WindowsIdentity classe pour l’utilisateur représenté par le jeton de compte Windows spécifié, le type d’authentification WindowsIdentity spécifié, le type de compte Windows spécifié et l’état 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 c’est nullle cas, le système de sécurité est défini AuthenticationTypeNegotiate sur Windows Vista et les versions ultérieures du système d’exploitation Windows, ainsi Kerberos que 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 uniquement d’une utilisation informationnelle.
Vous pouvez récupérer le jeton représenté par userToken l’appel de 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.