IApplicationTrustManager 인터페이스

정의

애플리케이션을 실행해야 하는지 여부와 애플리케이션에 부여해야 하는 권한 집합을 확인합니다.

public interface class IApplicationTrustManager : System::Security::ISecurityEncodable
[System.Runtime.InteropServices.ComVisible(true)]
public interface IApplicationTrustManager : System.Security.ISecurityEncodable
[<System.Runtime.InteropServices.ComVisible(true)>]
type IApplicationTrustManager = interface
    interface ISecurityEncodable
Public Interface IApplicationTrustManager
Implements 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" ?>
//                    <ApplicationEntries />
//                    <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>

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");
        }
    }
}
' 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" ?>
'                    <ApplicationEntries />
'                    <IApplicationTrustManager class="MyNamespace.MyTrustManager, CustomTrustManager, Version=1.0.0.3, Culture=neutral, PublicKeyToken=5659fc598c2a503e"/>
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 Sub
End Class

설명

트러스트 관리자를 구현 해야 합니다는 IApplicationTrustManager 인터페이스입니다. 호스트 호출을 IApplicationTrustManager.DetermineApplicationTrust 애플리케이션에 권한을 부여 해야 하 고 애플리케이션을 실행 해야 하는지 여부를 결정 하는 방법입니다.

.NET Framework 4 이상에는 인터페이스의 사용자 지정 구현일 수 있는 트러스트 관리자가 IApplicationTrustManager 하나만 있습니다. 사용 권한에 대 한 사용자 애플리케이션을 설치 하 고 애플리케이션에 부여 된 권한에 elevate 라는 메시지를 표시 하는 기본 트러스트 관리자 구현입니다. 다른 트러스트 관리자 구현에서는 다른 사용자 환경을 제공할 수 있습니다. 예를 들어는 구현 정보에 대 한 사용자에 게 확인 하는 대신 신뢰할 수 있는 애플리케이션에 대 한 엔터프라이즈 목록을 확인할 수 있습니다.

메서드

DetermineApplicationTrust(ActivationContext, TrustManagerContext)

애플리케이션을 실행해야 하는지 여부와 애플리케이션에 부여해야 하는 권한 집합을 확인합니다.

FromXml(SecurityElement)

XML 인코딩의 지정된 상태를 사용하여 보안 개체를 다시 만듭니다.

(다음에서 상속됨 ISecurityEncodable)
ToXml()

보안 개체 및 현재 상태의 XML 인코딩을 만듭니다.

(다음에서 상속됨 ISecurityEncodable)

적용 대상