WindowsPrincipal クラス

定義

コードによって Windows ユーザーの 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
継承
WindowsPrincipal
継承
WindowsPrincipal
属性
実装

次の例では、 メソッドのオーバーロードを使用する方法を IsInRole 示します。 WindowsBuiltInRole列挙体は、組み込みロールを識別する相対識別子 (RID) のソースとして使用されます。 RID は、現在のプリンシパルのロールを決定するために使用されます。

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

注釈

クラスは WindowsPrincipal 、主に Windows ユーザーのロールを確認するために使用されます。 メソッドの WindowsPrincipal.IsInRole オーバーロードを使用すると、さまざまなロール コンテキストを使用してユーザー ロールを確認できます。

コンストラクター

WindowsPrincipal(WindowsIdentity)

指定した WindowsIdentity オブジェクトを使用して、WindowsPrincipal クラスの新しいインスタンスを初期化します。

プロパティ

Claims

この要求プリンシパルと関連付けられているすべての要求 ID のすべての要求を含むコレクションを取得します。

(継承元 ClaimsPrincipal)
CustomSerializationData

派生型によって提供される追加データが含まれています。 通常、WriteTo(BinaryWriter, Byte[]) の呼び出し時に設定されます。

(継承元 ClaimsPrincipal)
DeviceClaims

このプリンシパルからのすべての Windows デバイス クレームを取得します。

Identities

このクレーム プリンシパルと関連付けられているクレーム ID をすべて含むコレクションを取得します。

(継承元 ClaimsPrincipal)
Identity

現在のプリンシパルの ID を取得します。

UserClaims

このプリンシパルからのすべての Windows ユーザー クレームを取得します。

メソッド

AddIdentities(IEnumerable<ClaimsIdentity>)

指定された要求 ID をこの要求プリンシパルに追加します。

(継承元 ClaimsPrincipal)
AddIdentity(ClaimsIdentity)

指定された要求 ID をこの要求プリンシパルに追加します。

(継承元 ClaimsPrincipal)
Clone()

このインスタンスの新しいコピーを作成します。

(継承元 ClaimsPrincipal)
CreateClaimsIdentity(BinaryReader)

新しい要求の ID を作成します。

(継承元 ClaimsPrincipal)
Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
FindAll(Predicate<Claim>)

指定した述語に一致するすべてのクレームを取得します。

(継承元 ClaimsPrincipal)
FindAll(String)

すべての要求、または指定された要求の種類を持つ要求を取得します。

(継承元 ClaimsPrincipal)
FindFirst(Predicate<Claim>)

指定した述語に一致する最初のクレームを取得します。

(継承元 ClaimsPrincipal)
FindFirst(String)

指定したクレームの種類の最初のクレームを取得します。

(継承元 ClaimsPrincipal)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo オブジェクトに、現在の ClaimsPrincipal オブジェクトをシリアル化するために必要なデータを格納します。

(継承元 ClaimsPrincipal)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
HasClaim(Predicate<Claim>)

この要求プリンシパルに関連付けられている要求 ID のいずれかに、指定された述語と一致する要求が含まれているかどうかを判断します。

(継承元 ClaimsPrincipal)
HasClaim(String, String)

この要求プリンシパルに関連付けられているクレーム ID のいずれかに、指定された要求の種類と値を持つ要求が含まれているかどうかを判断します。

(継承元 ClaimsPrincipal)
IsInRole(Int32)

現在のプリンシパルが、指定した相対識別子 (RID) の Windows ユーザー グループに属しているかどうかを確認します。

IsInRole(SecurityIdentifier)

現在のプリンシパルが、指定したセキュリティ識別子 (SID) の Windows ユーザー グループに属しているかどうかを確認します。

IsInRole(String)

現在のプリンシパルが、指定した名前の Windows ユーザー グループに属しているかどうかを確認します。

IsInRole(WindowsBuiltInRole)

現在のプリンシパルが、指定した WindowsBuiltInRole の Windows ユーザー グループに属しているかどうかを確認します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
WriteTo(BinaryWriter)

BinaryWriter を使用してシリアル化します。

(継承元 ClaimsPrincipal)
WriteTo(BinaryWriter, Byte[])

BinaryWriter を使用してシリアル化します。

(継承元 ClaimsPrincipal)

適用対象