WindowsPrincipal クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Windows ユーザーの Windows グループ メンバーシップを確認するコードを有効にします。
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
- 継承
-
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) |
指定したWindowsPrincipal オブジェクトを使用して、WindowsIdentity クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| 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, Byte[]) |
BinaryWriterを使用してシリアル化します。 (継承元 ClaimsPrincipal) |
| WriteTo(BinaryWriter) |
BinaryWriterを使用してシリアル化します。 (継承元 ClaimsPrincipal) |