WindowsPrincipal Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Aktiverar kod för att kontrollera Windows gruppmedlemskap för en Windows användare.
public ref class WindowsPrincipal : System::Security::Principal::IPrincipal
public ref 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
[<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
Implements IPrincipal
Public Class WindowsPrincipal
Inherits ClaimsPrincipal
- Arv
-
WindowsPrincipal
- Arv
- Attribut
- Implementeringar
Exempel
I följande exempel visas hur du använder IsInRole metodens överlagringar. Uppräkningen WindowsBuiltInRole används som källa för de relativa identifierare (RID) som identifierar de inbyggda rollerna. RID:erna används för att fastställa rollerna för det aktuella huvudkontot.
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
Kommentarer
Klassen WindowsPrincipal används främst för att kontrollera rollen för en Windows användare. Med WindowsPrincipal.IsInRole metodöverlagringarna kan du kontrollera användarrollen med hjälp av olika rollkontexter.
Konstruktorer
| Name | Description |
|---|---|
| WindowsPrincipal(WindowsIdentity) |
Initierar en ny instans av WindowsPrincipal klassen med hjälp av det angivna WindowsIdentity objektet. |
Egenskaper
| Name | Description |
|---|---|
| Claims |
Hämtar en samling som innehåller alla anspråk från alla anspråksidentiteter som är associerade med anspråksobjektet. (Ärvd från ClaimsPrincipal) |
| 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 ClaimsPrincipal) |
| DeviceClaims |
Hämtar alla Windows enhetsanspråk från det här huvudkontot. |
| Identities |
Hämtar en samling som innehåller alla anspråksidentiteter som är associerade med anspråksobjektet. (Ärvd från ClaimsPrincipal) |
| Identity |
Hämtar identiteten för det aktuella huvudkontot. |
| UserClaims |
Hämtar alla Windows användaranspråk från det här huvudkontot. |
Metoder
| Name | Description |
|---|---|
| AddIdentities(IEnumerable<ClaimsIdentity>) |
Lägger till de angivna anspråksidentiteterna i anspråksobjektet. (Ärvd från ClaimsPrincipal) |
| AddIdentity(ClaimsIdentity) |
Lägger till den angivna anspråksidentiteten i anspråksobjektet. (Ärvd från ClaimsPrincipal) |
| Clone() |
Returnerar en kopia av den här instansen. (Ärvd från ClaimsPrincipal) |
| CreateClaimsIdentity(BinaryReader) |
Skapar en ny anspråksidentitet. (Ärvd från ClaimsPrincipal) |
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| FindAll(Predicate<Claim>) |
Hämtar alla anspråk som matchas av det angivna predikatet. (Ärvd från ClaimsPrincipal) |
| FindAll(String) |
Hämtar alla eller de anspråk som har den angivna anspråkstypen. (Ärvd från ClaimsPrincipal) |
| FindFirst(Predicate<Claim>) |
Hämtar det första anspråket som matchas av det angivna predikatet. (Ärvd från ClaimsPrincipal) |
| FindFirst(String) |
Hämtar det första anspråket med den angivna anspråkstypen. (Ärvd från ClaimsPrincipal) |
| 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 ClaimsPrincipal objektet. (Ärvd från ClaimsPrincipal) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| HasClaim(Predicate<Claim>) |
Avgör om någon av anspråksidentiteterna som är associerade med det här anspråksobjektet innehåller ett anspråk som matchas av det angivna predikatet. (Ärvd från ClaimsPrincipal) |
| HasClaim(String, String) |
Avgör om någon av anspråksidentiteterna som är associerade med det här anspråksobjektet innehåller ett anspråk med den angivna anspråkstypen och värdet. (Ärvd från ClaimsPrincipal) |
| IsInRole(Int32) |
Avgör om det aktuella huvudkontot tillhör Windows användargrupp med den angivna relativa identifieraren (RID). |
| IsInRole(SecurityIdentifier) |
Avgör om det aktuella huvudkontot tillhör Windows användargrupp med angiven säkerhetsidentifierare (SID). |
| IsInRole(String) |
Avgör om det aktuella huvudkontot tillhör Windows användargrupp med det angivna namnet. |
| IsInRole(WindowsBuiltInRole) |
Avgör om det aktuella huvudkontot tillhör användargruppen Windows med angiven WindowsBuiltInRole. |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
| WriteTo(BinaryWriter, Byte[]) |
Serialiserar med hjälp av en BinaryWriter. (Ärvd från ClaimsPrincipal) |
| WriteTo(BinaryWriter) |
Serialiserar med hjälp av en BinaryWriter. (Ärvd från ClaimsPrincipal) |