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

IApplicationTrustManager インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

アプリケーション実行するかどうか、およびどのアクセス許可セットアプリケーション付与するかを判断します

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

<ComVisibleAttribute(True)> _
Public Interface IApplicationTrustManager
    Inherits ISecurityEncodable
Dim instance As IApplicationTrustManager
[ComVisibleAttribute(true)] 
public interface IApplicationTrustManager : ISecurityEncodable
[ComVisibleAttribute(true)] 
public interface class IApplicationTrustManager
 : ISecurityEncodable
/** @attribute ComVisibleAttribute(true) */ 
public interface IApplicationTrustManager extends ISecurityEncodable
ComVisibleAttribute(true) 
public interface IApplicationTrustManager extends
 ISecurityEncodable
解説解説
使用例使用例

IApplicationTrustManager の非常に単純な実装次のコード例示します

' To use the custom trust manager MyTrustManager, compile it into CustomTrustManager.dll,
 
' place that assembly in the GAC, and  put the following elements in
' an ApplicationTrust.config file in the config folder in the Microsoft
 .NET framework
' installation folder.
'<?xml version="1.0" encoding="utf-8" ?>
'<configuration>
'    <mscorlib>
'        <security>
'            <policy>
'                <ApplicationSecurityManager>
'                    <ApplicationEntries />
'                    <IApplicationTrustManager class="MyNamespace.MyTrustManager,
 CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>
'                </ApplicationSecurityManager>
'            </policy>
'        </security>
'    </mscorlib>
'</configuration>
Imports System
Imports System.Security
Imports System.Security.Policy
Imports System.Windows.Forms


Public Class MyTrustManager
    Implements IApplicationTrustManager
    
    Public Function DetermineApplicationTrust(ByVal
 appContext As ActivationContext, ByVal context
 As TrustManagerContext) As ApplicationTrust Implements IApplicationTrustManager.DetermineApplicationTrust
        Dim trust As New
 ApplicationTrust(appContext.Identity)
        trust.IsApplicationTrustedToRun = False

        Dim asi As New ApplicationSecurityInfo(appContext)
        trust.DefaultGrantSet = New PolicyStatement(asi.DefaultRequestSet,
 _
        PolicyStatementAttribute.Nothing)
        If context.UIContext = TrustManagerUIContext.Run Then
            Dim message As String
 = "Do you want to run " + asi.ApplicationId.Name
 + " ?"
            Dim caption As String
 = "MyTrustManager"
            Dim buttons As MessageBoxButtons
 = MessageBoxButtons.YesNo
            Dim result As DialogResult

            ' Displays the MessageBox.
            result = MessageBox.Show(message, caption, buttons)

            If result = DialogResult.Yes Then
                trust.IsApplicationTrustedToRun = True
                If Not (context Is
 Nothing) Then
                    trust.Persist = context.Persist
                Else
                    trust.Persist = False
                End If
            End If
        End If
        Return trust

    End Function 'DetermineApplicationTrust
    
    Public Function ToXml() As
 SecurityElement Implements IApplicationTrustManager.ToXml
        Dim se As New SecurityElement("IApplicationTrustManager")
        se.AddAttribute("class", GetType(MyTrustManager).AssemblyQualifiedName)
        Return se

    End Function 'ToXml
    
    Public Sub FromXml(ByVal
 se As SecurityElement) Implements IApplicationTrustManager.FromXml
        If se.Tag <> "IApplicationTrustManager"
 OrElse _
        CStr(se.Attributes("class")) <> GetType(MyTrustManager).AssemblyQualifiedName
 Then
            Throw New ArgumentException("Invalid
 tag")
        End If

End Class 'MyTrustManager
// To use the custom trust manager MyTrustManager, compile it into CustomTrustManager.dll,
 
// place that assembly in the GAC, and  put the following elements in
// an ApplicationTrust.config file in the config folder in the Microsoft
 .NET framework
// installation folder.

//<?xml version="1.0" encoding="utf-8" ?>
//<configuration>
//    <mscorlib>
//        <security>
//            <policy>
//                <ApplicationSecurityManager>
//                    <ApplicationEntries />
//                    <IApplicationTrustManager class="MyNamespace.MyTrustManager,
 CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>
//                </ApplicationSecurityManager>
//            </policy>
//        </security>
//    </mscorlib>
//</configuration>

using System;
using System.Security;
using System.Security.Policy;
using System.Windows.Forms;
namespace MyNamespace
{
    public class MyTrustManager : IApplicationTrustManager
    {
        public ApplicationTrust DetermineApplicationTrust(ActivationContext
 appContext, TrustManagerContext context)
        {
            ApplicationTrust trust = new ApplicationTrust(appContext.Identity);
            trust.IsApplicationTrustedToRun = false;

            ApplicationSecurityInfo asi = new ApplicationSecurityInfo(appContext);
            trust.DefaultGrantSet = new PolicyStatement(asi.DefaultRequestSet,
 PolicyStatementAttribute.Nothing);
            if (context.UIContext == TrustManagerUIContext.Run)
            {
                string message = "Do you want to run "
 + asi.ApplicationId.Name + " ?";
                string caption = "MyTrustManager";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult result;

                // Displays the MessageBox.

                result = MessageBox.Show(message, caption, buttons);

                if (result == DialogResult.Yes)
                {
                    trust.IsApplicationTrustedToRun = true;
                    if (context != null)
                        trust.Persist = context.Persist;
                    else
                        trust.Persist = false;
                }
            }

            return trust;
        }

        public SecurityElement ToXml()
        {
            SecurityElement se = new SecurityElement("IApplicationTrustManager");
            se.AddAttribute("class", typeof(MyTrustManager).AssemblyQualifiedName);
            return se;
        }

        public void FromXml(SecurityElement
 se)
        {
            if (se.Tag != "IApplicationTrustManager"
 || (string)se.Attributes["class"]
 != typeof(MyTrustManager).AssemblyQualifiedName)
                throw new ArgumentException("Invalid tag");
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IApplicationTrustManager メンバ
System.Security.Policy 名前空間

IApplicationTrustManager メソッド


パブリック メソッドパブリック メソッド

参照参照

関連項目

IApplicationTrustManager インターフェイス
System.Security.Policy 名前空間

IApplicationTrustManager メンバ



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

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

辞書ショートカット

すべての辞書の索引

「IApplicationTrustManager」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS