WindowsPrincipal Classe
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.
Permet au code de vérifier l’appartenance au groupe Windows d’un utilisateur Windows.
public ref class WindowsPrincipal : System::Security::Claims::ClaimsPrincipal
public ref class WindowsPrincipal : System::Security::Principal::IPrincipal
public class WindowsPrincipal : System.Security.Claims.ClaimsPrincipal
[System.Serializable]
public class WindowsPrincipal : System.Security.Principal.IPrincipal
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsPrincipal : System.Security.Principal.IPrincipal
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsPrincipal : System.Security.Claims.ClaimsPrincipal
type WindowsPrincipal = class
inherit ClaimsPrincipal
[<System.Serializable>]
type WindowsPrincipal = class
interface IPrincipal
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsPrincipal = class
interface IPrincipal
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsPrincipal = class
inherit ClaimsPrincipal
Public Class WindowsPrincipal
Inherits ClaimsPrincipal
Public Class WindowsPrincipal
Implements IPrincipal
- Héritage
- Héritage
-
WindowsPrincipal
- Attributs
- Implémente
Exemples
L’exemple suivant montre comment utiliser les IsInRole surcharges de méthode. L’énumération WindowsBuiltInRole est utilisée comme source pour les identificateurs relatifs (RID) qui identifient les rôles intégrés. Les RID sont utilisés pour déterminer les rôles du principal actuel.
public:
static void DemonstrateWindowsBuiltInRoleEnum()
{
AppDomain^ myDomain = Thread::GetDomain();
myDomain->SetPrincipalPolicy( PrincipalPolicy::WindowsPrincipal );
WindowsPrincipal^ myPrincipal = dynamic_cast<WindowsPrincipal^>(Thread::CurrentPrincipal);
Console::WriteLine( "{0} belongs to: ", myPrincipal->Identity->Name );
Array^ wbirFields = Enum::GetValues( WindowsBuiltInRole::typeid );
for each ( Object^ roleName in wbirFields )
{
try
{
Console::WriteLine( "{0}? {1}.", roleName,
myPrincipal->IsInRole( *dynamic_cast<WindowsBuiltInRole^>(roleName) ) );
}
catch ( Exception^ )
{
Console::WriteLine( "{0}: Could not obtain role for this RID.",
roleName );
}
}
}
using System;
using System.Threading;
using System.Security.Permissions;
using System.Security.Principal;
class SecurityPrincipalDemo
{
public static void DemonstrateWindowsBuiltInRoleEnum()
{
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString());
Array wbirFields = Enum.GetValues(typeof(WindowsBuiltInRole));
foreach (object roleName in wbirFields)
{
try
{
// Cast the role name to a RID represented by the WindowsBuildInRole value.
Console.WriteLine("{0}? {1}.", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
Console.WriteLine("The RID for this role is: " + ((int)roleName).ToString());
}
catch (Exception)
{
Console.WriteLine("{0}: Could not obtain role for this RID.",
roleName);
}
}
// Get the role using the string value of the role.
Console.WriteLine("{0}? {1}.", "Administrators",
myPrincipal.IsInRole("BUILTIN\\" + "Administrators"));
Console.WriteLine("{0}? {1}.", "Users",
myPrincipal.IsInRole("BUILTIN\\" + "Users"));
// Get the role using the WindowsBuiltInRole enumeration value.
Console.WriteLine("{0}? {1}.", WindowsBuiltInRole.Administrator,
myPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
// Get the role using the WellKnownSidType.
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
Console.WriteLine("WellKnownSidType BuiltinAdministratorsSid {0}? {1}.", sid.Value, myPrincipal.IsInRole(sid));
}
public static void Main()
{
DemonstrateWindowsBuiltInRoleEnum();
}
}
Imports System.Threading
Imports System.Security.Permissions
Imports System.Security.Principal
Class SecurityPrincipalDemo
Public Shared Sub DemonstrateWindowsBuiltInRoleEnum()
Dim myDomain As AppDomain = Thread.GetDomain()
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
Dim myPrincipal As WindowsPrincipal = CType(Thread.CurrentPrincipal, WindowsPrincipal)
Console.WriteLine("{0} belongs to: ", myPrincipal.Identity.Name.ToString())
Dim wbirFields As Array = [Enum].GetValues(GetType(WindowsBuiltInRole))
Dim roleName As Object
For Each roleName In wbirFields
Try
' Cast the role name to a RID represented by the WindowsBuildInRole value.
Console.WriteLine("{0}? {1}.", roleName, myPrincipal.IsInRole(CType(roleName, WindowsBuiltInRole)))
Console.WriteLine("The RID for this role is: " + Fix(roleName).ToString())
Catch
Console.WriteLine("{0}: Could not obtain role for this RID.", roleName)
End Try
Next roleName
' Get the role using the string value of the role.
Console.WriteLine("{0}? {1}.", "Administrators", myPrincipal.IsInRole("BUILTIN\" + "Administrators"))
Console.WriteLine("{0}? {1}.", "Users", myPrincipal.IsInRole("BUILTIN\" + "Users"))
' Get the role using the WindowsBuiltInRole enumeration value.
Console.WriteLine("{0}? {1}.", WindowsBuiltInRole.Administrator, myPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
' Get the role using the WellKnownSidType.
Dim sid As New SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, Nothing)
Console.WriteLine("WellKnownSidType BuiltinAdministratorsSid {0}? {1}.", sid.Value, myPrincipal.IsInRole(sid))
End Sub
Public Shared Sub Main()
DemonstrateWindowsBuiltInRoleEnum()
End Sub
End Class
Remarques
La classe WindowsPrincipal est principalement utilisée pour vérifier le rôle d’un utilisateur Windows. Les WindowsPrincipal.IsInRole surcharges de méthode vous permettent de vérifier le rôle d’utilisateur à l’aide de différents contextes de rôle.
Constructeurs
| Nom | Description |
|---|---|
| WindowsPrincipal(WindowsIdentity) |
Initialise une nouvelle instance de la WindowsPrincipal classe à l’aide de l’objet spécifié WindowsIdentity . |
Propriétés
| Nom | Description |
|---|---|
| Claims |
Obtient une collection qui contient toutes les revendications de toutes les identités de revendications associées à ce principal de revendications. (Hérité de ClaimsPrincipal) |
| CustomSerializationData |
Contient toutes les données supplémentaires fournies par un type dérivé. Généralement défini lors de l’appel WriteTo(BinaryWriter, Byte[]). (Hérité de ClaimsPrincipal) |
| DeviceClaims |
Obtient toutes les revendications d’appareil Windows de ce principal. |
| Identities |
Obtient une collection qui contient toutes les identités de revendications associées à ce principal de revendications. (Hérité de ClaimsPrincipal) |
| Identity |
Obtient l’identité du principal actuel. |
| UserClaims |
Obtient toutes les revendications d’utilisateur Windows de ce principal. |
Méthodes
| Nom | Description |
|---|---|
| AddIdentities(IEnumerable<ClaimsIdentity>) |
Ajoute les identités de revendications spécifiées à ce principal de revendications. (Hérité de ClaimsPrincipal) |
| AddIdentity(ClaimsIdentity) |
Ajoute l’identité de revendications spécifiée à ce principal de revendications. (Hérité de ClaimsPrincipal) |
| Clone() |
Retourne une copie de cette instance. (Hérité de ClaimsPrincipal) |
| CreateClaimsIdentity(BinaryReader) |
Crée une identité de revendications. (Hérité de ClaimsPrincipal) |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| FindAll(Predicate<Claim>) |
Récupère toutes les revendications mises en correspondance par le prédicat spécifié. (Hérité de ClaimsPrincipal) |
| FindAll(String) |
Récupère toutes ou toutes les revendications qui ont le type de revendication spécifié. (Hérité de ClaimsPrincipal) |
| FindFirst(Predicate<Claim>) |
Récupère la première revendication correspondant au prédicat spécifié. (Hérité de ClaimsPrincipal) |
| FindFirst(String) |
Récupère la première revendication avec le type de revendication spécifié. (Hérité de ClaimsPrincipal) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Remplit les SerializationInfo données nécessaires pour sérialiser l’objet actuel ClaimsPrincipal . (Hérité de ClaimsPrincipal) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| HasClaim(Predicate<Claim>) |
Détermine si l’une des identités de revendications associées à ce principal de revendications contient une revendication qui est mise en correspondance par le prédicat spécifié. (Hérité de ClaimsPrincipal) |
| HasClaim(String, String) |
Détermine si l’une des identités de revendications associées à ce principal de revendications contient une revendication avec le type de revendication et la valeur spécifiés. (Hérité de ClaimsPrincipal) |
| IsInRole(Int32) |
Détermine si le principal actuel appartient au groupe d’utilisateurs Windows avec l’identificateur relatif spécifié (RID). |
| IsInRole(SecurityIdentifier) |
Détermine si le principal actuel appartient au groupe d’utilisateurs Windows avec l’identificateur de sécurité (SID) spécifié. |
| IsInRole(String) |
Détermine si le principal actuel appartient au groupe d’utilisateurs Windows avec le nom spécifié. |
| IsInRole(WindowsBuiltInRole) |
Détermine si le principal actuel appartient au groupe d’utilisateurs Windows avec le WindowsBuiltInRole spécifié. |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
| WriteTo(BinaryWriter, Byte[]) |
Sérialise à l’aide d’un BinaryWriter. (Hérité de ClaimsPrincipal) |
| WriteTo(BinaryWriter) |
Sérialise à l’aide d’un BinaryWriter. (Hérité de ClaimsPrincipal) |