GenericPrincipalとは? わかりやすく解説

GenericPrincipal クラス

汎用プリンシパル表します

名前空間: System.Security.Principal
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class GenericPrincipal
    Implements IPrincipal
Dim instance As GenericPrincipal
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class GenericPrincipal : IPrincipal
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class GenericPrincipal : IPrincipal
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class GenericPrincipal implements IPrincipal
SerializableAttribute 
ComVisibleAttribute(true) 
public class GenericPrincipal implements IPrincipal
解説解説
使用例使用例

GenericPrincipal クラスメンバ使用例次に示します

Imports System
Imports System.Security.Principal

Public Class Form1
    Inherits System.Windows.Forms.Form

    ' Event handler for Run button.
    Private Sub Button1_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles
 Button1.Click

        tbxOutput.Cursor = Cursors.WaitCursor
        tbxOutput.Text = ""

        ' Retrieve a GenericPrincipal that is based on the current user's
        ' WindowsIdentity.
        Dim genericPrincipal As GenericPrincipal
 = GetGenericPrincipal()

        ' Retrieve the generic identity of the GenericPrincipal object.
        Dim principalIdentity As GenericIdentity
 = _
            CType(genericPrincipal.Identity, GenericIdentity)

        ' Display identity name and authentication type.
        If (principalIdentity.IsAuthenticated) Then
            WriteLine(principalIdentity.Name)
            WriteLine("Type:" + principalIdentity.AuthenticationType)
        End If

        ' Verify that the generic principal has been assigned the
        ' NetworkUser role.
        If (genericPrincipal.IsInRole("NetworkUser"))
 Then
            WriteLine("User belongs to the NetworkUser role.")
        End If
        WriteLine("This sample completed successfully; "
 + _
            " press Exit to continue.")
        tbxOutput.Cursor = Cursors.Default
    End Sub
    ' Create generic principal based on values from the current
    ' WindowsIdentity.
    Private Function GetGenericPrincipal()
 As GenericPrincipal
        ' Use values from the current WindowsIdentity to construct
        ' a set of GenericPrincipal roles.
        Dim roles(10) As String
        Dim windowsIdentity As WindowsIdentity
 = windowsIdentity.GetCurrent()

        If (windowsIdentity.IsAuthenticated) Then
            ' Add custom NetworkUser role.
            roles(0) = "NetworkUser"
        End If

        If (windowsIdentity.IsGuest) Then
            ' Add custom GuestUser role.
            roles(1) = "GuestUser"
        End If


        If (windowsIdentity.IsSystem) Then
            ' Add custom SystemUser role.
            roles(2) = "SystemUser"
        End If

        ' Construct a GenericIdentity object based on the current Windows
        ' identity name and authentication type.
        Dim authenticationType As String
 = windowsIdentity.AuthenticationType
        Dim userName As String
 = windowsIdentity.Name
        Dim genericIdentity = _
            New GenericIdentity(userName, authenticationType)

        ' Construct a GenericPrincipal object based on the generic identity
        ' and custom roles for the user.
        Dim genericPrincipal As New
 GenericPrincipal(genericIdentity, roles)

        Return genericPrincipal
    End Function
    ' Write out message with linefeed and carriage return.
    Private Sub WriteLine(ByVal
 message As String)
        tbxOutput.AppendText(message + vbCrLf)
    End Sub

    ' Event handler for Exit button.
    Private Sub Button2_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles
 Button2.Click

        Application.Exit()
    End Sub
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides
 Sub Dispose(ByVal disposing As
 Boolean)
        If disposing Then
            If Not (components Is
 Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel2 As
 System.Windows.Forms.Panel
    Friend WithEvents Panel1 As
 System.Windows.Forms.Panel
    Friend WithEvents Button1 As
 System.Windows.Forms.Button
    Friend WithEvents Button2 As
 System.Windows.Forms.Button
    Friend WithEvents tbxOutput As
 System.Windows.Forms.RichTextBox
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.tbxOutput = New System.Windows.Forms.RichTextBox
        Me.Panel2.SuspendLayout()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel2
        '
        Me.Panel2.Controls.Add(Me.Button1)
        Me.Panel2.Controls.Add(Me.Button2)
        Me.Panel2.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Panel2.DockPadding.All = 20
        Me.Panel2.Location = New System.Drawing.Point(0,
 320)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(616,
 64)
        Me.Panel2.TabIndex = 1
        '
        'Button1
        '
        Me.Button1.Dock = System.Windows.Forms.DockStyle.Right
        Me.Button1.Font = New System.Drawing.Font(
 _
            "Microsoft Sans Serif", _
            9.0!, _
            System.Drawing.FontStyle.Regular, _
            System.Drawing.GraphicsUnit.Point, _
            CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(446,
 20)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75,
 24)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "&Run"
        '
        'Button2
        '
        Me.Button2.Dock = System.Windows.Forms.DockStyle.Right
        Me.Button2.Font = New System.Drawing.Font(
 _
            "Microsoft Sans Serif", _
            9.0!, _
            System.Drawing.FontStyle.Regular, _
            System.Drawing.GraphicsUnit.Point, _
            CType(0, Byte))
        Me.Button2.Location = New System.Drawing.Point(521,
 20)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(75,
 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "E&xit"
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.tbxOutput)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.DockPadding.All = 20
        Me.Panel1.Location = New System.Drawing.Point(0,
 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(616,
 320)
        Me.Panel1.TabIndex = 2
        '
        'tbxOutput
        '
        Me.tbxOutput.AccessibleDescription = _
            "Displays output from application."
        Me.tbxOutput.AccessibleName = "Output
 textbox."
        Me.tbxOutput.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tbxOutput.Location = New System.Drawing.Point(20,
 20)
        Me.tbxOutput.Name = "tbxOutput"
        Me.tbxOutput.Size = New System.Drawing.Size(576,
 280)
        Me.tbxOutput.TabIndex = 1
        Me.tbxOutput.Text = "Click the Run
 button to run the application."
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6,
 15)
        Me.ClientSize = New System.Drawing.Size(616,
 384)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Panel2)
        Me.Name = "Form1"
        Me.Text = "GenericPrincipal"
        Me.Panel2.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
End Class

using System;
using System.Security.Principal;

class GenericPrincipalMembers
{
    [STAThread]
    static void Main(string[]
 args)
    {
        // Retrieve a GenericPrincipal that is based on the current
 user's
        // WindowsIdentity.
        GenericPrincipal genericPrincipal = GetGenericPrincipal();

        // Retrieve the generic identity of the GenericPrincipal object.
        GenericIdentity principalIdentity = 
            (GenericIdentity)genericPrincipal.Identity;

        // Display the identity name and authentication type.
        if (principalIdentity.IsAuthenticated)
        {
            Console.WriteLine(principalIdentity.Name);
            Console.WriteLine("Type:"+principalIdentity.AuthenticationType);
        }

        // Verify that the generic principal has been assigned the
        // NetworkUser role.
        if (genericPrincipal.IsInRole("NetworkUser"))
        {
            Console.WriteLine("User belongs to the NetworkUser role.");
        }

        Console.WriteLine("The sample completed successfully; " +
            "press Enter to continue.");
        Console.ReadLine();
    }

    // Create a generic principal based on values from the current
    // WindowsIdentity.
    private static GenericPrincipal GetGenericPrincipal()
    {
        // Use values from the current WindowsIdentity to construct
        // a set of GenericPrincipal roles.
        WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
        string[] roles = new string[10];
        if (windowsIdentity.IsAuthenticated)
        {
            // Add custom NetworkUser role.
            roles[0] = "NetworkUser";
        }

        if (windowsIdentity.IsGuest)
        {
            // Add custom GuestUser role.
            roles[1] = "GuestUser";
        }

        if (windowsIdentity.IsSystem)
        {
            // Add custom SystemUser role.
            roles[2] = "SystemUser";
        }

        // Construct a GenericIdentity object based on the current Windows
        // identity name and authentication type.
        string authenticationType = windowsIdentity.AuthenticationType;
        string userName = windowsIdentity.Name;
        GenericIdentity genericIdentity =
            new GenericIdentity(userName, authenticationType);

        // Construct a GenericPrincipal object based on the generic
 identity
        // and custom roles for the user.
        GenericPrincipal genericPrincipal =
            new GenericPrincipal(genericIdentity, roles);

        return genericPrincipal;
    }
}

using namespace System;
using namespace System::Security::Principal;

ref class GenericPrincipalMembers
{
public:
   [STAThread]
   static void Main()
   {
      // Retrieve a GenericPrincipal that is based on the current user's
      // WindowsIdentity.
      GenericPrincipal^ genericPrincipal = GetGenericPrincipal();
      
      // Retrieve the generic identity of the GenericPrincipal object.
      GenericIdentity^ principalIdentity =
         dynamic_cast<GenericIdentity^>(genericPrincipal->Identity);

      // Display the identity name and authentication type.
      if ( principalIdentity->IsAuthenticated )
      {
         Console::WriteLine( principalIdentity->Name );
         Console::WriteLine( L"Type:{0}",
            principalIdentity->AuthenticationType );
      }
      
      // Verify that the generic principal has been assigned the
      // NetworkUser role.
      if ( genericPrincipal->IsInRole( L"NetworkUser"
 ) )
      {
         Console::WriteLine( L"User belongs to the NetworkUser role." );
      }
      Console::WriteLine( L"The sample completed successfully; "
      L"press Enter to continue." );
      Console::ReadLine();
   }

private:
   // Create a generic principal based on values from the current
   // WindowsIdentity.
   static GenericPrincipal^ GetGenericPrincipal()
   {
      // Use values from the current WindowsIdentity to construct
      // a set of GenericPrincipal roles.
      WindowsIdentity^ windowsIdentity = WindowsIdentity::GetCurrent();
      array<String^>^roles = gcnew array<String^>(10);
      if ( windowsIdentity->IsAuthenticated )
      {
         
         // Add custom NetworkUser role.
         roles[ 0 ] = L"NetworkUser";
      }

      if ( windowsIdentity->IsGuest )
      {
         
         // Add custom GuestUser role.
         roles[ 1 ] = L"GuestUser";
      }

      if ( windowsIdentity->IsSystem )
      {
         
         // Add custom SystemUser role.
         roles[ 2 ] = L"SystemUser";
      }
      
      // Construct a GenericIdentity object based on the current Windows
      // identity name and authentication type.
      String^ authenticationType = windowsIdentity->AuthenticationType;
      String^ userName = windowsIdentity->Name;
      GenericIdentity^ genericIdentity = gcnew GenericIdentity(
         userName,authenticationType );
      
      // Construct a GenericPrincipal object based on the generic identity
      // and custom roles for the user.
      GenericPrincipal^ genericPrincipal = gcnew GenericPrincipal(
         genericIdentity,roles );

      return genericPrincipal;
   }
};

int main()
{
   GenericPrincipalMembers::Main();
}


import System.*;
import System.Security.Principal.*;

class GenericPrincipalMembers
{
    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        // Retrieve a GenericPrincipal that is based on the current
 user's
        // WindowsIdentity.
        GenericPrincipal genericPrincipal = GetGenericPrincipal();
        // Retrieve the generic identity of the GenericPrincipal object.
        GenericIdentity principalIdentity = (GenericIdentity)
            (genericPrincipal.get_Identity());
        // Display the identity name and authentication type.
        if (principalIdentity.get_IsAuthenticated()) {
            Console.WriteLine(principalIdentity.get_Name());
            Console.WriteLine("Type:" + principalIdentity.
                get_AuthenticationType());
        }
        // Verify that the generic principal has been assigned the
        // NetworkUser role.
        if (genericPrincipal.IsInRole("NetworkUser"))
 {
            Console.WriteLine("User belongs to the NetworkUser role.");
        }

        Console.WriteLine("The sample completed successfully; " 
            + "press Enter to continue.");
        Console.ReadLine();
    } //main

    // Create a generic principal based on values from the current
    // WindowsIdentity.
    private static GenericPrincipal GetGenericPrincipal()
    {
        // Use values from the current WindowsIdentity to construct
        // a set of GenericPrincipal roles.
        WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
        String roles[] = new String[10];
        if (windowsIdentity.get_IsAuthenticated()) {
            // Add custom NetworkUser role.
            roles.set_Item(0, "NetworkUser");
        }

        if (windowsIdentity.get_IsGuest()) {
            // Add custom GuestUser role.
            roles.set_Item(1, "GuestUser");
        }

        if (windowsIdentity.get_IsSystem()) {
            // Add custom SystemUser role.
            roles.set_Item(2, "SystemUser");
        }
        // Construct a GenericIdentity object based on the current Windows
        // identity name and authentication type.
        String authenticationType = windowsIdentity.get_AuthenticationType();
        String userName = windowsIdentity.get_Name();
        GenericIdentity genericIdentity = new GenericIdentity(userName,
 
            authenticationType);
        // Construct a GenericPrincipal object based on the generic
 identity
        // and custom roles for the user.
        GenericPrincipal genericPrincipal = new GenericPrincipal(genericIdentity
,
            roles);
        return genericPrincipal;
    } //GetGenericPrincipal
} //GenericPrincipalMembers

継承階層継承階層
System.Object
  System.Security.Principal.GenericPrincipal
     System.Web.Security.PassportPrincipal
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GenericPrincipal メンバ
System.Security.Principal 名前空間

GenericPrincipal コンストラクタ

ユーザー ID と、その ID が表すユーザー属しているロールの名前の配列から、GenericPrincipal クラス新しインスタンス初期化します。

名前空間: System.Security.Principal
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    identity As IIdentity, _
    roles As String() _
)
Dim identity As IIdentity
Dim roles As String()

Dim instance As New GenericPrincipal(identity,
 roles)
public GenericPrincipal (
    IIdentity identity,
    string[] roles
)
public:
GenericPrincipal (
    IIdentity^ identity, 
    array<String^>^ roles
)
public GenericPrincipal (
    IIdentity identity, 
    String[] roles
)
public function GenericPrincipal (
    identity : IIdentity, 
    roles : String[]
)

パラメータ

identity

任意のユーザーを表す IIdentity の基本実装

roles

identity パラメータによって表されるユーザー属しているロールの名前の配列

例外例外
例外種類条件

ArgumentNullException

identity パラメータnull 参照 (Visual Basic では Nothing) です。

使用例使用例

GenericPrincipal コンストラクタ使用する方法次のコード示します。このコード例は、GenericPrincipal クラストピック取り上げているコード例一部分です。

Dim roles(10) As String
Dim windowsIdentity As WindowsIdentity = windowsIdentity.GetCurrent()

If (windowsIdentity.IsAuthenticated) Then
    ' Add custom NetworkUser role.
    roles(0) = "NetworkUser"
End If

If (windowsIdentity.IsGuest) Then
    ' Add custom GuestUser role.
    roles(1) = "GuestUser"
End If


If (windowsIdentity.IsSystem) Then
    ' Add custom SystemUser role.
    roles(2) = "SystemUser"
End If

' Construct a GenericIdentity object based on the current Windows
' identity name and authentication type.
Dim authenticationType As String
 = windowsIdentity.AuthenticationType
Dim userName As String =
 windowsIdentity.Name
Dim genericIdentity = _
    New GenericIdentity(userName, authenticationType)

' Construct a GenericPrincipal object based on the generic identity
' and custom roles for the user.
Dim genericPrincipal As New
 GenericPrincipal(genericIdentity, roles)
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
string[] roles = new string[10];
if (windowsIdentity.IsAuthenticated)
{
    // Add custom NetworkUser role.
    roles[0] = "NetworkUser";
}

if (windowsIdentity.IsGuest)
{
    // Add custom GuestUser role.
    roles[1] = "GuestUser";
}

if (windowsIdentity.IsSystem)
{
    // Add custom SystemUser role.
    roles[2] = "SystemUser";
}

// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
string authenticationType = windowsIdentity.AuthenticationType;
string userName = windowsIdentity.Name;
GenericIdentity genericIdentity =
    new GenericIdentity(userName, authenticationType);

// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal genericPrincipal =
    new GenericPrincipal(genericIdentity, roles);
WindowsIdentity^ windowsIdentity = WindowsIdentity::GetCurrent();
array<String^>^roles = gcnew array<String^>(10);
if ( windowsIdentity->IsAuthenticated )
{
   
   // Add custom NetworkUser role.
   roles[ 0 ] = L"NetworkUser";
}

if ( windowsIdentity->IsGuest )
{
   
   // Add custom GuestUser role.
   roles[ 1 ] = L"GuestUser";
}

if ( windowsIdentity->IsSystem )
{
   
   // Add custom SystemUser role.
   roles[ 2 ] = L"SystemUser";
}

// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
String^ authenticationType = windowsIdentity->AuthenticationType;
String^ userName = windowsIdentity->Name;
GenericIdentity^ genericIdentity = gcnew GenericIdentity(
   userName,authenticationType );

// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal^ genericPrincipal = gcnew GenericPrincipal(
   genericIdentity,roles );
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
String roles[] = new String[10];
if (windowsIdentity.get_IsAuthenticated()) {
    // Add custom NetworkUser role.
    roles.set_Item(0, "NetworkUser");
}

if (windowsIdentity.get_IsGuest()) {
    // Add custom GuestUser role.
    roles.set_Item(1, "GuestUser");
}

if (windowsIdentity.get_IsSystem()) {
    // Add custom SystemUser role.
    roles.set_Item(2, "SystemUser");
}
// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
String authenticationType = windowsIdentity.get_AuthenticationType();
String userName = windowsIdentity.get_Name();
GenericIdentity genericIdentity = new GenericIdentity(userName,
 
    authenticationType);
// Construct a GenericPrincipal object based on the generic identity
// and custom roles for the user.
GenericPrincipal genericPrincipal = new GenericPrincipal(genericIdentity
,
    roles);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GenericPrincipal クラス
GenericPrincipal メンバ
System.Security.Principal 名前空間

GenericPrincipal プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Identity 現在の GenericPrincipal によって表されるユーザーの GenericIdentity を取得します
参照参照

関連項目

GenericPrincipal クラス
System.Security.Principal 名前空間

GenericPrincipal メソッド


GenericPrincipal メンバ

汎用プリンシパル表します

GenericPrincipal データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド GenericPrincipal ユーザー ID と、その ID が表すユーザー属しているロールの名前の配列から、GenericPrincipal クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Identity 現在の GenericPrincipal によって表されるユーザーの GenericIdentity を取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

GenericPrincipal クラス
System.Security.Principal 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「GenericPrincipal」の関連用語

GenericPrincipalのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



GenericPrincipalのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS