Thread.CurrentPrincipal プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Thread.CurrentPrincipal プロパティの意味・解説 

Thread.CurrentPrincipal プロパティ

ロールベースのセキュリティに関するスレッド現在のプリンシパル取得または設定します

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

Public Shared Property CurrentPrincipal
 As IPrincipal
Dim value As IPrincipal

value = Thread.CurrentPrincipal

Thread.CurrentPrincipal = value
public static IPrincipal CurrentPrincipal {
 get; set; }
public:
static property IPrincipal^ CurrentPrincipal {
    IPrincipal^ get ();
    void set (IPrincipal^ value);
}
/** @property */
public static IPrincipal get_CurrentPrincipal
 ()

/** @property */
public static void set_CurrentPrincipal
 (IPrincipal value)
public static function get
 CurrentPrincipal () : IPrincipal

public static function set
 CurrentPrincipal (value : IPrincipal)

プロパティ
セキュリティ コンテキストを表す IPrincipal 値。

例外例外
使用例使用例

スレッドプリンシパル設定および取得する方法の例を次に示します

Option Explicit
Option Strict

Imports Microsoft.VisualBasic
Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Principal
Imports System.Threading

' Request permission to set thread principal.
<Assembly: SecurityPermissionAttribute( _
    SecurityAction.RequestOptional, ControlPrincipal := True)>

Public Class Principal

    <MTAThread> _
    Shared Sub Main()
    
        Dim rolesArray As String()
 = {"managers", "executives"}
        Try
            ' Set the principal to a new generic principal.
            Thread.CurrentPrincipal = _
                New GenericPrincipal(New GenericIdentity(
 _
                "Bob", "Passport"),
 rolesArray)

        Catch secureException As SecurityException
            Console.WriteLine("{0}: Permission to set Principal
 " & _
                "is denied.", secureException.GetType().Name)
        End Try

        Dim threadPrincipal As IPrincipal =
 Thread.CurrentPrincipal
        Console.WriteLine( _
            "Name: {0}" & vbCrLf & "IsAuthenticated:"
 & _
            " {1}" & vbCrLf & "AuthenticationType:
 {2}", _
            threadPrincipal.Identity.Name, _
            threadPrincipal.Identity.IsAuthenticated, _
            threadPrincipal.Identity.AuthenticationType)
    
    End Sub
End Class
using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;

// Request permission to set thread principal.
[assembly: SecurityPermissionAttribute(
    SecurityAction.RequestOptional, ControlPrincipal = true)]
class Principal
{
    static void Main()
    {
        string[] rolesArray = {"managers", "executives"};
        try
        {
            // Set the principal to a new generic principal.
            Thread.CurrentPrincipal = 
                new GenericPrincipal(new GenericIdentity(
                "Bob", "Passport"), rolesArray);
        }
        catch(SecurityException secureException)
        {
            Console.WriteLine("{0}: Permission to set Principal
 " +
                "is denied.", secureException.GetType().Name);
        }

        IPrincipal threadPrincipal = Thread.CurrentPrincipal;
        Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
            "\nAuthenticationType: {2}", 
            threadPrincipal.Identity.Name, 
            threadPrincipal.Identity.IsAuthenticated,
            threadPrincipal.Identity.AuthenticationType);
    }
}
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Principal;
using namespace System::Threading;

// Request permission to set thread principal.

[assembly:SecurityPermissionAttribute(
SecurityAction::RequestOptional,ControlPrincipal=true)];
[assembly:SecurityPermissionAttribute(
SecurityAction::RequestMinimum,UnmanagedCode=true)];
int main()
{
   array<String^>^rolesArray = {"managers","executives"};
   try
   {
      
      // Set the principal to a new generic principal.
      Thread::CurrentPrincipal = gcnew GenericPrincipal( gcnew GenericIdentity( "Bob","Passport"
 ),rolesArray );
   }
   catch ( SecurityException^ secureException ) 
   {
      Console::WriteLine( "{0}: Permission to set Principal
 "
      "is denied.", secureException->GetType()->Name );
   }

   IPrincipal^ threadPrincipal = Thread::CurrentPrincipal;
   Console::WriteLine( "Name: {0}\nIsAuthenticated: {1}"
   "\nAuthenticationType: {2}", threadPrincipal->Identity->Name,
 threadPrincipal->Identity->IsAuthenticated.ToString(), threadPrincipal->Identity->AuthenticationType
 );
}

import System.*;
import System.Security.*;
import System.Security.Permissions.*;
import System.Security.Principal.*;
import System.Threading.*;
import System.Threading.Thread;
import System.Security.SecurityManager;

// Request permission to set thread principal.
/** @class.assembly SecurityPermissionAttribute(SecurityAction.RequestOptional
,
     ControlPrincipal = true)
 */

class Principal
{
    public static void main(String[]
 args)
    {
        String rolesArray[] = new String[] { "managers",
 "executives" };

        try {
            // Set the principal to a new generic principal.
            Thread.set_CurrentPrincipal(new GenericPrincipal
                (new GenericIdentity("Bob", "Passport"),
 rolesArray));
        }
        catch (SecurityException secureException) {
            Console.WriteLine("{0}: Permission to set Principal
 " +
                "is denied.", secureException.GetType().get_Name());
        }

        IPrincipal threadPrincipal = Thread.get_CurrentPrincipal();
        Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
            "\nAuthenticationType: {2}",
            threadPrincipal.get_Identity().get_Name(),
            String.valueOf(threadPrincipal.get_Identity().get_IsAuthenticated()
            ),threadPrincipal.get_Identity().get_AuthenticationType());
    } //main
} //Principal
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からThread.CurrentPrincipal プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からThread.CurrentPrincipal プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からThread.CurrentPrincipal プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「Thread.CurrentPrincipal プロパティ」の関連用語

Thread.CurrentPrincipal プロパティのお隣キーワード
検索ランキング

   

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



Thread.CurrentPrincipal プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS