Thread.CurrentPrincipal プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ロールベースのセキュリティに関する、スレッドの現在のプリンシパルを取得または設定します。
public:
static property System::Security::Principal::IPrincipal ^ CurrentPrincipal { System::Security::Principal::IPrincipal ^ get(); void set(System::Security::Principal::IPrincipal ^ value); };
public static System.Security.Principal.IPrincipal? CurrentPrincipal { get; set; }
public static System.Security.Principal.IPrincipal CurrentPrincipal { get; set; }
static member CurrentPrincipal : System.Security.Principal.IPrincipal with get, set
Public Shared Property CurrentPrincipal As IPrincipal
プロパティ値
セキュリティ コンテキストを表す IPrincipal 値。
例外
呼び出し元に、プリンシパルを設定するために必要なアクセス許可がありません。
例
次のコード例は、スレッドのプリンシパルを設定および取得する方法を示しています。
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Principal;
using namespace System::Threading;
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 );
}
using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;
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);
}
}
open System.Security
open System.Security.Principal
open System.Threading
let rolesArray = [| "managers"; "executives" |]
try
// Set the principal to a new generic principal.
Thread.CurrentPrincipal <- GenericPrincipal(GenericIdentity("Bob", "Passport"), rolesArray)
with :? SecurityException as secureException ->
printfn $"{secureException.GetType().Name}: Permission to set Principal is denied."
let threadPrincipal = Thread.CurrentPrincipal
printfn $"Name: {threadPrincipal.Identity.Name}\nIsAuthenticated: {threadPrincipal.Identity.IsAuthenticated}\nAuthenticationType: {threadPrincipal.Identity.AuthenticationType}"
Option Explicit
Option Strict
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Principal
Imports System.Threading
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
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET