FirstMatchCodeGroup クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class FirstMatchCodeGroup Inherits CodeGroup
[SerializableAttribute] [ComVisibleAttribute(true)] public sealed class FirstMatchCodeGroup : CodeGroup
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class FirstMatchCodeGroup sealed : public CodeGroup

コード グループは、コード アクセス セキュリティ ポリシーのビルド ブロックです。各ポリシー レベルは、ルート コード グループで構成され、子コード グループを含めることができます。各子コード グループがそれぞれに子コード グループを持つことができます。この機能は任意の数のレベルに拡張され、コード グループのツリーが形成されていきます。各コード グループには、特定のアセンブリの証拠に基づいて、そのアセンブリがそのコード グループに所属しているかどうかを判断するメンバシップ条件があります。指定されたアセンブリとメンバシップ条件が一致するコード グループ、およびそれらの子コード グループだけがポリシーを適用します。
コード グループと同様に、FirstMatchCodeGroup は、メンバシップ条件がアセンブリの証拠に一致した場合にだけ適用されます。一致した場合は、各子コード グループのメンバシップ条件が順番にテストされ、最初に一致した時点でテストは停止します。FirstMatchCodeGroup の結果は、ルート コード グループのポリシー ステートメントと、最初に一致したコード グループの子コード グループのポリシー ステートメントの和集合になります。
FirstMatchCodeGroup は、ドメイン ポリシーを設定するためにアプリケーション ドメインのホストでプログラムにより使用されます。

FirstMatchCodeGroup クラスのメンバを使用する例を次に示します。
Imports System Imports System.Security Imports System.Security.Policy Imports System.Security.Permissions Imports System.Reflection 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 = "" ' Create a new FirstMatchCodeGroup. Dim codeGroup As FirstMatchCodeGroup = constructDefaultGroup() ' Create a deep copy of the FirstMatchCodeGroup. Dim copyCodeGroup As FirstMatchCodeGroup copyCodeGroup = CType(codeGroup.Copy(), FirstMatchCodeGroup) ' Compare the original code group with the copy. CompareTwoCodeGroups(codeGroup, copyCodeGroup) addPolicy(codeGroup) addXmlMember(codeGroup) updateMembershipCondition(codeGroup) addChildCodeGroup(codeGroup) Write("Comparing the resolved code group ") WriteLine("with the initial code group.") Dim resolvedCodeGroup As FirstMatchCodeGroup resolvedCodeGroup = ResolveGroupToEvidence(codeGroup) If (CompareTwoCodeGroups(codeGroup, resolvedCodeGroup)) Then PrintCodeGroup(resolvedCodeGroup) Else PrintCodeGroup(codeGroup) End If ' Reset the cursor and conclude application. tbxOutput.AppendText(vbCrLf + "This sample completed " + _ "successfully; press Exit to continue.") tbxOutput.Cursor = Cursors.Default End Sub ' Create a FirstMatchCodeGroup with an exclusive policy and membership ' condition. Private Function constructDefaultGroup() As FirstMatchCodeGroup ' Construct a new FirstMatchCodeGroup with Read, Write, Append ' and PathDiscovery access. ' Create read access permission to the root directory on drive C. Dim rootFilePermissions As New FileIOPermission(PermissionState.None) rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\") ' Add a permission to a named permission set. Dim namedPermissions As New NamedPermissionSet("RootPermissions") namedPermissions.AddPermission(rootFilePermissions) ' Create a PolicyStatement with exclusive rights to the policy. Dim policy As New PolicyStatement( _ namedPermissions, _ PolicyStatementAttribute.Exclusive) ' Create a FirstMatchCodeGroup with a membership condition that ' matches all code, and an exclusive policy. Dim codeGroup As New FirstMatchCodeGroup( _ New AllMembershipCondition, _ policy) ' Set the name of the first match code group. codeGroup.Name = "TempCodeGroup" ' Set the description of the first match code group. codeGroup.Description = "Temp folder permissions group" Return codeGroup End Function ' Add file permission to restrict write access to all files ' on the local machine. Private Sub addPolicy(ByRef codeGroup As FirstMatchCodeGroup) ' Set the PolicyStatement property to a policy with read access to the ' root directory on drive C. Dim rootFilePermissions As New FileIOPermission(PermissionState.None) rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\") Dim namedPermissions As New NamedPermissionSet("RootPermissions") namedPermissions.AddPermission(rootFilePermissions) ' Create a PolicyStatement with exclusive rights to the policy. Dim policy As New PolicyStatement( _ namedPermissions, _ PolicyStatementAttribute.Exclusive) codeGroup.PolicyStatement = policy End Sub ' Set the membership condition of the code group. Private Sub updateMembershipCondition( _ ByRef codeGroup As FirstMatchCodeGroup) ' Set the membership condition of the specified FirstMatchCodeGroup ' to the Intranet zone. Dim zoneCondition As _ New ZoneMembershipCondition(SecurityZone.Intranet) codeGroup.MembershipCondition = zoneCondition End Sub ' Create a child code group with read-access file permissions and add it ' to the specified code group. Private Sub addChildCodeGroup(ByRef codegroup As FirstMatchCodeGroup) ' Create a first match code group with read access. Dim rootFilePermissions As New FileIOPermission(PermissionState.None) rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\") Dim permissions As New PermissionSet(PermissionState.Unrestricted) permissions.AddPermission(rootFilePermissions) Dim tempFolderCodeGroup = New FirstMatchCodeGroup( _ New AllMembershipCondition, _ New PolicyStatement(permissions)) ' Set the name of the child code group and add it to the specified ' code group. tempFolderCodeGroup.Name = "Read-only code group" codegroup.AddChild(tempFolderCodeGroup) End Sub ' Compare the two FirstMatchCodeGroups. Private Function CompareTwoCodeGroups( _ ByVal firstCodeGroup As FirstMatchCodeGroup, _ ByVal secondCodeGroup As FirstMatchCodeGroup) As Boolean ' Compare the two specified FirstMatchCodeGroups for equality. If (firstCodeGroup.Equals(secondCodeGroup)) Then WriteLine("The two code groups are equal.") Return True Else WriteLine("The two code groups are not equal.") Return False End If End Function ' Retrieve the resolved policy based on executing evidence found ' in the specified code group. Private Function ResolveEvidence(ByVal codeGroup As CodeGroup) As String Dim policyString As String = "None" ' Resolve the policy based on the executing assembly's evidence. Dim executingAssembly As [Assembly] = _ [Assembly].GetExecutingAssembly() Dim executingEvidence As Evidence executingEvidence = executingAssembly.Evidence Dim policy As PolicyStatement = codeGroup.Resolve(executingEvidence) If (Not policy Is Nothing) Then policyString = policy.ToString() End If Return policyString End Function ' Retrieve the resolved code group based on the evidence from the ' specified code group. Private Function ResolveGroupToEvidence( _ ByVal codegroup As FirstMatchCodeGroup) _ As FirstMatchCodeGroup ' Resolve matching code groups to the executing assembly. Dim executingAssembly As [Assembly] = _ [Assembly].GetExecutingAssembly() Dim evidence As Evidence = executingAssembly.Evidence Dim resolvedCodeGroup As CodeGroup resolvedCodeGroup = codegroup.ResolveMatchingCodeGroups(Evidence) Return CType(resolvedCodeGroup, FirstMatchCodeGroup) End Function ' If a domain attribute is not found in the specified FirstMatchCodeGroup , ' add a child XML element identifying a custom membership condition. Private Sub addXmlMember(ByRef codeGroup As FirstMatchCodeGroup) Dim xmlElement As SecurityElement = codeGroup.ToXml() Dim rootElement As New SecurityElement("CodeGroup") If (xmlElement.Attribute("domain") Is Nothing) Then Dim newElement As New SecurityElement("CustomMembershipCondition") newElement.AddAttribute("class", "CustomMembershipCondition") newElement.AddAttribute("version", "1") newElement.AddAttribute("domain", "contoso.com") rootElement.AddChild(newElement) codeGroup.FromXml(rootElement) End If WriteLine("Added a custom membership condition:") WriteLine(rootElement.ToString()) End Sub ' Print the properties of the specified code group to the console. Private Sub PrintCodeGroup(ByVal codeGroup As CodeGroup) ' Compare the type of the specified object with the ' FirstMatchCodeGroup type. If (Not codeGroup.GetType() Is GetType(FirstMatchCodeGroup)) Then Throw New ArgumentException( _ "Expected the FirstMatchCodeGroup type.") End If Dim codeGroupName As String = codeGroup.Name Dim membershipCondition As String membershipCondition = codeGroup.MembershipCondition.ToString() Dim permissionSetName As String = codeGroup.PermissionSetName Dim hashCode As Integer = codeGroup.GetHashCode() Dim mergeLogic As String = "" If (codeGroup.MergeLogic.Equals("First Match")) Then mergeLogic = "with first-match merge logic" End If ' Retrieve the class path for the FirstMatchCodeGroup. Dim firstMatchGroupClass As String = codeGroup.ToString() Dim attributeString As String = "" ' Retrieve the string representation of the FirstMatchCodeGroup's ' attributes. If (Not codeGroup.AttributeString Is Nothing) Then attributeString = codeGroup.AttributeString End If ' Write a summary to the console window. WriteLine(vbCrLf + "* " + firstMatchGroupClass + " summary *") Write("A FirstMatchCodeGroup named ") Write(codeGroupName + mergeLogic) Write(" has been created with hash code ") WriteLine(hashCode.ToString() + ". ") Write("This code group contains a " + membershipCondition) Write(" membership condition with the ") Write(permissionSetName + " permission set. ") Write("The code group contains the following policy: ") Write(ResolveEvidence(codeGroup) + ". ") Write("It also contains the following attributes: ") WriteLine(attributeString) Dim childCount As Integer = codeGroup.Children.Count If (childCount > 0) Then Write("There are " + childCount.ToString()) WriteLine(" child elements in the code group.") ' Iterate through the child code groups to display their names ' and then remove them from the specified code group. For i As Int16 = 0 To childCount - 1 Step 1 ' Retrieve each child explicitly casted as a ' FirstMatchCodeGroup type. Dim childCodeGroup As FirstMatchCodeGroup childCodeGroup = _ CType(codeGroup.Children(i), FirstMatchCodeGroup) Write("Removing the " + childCodeGroup.Name + ".") ' Remove the child code group. codeGroup.RemoveChild(childCodeGroup) Next WriteLine("") Else WriteLine("No child code groups were found in this code group.") End If End Sub Private Sub WriteLine(ByVal message As String) tbxOutput.AppendText(message + vbCrLf) End Sub Private Sub Write(ByVal message As String) tbxOutput.AppendText(message) 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 = "FirstMatchCodeGroup" Me.Panel2.ResumeLayout(False) Me.Panel1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region End Class ' ' This sample produces the following output: ' ' The two code groups are equal. ' Added a custom membership condition: ' <CodeGroup> ' <CustomMembershipCondition class="CustomMembershipCondition" ' version="1" ' domain="contoso.com"/> ' </CodeGroup> ' ' Comparing the resolved code group with the initial code group. ' The two code groups are not equal. ' ' * System.Security.Policy.FirstMatchCodeGroup summary * ' A FirstMatchCodeGroup named with first-match merge logic has been created ' with hash code 113155593. This code group contains a Zone - Intranet ' membership condition with the permission set. The code group contains the ' following policy: None. It also contains the following attributes: ' There are 1 child elements in the code group. ' Removing the Read-only code group. ' ' This sample completed successfully; press Exit to continue.
using System; using System.Security; using System.Security.Policy; using System.Security.Permissions; using System.Reflection; class Members { [STAThread] static void Main(string[] args) { // Create a new FirstMatchCodeGroup. FirstMatchCodeGroup codeGroup = constructDefaultGroup(); // Create a deep copy of the FirstMatchCodeGroup. FirstMatchCodeGroup copyCodeGroup = (FirstMatchCodeGroup)codeGroup.Copy(); // Compare the original code group with the copy. CompareTwoCodeGroups(codeGroup, copyCodeGroup); addPolicy(ref codeGroup); addXmlMember(ref codeGroup); updateMembershipCondition(ref codeGroup); addChildCodeGroup(ref codeGroup); Console.Write("Comparing the resolved code group "); Console.WriteLine("with the initial code group."); FirstMatchCodeGroup resolvedCodeGroup = ResolveGroupToEvidence(codeGroup); if (CompareTwoCodeGroups(codeGroup, resolvedCodeGroup)) { PrintCodeGroup(resolvedCodeGroup); } else { PrintCodeGroup(codeGroup); } Console.WriteLine("This sample completed successfully; " + "press Enter to exit."); Console.ReadLine(); } // Create a FirstMatchCodeGroup with an exclusive policy and membership // condition. private static FirstMatchCodeGroup constructDefaultGroup() { // Construct a new FirstMatchCodeGroup with Read, Write, Append // and PathDiscovery access. // Create read access permission to the root directory on drive C. FileIOPermission rootFilePermissions = new FileIOPermission(PermissionState.None); rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read; rootFilePermissions.SetPathList(FileIOPermissionAccess.Read,"C:\\"); // Add a permission to a named permission set. NamedPermissionSet namedPermissions = new NamedPermissionSet("RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement( namedPermissions,PolicyStatementAttribute.Exclusive); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup codeGroup = new FirstMatchCodeGroup( new AllMembershipCondition(), policy); // Set the name of the first match code group. codeGroup.Name = "TempCodeGroup"; // Set the description of the first match code group. codeGroup.Description = "Temp folder permissions group"; return codeGroup; } // Add file permission to restrict write access to all files // on the local machine. private static void addPolicy(ref FirstMatchCodeGroup codeGroup) { // Set the PolicyStatement property to a policy with read access to // the root directory on drive C. FileIOPermission rootFilePermissions = new FileIOPermission(PermissionState.None); rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read; rootFilePermissions.SetPathList(FileIOPermissionAccess.Read,"C:\\"); NamedPermissionSet namedPermissions = new NamedPermissionSet("RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement( namedPermissions, PolicyStatementAttribute.Exclusive); codeGroup.PolicyStatement = policy; } // Set the membership condition of the code group. private static void updateMembershipCondition( ref FirstMatchCodeGroup codeGroup) { // Set the membership condition of the specified FirstMatchCodeGroup // to the Intranet zone. ZoneMembershipCondition zoneCondition = new ZoneMembershipCondition(SecurityZone.Intranet); codeGroup.MembershipCondition = zoneCondition; } // Create a child code group with read-access file permissions and add it // to the specified code group. private static void addChildCodeGroup(ref FirstMatchCodeGroup codeGroup) { // Create a first match code group with read access. FileIOPermission rootFilePermissions = new FileIOPermission(PermissionState.None); rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read; rootFilePermissions.SetPathList(FileIOPermissionAccess.Read,"C:\\"); PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted); permissions.AddPermission(rootFilePermissions); FirstMatchCodeGroup tempFolderCodeGroup = new FirstMatchCodeGroup( new AllMembershipCondition(), new PolicyStatement(permissions)); // Set the name of the child code group and add it to // the specified code group. tempFolderCodeGroup.Name = "Read-only code group"; codeGroup.AddChild(tempFolderCodeGroup); } // Compare the two FirstMatchCodeGroups. private static bool CompareTwoCodeGroups( FirstMatchCodeGroup firstCodeGroup, FirstMatchCodeGroup secondCodeGroup) { // Compare the two specified FirstMatchCodeGroups for equality. if (firstCodeGroup.Equals(secondCodeGroup)) { Console.WriteLine("The two code groups are equal."); return true; } else { Console.WriteLine("The two code groups are not equal."); return false; } } // Retrieve the resolved policy based on executing evidence found // in the specified code group. private static string ResolveEvidence(CodeGroup codeGroup) { string policyString = "None"; // Resolve the policy based on the executing assembly's evidence. Assembly assembly = Assembly.GetExecutingAssembly(); Evidence executingEvidence = assembly.Evidence; PolicyStatement policy = codeGroup.Resolve(executingEvidence); if (policy != null) { policyString = policy.ToString(); } return policyString; } // Retrieve the resolved code group based on the evidence from the // specified code group. private static FirstMatchCodeGroup ResolveGroupToEvidence( FirstMatchCodeGroup codeGroup) { // Resolve matching code groups to the executing assembly. Assembly assembly = Assembly.GetExecutingAssembly(); Evidence evidence = assembly.Evidence; CodeGroup resolvedCodeGroup = codeGroup.ResolveMatchingCodeGroups(evidence); return (FirstMatchCodeGroup)resolvedCodeGroup; } // If a domain attribute is not found in the specified // FirstMatchCodeGroup, add a child XML element identifying a custom // membership condition. private static void addXmlMember(ref FirstMatchCodeGroup codeGroup) { SecurityElement xmlElement = codeGroup.ToXml(); SecurityElement rootElement = new SecurityElement("CodeGroup"); if (xmlElement.Attribute("domain") == null) { SecurityElement newElement = new SecurityElement("CustomMembershipCondition"); newElement.AddAttribute("class","CustomMembershipCondition"); newElement.AddAttribute("version","1"); newElement.AddAttribute("domain","contoso.com"); rootElement.AddChild(newElement); codeGroup.FromXml(rootElement); } Console.WriteLine("Added a custom membership condition:"); Console.WriteLine(rootElement.ToString()); } // Print the properties of the specified code group to the console. private static void PrintCodeGroup(CodeGroup codeGroup) { // Compare the type of the specified object with the // FirstMatchCodeGroup type. if (!codeGroup.GetType().Equals(typeof(FirstMatchCodeGroup))) { throw new ArgumentException( "Expected the FirstMatchCodeGroup type."); } string codeGroupName = codeGroup.Name; string membershipCondition = codeGroup.MembershipCondition.ToString(); string permissionSetName = codeGroup.PermissionSetName; int hashCode = codeGroup.GetHashCode(); string mergeLogic = ""; if (codeGroup.MergeLogic.Equals("First Match")) { mergeLogic = "with first-match merge logic"; } // Retrieve the class path for the FirstMatchCodeGroup. string firstMatchGroupClass = codeGroup.ToString(); string attributeString = ""; // Retrieve the string representation of the FirstMatchCodeGroup's // attributes. if (codeGroup.AttributeString != null) { attributeString = codeGroup.AttributeString; } // Write a summary to the console window. Console.WriteLine("\n*** " + firstMatchGroupClass + " summary ***"); Console.Write("A FirstMatchCodeGroup named "); Console.Write(codeGroupName + mergeLogic); Console.Write(" has been created with hash code(" + hashCode + ")."); Console.Write("\nThis code group contains a " + membershipCondition); Console.Write(" membership condition with the "); Console.WriteLine(permissionSetName + " permission set."); Console.Write("The code group contains the following policy: "); Console.Write(ResolveEvidence(codeGroup)); Console.Write("\nIt also contains the following attributes: "); Console.WriteLine(attributeString); int childCount = codeGroup.Children.Count; if (childCount > 0 ) { Console.Write("There are " + childCount); Console.WriteLine(" child elements in the code group."); // Iterate through the child code groups to display their names // and then remove them from the specified code group. for (int i=0; i < childCount; i++) { // Retrieve a child code group, which has been cast as a // FirstMatchCodeGroup type. FirstMatchCodeGroup childCodeGroup = (FirstMatchCodeGroup)codeGroup.Children[i]; Console.Write("Removing the " + childCodeGroup.Name + "."); // Remove the child code group. codeGroup.RemoveChild(childCodeGroup); } Console.WriteLine(); } else { Console.WriteLine(" No child code groups were found in this" + " code group."); } } } // // This sample produces the following output: // // The two code groups are equal. // Added a custom membership condition: // <CodeGroup> // <CustomMembershipCondition class="CustomMembershipCondition" // version="1" // domain="contoso.com"/> // </CodeGroup> // // Comparing the resolved code group with the initial code group. // The two code groups are not equal. // // *** System.Security.Policy.FirstMatchCodeGroup summary *** // A FirstMatchCodeGroup named with first-match merge logic has been created // with hash code(113151525). // This code group contains a Zone - Intranet membership condition with the // permission set.The code group contains the following policy: // It also contains the following attributes: // There are 1 child elements in the code group. // Removing the Read-only code group. // This sample completed successfully; press Enter to exit.
using namespace System; using namespace System::Security; using namespace System::Security::Policy; using namespace System::Security::Permissions; using namespace System::Reflection; ref class Members { public: [STAThread] static void Main() { // Create a new FirstMatchCodeGroup. FirstMatchCodeGroup^ codeGroup = constructDefaultGroup(); // Create a deep copy of the FirstMatchCodeGroup. FirstMatchCodeGroup^ copyCodeGroup = dynamic_cast<FirstMatchCodeGroup^>(codeGroup->Copy()); // Compare the original code group with the copy. CompareTwoCodeGroups( codeGroup, copyCodeGroup ); addPolicy( &codeGroup ); addXmlMember( &codeGroup ); updateMembershipCondition( &codeGroup ); addChildCodeGroup( &codeGroup ); Console::Write( L"Comparing the resolved code group " ); Console::WriteLine( L"with the initial code group." ); FirstMatchCodeGroup^ resolvedCodeGroup = ResolveGroupToEvidence( codeGroup ); if ( CompareTwoCodeGroups( codeGroup, resolvedCodeGroup ) ) { PrintCodeGroup( resolvedCodeGroup ); } else { PrintCodeGroup( codeGroup ); } Console::WriteLine( L"This sample completed successfully; " L"press Enter to exit." ); Console::ReadLine(); } private: // Create a FirstMatchCodeGroup with an exclusive policy and membership // condition. static FirstMatchCodeGroup^ constructDefaultGroup() { // Construct a new FirstMatchCodeGroup with Read, Write, Append // and PathDiscovery access. // Create read access permission to the root directory on drive C. FileIOPermission^ rootFilePermissions = gcnew FileIOPermission( PermissionState::None ); rootFilePermissions->AllLocalFiles = FileIOPermissionAccess::Read; rootFilePermissions->SetPathList( FileIOPermissionAccess::Read, L"C:\\" ); // Add a permission to a named permission set. NamedPermissionSet^ namedPermissions = gcnew NamedPermissionSet( L"RootPermissions" ); namedPermissions->AddPermission( rootFilePermissions ); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement^ policy = gcnew PolicyStatement( namedPermissions,PolicyStatementAttribute::Exclusive ); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup^ codeGroup = gcnew FirstMatchCodeGroup( gcnew AllMembershipCondition,policy ); // Set the name of the first match code group. codeGroup->Name = L"TempCodeGroup"; // Set the description of the first match code group. codeGroup->Description = L"Temp folder permissions group"; return codeGroup; } // Add file permission to restrict write access to all files // on the local machine. static void addPolicy( interior_ptr<FirstMatchCodeGroup^> codeGroup ) { // Set the PolicyStatement property to a policy with read access to // the root directory on drive C. FileIOPermission^ rootFilePermissions = gcnew FileIOPermission( PermissionState::None ); rootFilePermissions->AllLocalFiles = FileIOPermissionAccess::Read; rootFilePermissions->SetPathList( FileIOPermissionAccess::Read, L"C:\\" ); NamedPermissionSet^ namedPermissions = gcnew NamedPermissionSet( L"RootPermissions" ); namedPermissions->AddPermission( rootFilePermissions ); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement^ policy = gcnew PolicyStatement( namedPermissions,PolicyStatementAttribute::Exclusive ); ( *codeGroup )->PolicyStatement = policy; } // Set the membership condition of the code group. static void updateMembershipCondition( interior_ptr<FirstMatchCodeGroup^> codeGroup ) { // Set the membership condition of the specified FirstMatchCodeGroup // to the Intranet zone. ZoneMembershipCondition^ zoneCondition = gcnew ZoneMembershipCondition( SecurityZone::Intranet ); ( *codeGroup )->MembershipCondition = zoneCondition; } // Create a child code group with read-access file permissions and add it // to the specified code group. static void addChildCodeGroup( interior_ptr<FirstMatchCodeGroup^> codeGroup ) { // Create a first match code group with read access. FileIOPermission^ rootFilePermissions = gcnew FileIOPermission( PermissionState::None ); rootFilePermissions->AllLocalFiles = FileIOPermissionAccess::Read; rootFilePermissions->SetPathList( FileIOPermissionAccess::Read, L"C:\\" ); PermissionSet^ permissions = gcnew PermissionSet( PermissionState::Unrestricted ); permissions->AddPermission( rootFilePermissions ); FirstMatchCodeGroup^ tempFolderCodeGroup = gcnew FirstMatchCodeGroup( gcnew AllMembershipCondition, gcnew PolicyStatement( permissions ) ); // Set the name of the child code group and add it to // the specified code group. tempFolderCodeGroup->Name = L"Read-only code group"; ( *codeGroup )->AddChild( tempFolderCodeGroup ); } // Compare the two FirstMatchCodeGroups. static bool CompareTwoCodeGroups( FirstMatchCodeGroup^ firstCodeGroup, FirstMatchCodeGroup^ secondCodeGroup ) { // Compare the two specified FirstMatchCodeGroups for equality. if ( firstCodeGroup->Equals( secondCodeGroup ) ) { Console::WriteLine( L"The two code groups are equal." ); return true; } else { Console::WriteLine( L"The two code groups are not equal." ); return false; } } // Retrieve the resolved policy based on executing evidence found // in the specified code group. static String^ ResolveEvidence( CodeGroup^ codeGroup ) { String^ policyString = L"None"; // Resolve the policy based on the executing assembly's evidence. Assembly^ assembly = Assembly::GetExecutingAssembly(); Evidence^ executingEvidence = assembly->Evidence; PolicyStatement^ policy = codeGroup->Resolve( executingEvidence ); if ( policy != nullptr ) { policyString = policy->ToString(); } return policyString; } // Retrieve the resolved code group based on the evidence from the // specified code group. static FirstMatchCodeGroup^ ResolveGroupToEvidence( FirstMatchCodeGroup^ codeGroup ) { // Resolve matching code groups to the executing assembly. Assembly^ assembly = Assembly::GetExecutingAssembly(); Evidence^ evidence = assembly->Evidence; CodeGroup^ resolvedCodeGroup = codeGroup->ResolveMatchingCodeGroups( evidence ); return dynamic_cast<FirstMatchCodeGroup^>(resolvedCodeGroup); } // If a domain attribute is not found in the specified // FirstMatchCodeGroup, add a child XML element identifying a custom // membership condition. static void addXmlMember( interior_ptr<FirstMatchCodeGroup^> codeGroup ) { SecurityElement^ xmlElement = ( *codeGroup )->ToXml(); SecurityElement^ rootElement = gcnew SecurityElement( L"CodeGroup" ); if ( xmlElement->Attribute(L"domain") == nullptr ) { SecurityElement^ newElement = gcnew SecurityElement( L"CustomMembershipCondition" ); newElement->AddAttribute( L"class", L"CustomMembershipCondition" ); newElement->AddAttribute( L"version", L"1" ); newElement->AddAttribute( L"domain", L"contoso.com" ); rootElement->AddChild( newElement ); ( *codeGroup )->FromXml( rootElement ); } Console::WriteLine( L"Added a custom membership condition:" ); Console::WriteLine( rootElement ); } // Print the properties of the specified code group to the console. static void PrintCodeGroup( CodeGroup^ codeGroup ) { // Compare the type of the specified object with the // FirstMatchCodeGroup type. if ( !codeGroup->GetType()->Equals( FirstMatchCodeGroup::typeid ) ) { throw gcnew ArgumentException( L"Expected the FirstMatchCodeGroup type." ); } String^ codeGroupName = codeGroup->Name; String^ membershipCondition = codeGroup->MembershipCondition->ToString(); String^ permissionSetName = codeGroup->PermissionSetName; int hashCode = codeGroup->GetHashCode(); String^ mergeLogic = L""; if ( codeGroup->MergeLogic->Equals( L"First Match" ) ) { mergeLogic = L"with first-match merge logic"; } // Retrieve the class path for the FirstMatchCodeGroup. String^ firstMatchGroupClass = codeGroup->ToString(); String^ attributeString = L""; // Retrieve the string representation of the FirstMatchCodeGroup's // attributes. if ( codeGroup->AttributeString != nullptr ) { attributeString = codeGroup->AttributeString; } // Write a summary to the console window. Console::WriteLine( L"\n*** {0} summary ***", firstMatchGroupClass ); Console::Write( L"A FirstMatchCodeGroup named " ); Console::Write( L"{0}{1}", codeGroupName, mergeLogic ); Console::Write( L" has been created with hash code({0}).", hashCode ); Console::Write( L"\nThis code group contains a {0}", membershipCondition ); Console::Write( L" membership condition with the " ); Console::WriteLine( L"{0} permission set.", permissionSetName ); Console::Write( L"The code group contains the following policy: " ); Console::Write( ResolveEvidence( codeGroup ) ); Console::Write( L"\nIt also contains the following attributes: " ); Console::WriteLine( attributeString ); int childCount = codeGroup->Children->Count; if ( childCount > 0 ) { Console::Write( L"There are {0}", childCount ); Console::WriteLine( L" child elements in the code group." ); // Iterate through the child code groups to display their names // and then remove them from the specified code group. for ( int i = 0; i < childCount; i++ ) { // Retrieve a child code group, which has been cast as a // FirstMatchCodeGroup type. FirstMatchCodeGroup^ childCodeGroup = dynamic_cast<FirstMatchCodeGroup^>(codeGroup->Children->default[ i ]); Console::Write( L"Removing the {0}.", childCodeGroup->Name ); // Remove the child code group. codeGroup->RemoveChild( childCodeGroup ); } Console::WriteLine(); } else { Console::WriteLine( L" No child code groups were found in this" L" code group." ); } } }; int main() { Members::Main(); } // // This sample produces the following output: // // The two code groups are equal. // Added a custom membership condition: // <CodeGroup> // <CustomMembershipCondition class="CustomMembershipCondition" // version="1" // domain="contoso.com"/> // </CodeGroup> // // Comparing the resolved code group with the initial code group. // The two code groups are not equal. // // *** System.Security.Policy.FirstMatchCodeGroup summary *** // A FirstMatchCodeGroup named with first-match merge logic has been created // with hash code(113151525). // This code group contains a Zone - Intranet membership condition with the // permission set.The code group contains the following policy: // It also contains the following attributes: // There are 1 child elements in the code group. // Removing the Read-only code group. // This sample completed successfully; press Enter to exit.
import System.*; import System.Security.*; import System.Security.Policy.*; import System.Security.Permissions.*; import System.Reflection.*; class Members { /** @attribute STAThread() */ public static void main(String[] args) { // Create a new FirstMatchCodeGroup. FirstMatchCodeGroup codeGroup = ConstructDefaultGroup(); // Create a deep copy of the FirstMatchCodeGroup. FirstMatchCodeGroup copyCodeGroup = (FirstMatchCodeGroup) (codeGroup.Copy()); // Compare the original code group with the copy. CompareTwoCodeGroups(codeGroup, copyCodeGroup); AddPolicy(codeGroup); AddXmlMember(codeGroup); UpdateMembershipCondition(codeGroup); AddChildCodeGroup(codeGroup); Console.Write("Comparing the resolved code group "); Console.WriteLine("with the initial code group."); FirstMatchCodeGroup resolvedCodeGroup = ResolveGroupToEvidence( codeGroup); if (CompareTwoCodeGroups(codeGroup, resolvedCodeGroup)) { PrintCodeGroup(resolvedCodeGroup); } else { PrintCodeGroup(codeGroup); } Console.WriteLine("This sample completed successfully; " + "press Enter to exit."); Console.ReadLine(); } //main // Create a FirstMatchCodeGroup with an exclusive policy and membership // condition. private static FirstMatchCodeGroup ConstructDefaultGroup() { // Construct a new FirstMatchCodeGroup with Read, Write, Append // and PathDiscovery access. // Create read access permission to the root directory on drive C. FileIOPermission rootFilePermissions = new FileIOPermission( PermissionState.None); rootFilePermissions.set_AllLocalFiles(FileIOPermissionAccess.Read); rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\"); // Add a permission to a named permission set. NamedPermissionSet namedPermissions = new NamedPermissionSet( "RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement(namedPermissions, PolicyStatementAttribute.Exclusive); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup codeGroup = new FirstMatchCodeGroup(new AllMembershipCondition(), policy); // Set the name of the first match code group. codeGroup.set_Name("TempCodeGroup"); // Set the description of the first match code group. codeGroup.set_Description("Temp folder permissions group"); return codeGroup; } //ConstructDefaultGroup // Add file permission to restrict write access to all files // on the local machine. private static void AddPolicy(FirstMatchCodeGroup codeGroup) { // Set the PolicyStatement property to a policy with read access to // the root directory on drive C. FileIOPermission rootFilePermissions = new FileIOPermission( PermissionState.None); rootFilePermissions.set_AllLocalFiles(FileIOPermissionAccess.Read); rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\"); NamedPermissionSet namedPermissions = new NamedPermissionSet( "RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement(namedPermissions, PolicyStatementAttribute.Exclusive); codeGroup.set_PolicyStatement(policy); } //AddPolicy // Set the membership condition of the code group. private static void UpdateMembershipCondition(FirstMatchCodeGroup codeGroup) { // Set the membership condition of the specified FirstMatchCodeGroup // to the Intranet zone. ZoneMembershipCondition zoneCondition = new ZoneMembershipCondition( SecurityZone.Intranet); codeGroup.set_MembershipCondition(zoneCondition); } //UpdateMembershipCondition // Create a child code group with read-access file permissions and add it // to the specified code group. private static void AddChildCodeGroup(FirstMatchCodeGroup codeGroup) { // Create a first match code group with read access. FileIOPermission rootFilePermissions = new FileIOPermission( PermissionState.None); rootFilePermissions.set_AllLocalFiles(FileIOPermissionAccess.Read); rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\"); PermissionSet permissions = new PermissionSet(PermissionState. Unrestricted); permissions.AddPermission(rootFilePermissions); FirstMatchCodeGroup tempFolderCodeGroup = new FirstMatchCodeGroup(new AllMembershipCondition(), new PolicyStatement(permissions)); // Set the name of the child code group and add it to // the specified code group. tempFolderCodeGroup.set_Name("Read-only code group"); codeGroup.AddChild(tempFolderCodeGroup); } //AddChildCodeGroup // Compare the two FirstMatchCodeGroups. private static boolean CompareTwoCodeGroups(FirstMatchCodeGroup firstCodeGroup, FirstMatchCodeGroup secondCodeGroup) { // Compare the two specified FirstMatchCodeGroups for equality. if (firstCodeGroup.Equals(secondCodeGroup)) { Console.WriteLine("The two code groups are equal."); return true; } else { Console.WriteLine("The two code groups are not equal."); return false; } } //CompareTwoCodeGroups // Retrieve the resolved policy based on executing evidence found // in the specified code group. private static String ResolveEvidence(CodeGroup codeGroup) { String policyString = "None"; // Resolve the policy based on the executing assembly's evidence. Assembly assembly = Assembly.GetExecutingAssembly(); Evidence executingEvidence = assembly.get_Evidence(); PolicyStatement policy = codeGroup.Resolve(executingEvidence); if (policy != null) { policyString = policy.ToString(); } return policyString; } //ResolveEvidence // Retrieve the resolved code group based on the evidence from the // specified code group. private static FirstMatchCodeGroup ResolveGroupToEvidence(FirstMatchCodeGroup codeGroup) { // Resolve matching code groups to the executing assembly. Assembly assembly = Assembly.GetExecutingAssembly(); Evidence evidence = assembly.get_Evidence(); CodeGroup resolvedCodeGroup = codeGroup.ResolveMatchingCodeGroups (evidence); return ((FirstMatchCodeGroup)(resolvedCodeGroup)); } //ResolveGroupToEvidence // If a domain attribute is not found in the specified // FirstMatchCodeGroup, add a child XML element identifying a custom // membership condition. private static void AddXmlMember(FirstMatchCodeGroup codeGroup) { SecurityElement xmlElement = codeGroup.ToXml(); SecurityElement rootElement = new SecurityElement("CodeGroup"); if (xmlElement.Attribute("domain") == null) { SecurityElement newElement = new SecurityElement( "CustomMembershipCondition"); newElement.AddAttribute("class", "CustomMembershipCondition"); newElement.AddAttribute("version", "1"); newElement.AddAttribute("domain", "contoso.com"); rootElement.AddChild(newElement); codeGroup.FromXml(rootElement); } Console.WriteLine("Added a custom membership condition:"); Console.WriteLine(rootElement.ToString()); } //AddXmlMember // Print the properties of the specified code group to the console. private static void PrintCodeGroup(CodeGroup codeGroup) { // Compare the type of the specified object with the // FirstMatchCodeGroup type. if (!(codeGroup.GetType().Equals(FirstMatchCodeGroup.class.ToType()))) { throw new ArgumentException("Expected the FirstMatchCodeGroup type."); } String codeGroupName = codeGroup.get_Name(); String membershipCondition = codeGroup.get_MembershipCondition(). ToString(); String permissionSetName = codeGroup.get_PermissionSetName(); int hashCode = codeGroup.GetHashCode(); String mergeLogic = ""; if (codeGroup.get_MergeLogic().Equals("First Match")) { mergeLogic = "with first-match merge logic"; } // Retrieve the class path for the FirstMatchCodeGroup. String firstMatchGroupClass = codeGroup.ToString(); String attributeString = ""; // Retrieve the string representation of the FirstMatchCodeGroup's // attributes. if (codeGroup.get_AttributeString() != null) { attributeString = codeGroup.get_AttributeString(); } // Write a summary to the console window. Console.WriteLine("\n*** " + firstMatchGroupClass + " summary ***"); Console.Write("A FirstMatchCodeGroup named "); Console.Write(codeGroupName + mergeLogic); Console.Write(" has been created with hash code(" + hashCode + ")."); Console.Write("\nThis code group contains a " + membershipCondition); Console.Write(" membership condition with the "); Console.WriteLine(permissionSetName + " permission set."); Console.Write("The code group contains the following policy: "); Console.Write(ResolveEvidence(codeGroup)); Console.Write("\nIt also contains the following attributes: "); Console.WriteLine(attributeString); int childCount = codeGroup.get_Children().get_Count(); if (childCount > 0) { Console.Write("There are " + childCount); Console.WriteLine(" child elements in the code group."); // Iterate through the child code groups to display their names // and then remove them from the specified code group. for (int i = 0; i < childCount; i++) { // Retrieve a child code group, which has been cast as a // FirstMatchCodeGroup type. FirstMatchCodeGroup childCodeGroup = (FirstMatchCodeGroup) (codeGroup.get_Children().get_Item(i)); Console.Write("Removing the " + childCodeGroup.get_Name() + "."); // Remove the child code group. codeGroup.RemoveChild(childCodeGroup); Console.WriteLine(); } else { Console.WriteLine(" No child code groups were found in this" + " code group."); } } //PrintCodeGroup } //Members // // This sample produces the following output: // // The two code groups are equal. // Added a custom membership condition: // <CodeGroup> // <CustomMembershipCondition class="CustomMembershipCondition" // version="1" // domain="contoso.com"/> // </CodeGroup> // // Comparing the resolved code group with the initial code group. // The two code groups are not equal. // // *** System.Security.Policy.FirstMatchCodeGroup summary *** // A FirstMatchCodeGroup named with first-match merge logic has been created // with hash code(113151525). // This code group contains a Zone - Intranet membership condition with the // permission set.The code group contains the following policy: // It also contains the following attributes: // There are 1 child elements in the code group. // Removing the Read-only code group. // This sample completed successfully; press Enter to exit.

System.Security.Policy.CodeGroup
System.Security.Policy.FirstMatchCodeGroup


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FirstMatchCodeGroup コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)

Dim membershipCondition As IMembershipCondition Dim policy As PolicyStatement Dim instance As New FirstMatchCodeGroup(membershipCondition, policy)
public function FirstMatchCodeGroup ( membershipCondition : IMembershipCondition, policy : PolicyStatement )



FirstMatchCodeGroup コンストラクタを使用する方法を次のコードに示します。このコード例は FirstMatchCodeGroup クラスのトピックで取り上げているコード例の一部分です。
Dim rootFilePermissions As New FileIOPermission(PermissionState.None) rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\") ' Add a permission to a named permission set. Dim namedPermissions As New NamedPermissionSet("RootPermissions") namedPermissions.AddPermission(rootFilePermissions) ' Create a PolicyStatement with exclusive rights to the policy. Dim policy As New PolicyStatement( _ namedPermissions, _ PolicyStatementAttribute.Exclusive) ' Create a FirstMatchCodeGroup with a membership condition that ' matches all code, and an exclusive policy. Dim codeGroup As New FirstMatchCodeGroup( _ New AllMembershipCondition, _ policy)
FileIOPermission rootFilePermissions = new FileIOPermission(PermissionState.None); rootFilePermissions.AllLocalFiles = FileIOPermissionAccess.Read; rootFilePermissions.SetPathList(FileIOPermissionAccess.Read,"C:\\"); // Add a permission to a named permission set. NamedPermissionSet namedPermissions = new NamedPermissionSet("RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement( namedPermissions,PolicyStatementAttribute.Exclusive); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup codeGroup = new FirstMatchCodeGroup( new AllMembershipCondition(), policy);
FileIOPermission^ rootFilePermissions = gcnew FileIOPermission( PermissionState::None ); rootFilePermissions->AllLocalFiles = FileIOPermissionAccess::Read; rootFilePermissions->SetPathList( FileIOPermissionAccess::Read, L"C:\\" ); // Add a permission to a named permission set. NamedPermissionSet^ namedPermissions = gcnew NamedPermissionSet( L"RootPermissions" ); namedPermissions->AddPermission( rootFilePermissions ); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement^ policy = gcnew PolicyStatement( namedPermissions,PolicyStatementAttribute::Exclusive ); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup^ codeGroup = gcnew FirstMatchCodeGroup( gcnew AllMembershipCondition,policy );
FileIOPermission rootFilePermissions = new FileIOPermission( PermissionState.None); rootFilePermissions.set_AllLocalFiles(FileIOPermissionAccess.Read); rootFilePermissions.SetPathList(FileIOPermissionAccess.Read, "C:\\"); // Add a permission to a named permission set. NamedPermissionSet namedPermissions = new NamedPermissionSet( "RootPermissions"); namedPermissions.AddPermission(rootFilePermissions); // Create a PolicyStatement with exclusive rights to the policy. PolicyStatement policy = new PolicyStatement(namedPermissions, PolicyStatementAttribute.Exclusive); // Create a FirstMatchCodeGroup with a membership condition that // matches all code, and an exclusive policy. FirstMatchCodeGroup codeGroup = new FirstMatchCodeGroup(new AllMembershipCondition(), policy);

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FirstMatchCodeGroup プロパティ

名前 | 説明 | |
---|---|---|
![]() | AttributeString | コード グループのポリシー ステートメントの属性の文字列形式を取得します。 ( CodeGroup から継承されます。) |
![]() | Children | コード グループの子コード グループを順序付けして示したリストを取得または設定します。 ( CodeGroup から継承されます。) |
![]() | Description | コード グループの説明を取得または設定します。 ( CodeGroup から継承されます。) |
![]() | MembershipCondition | コード グループのメンバシップ条件を取得または設定します。 ( CodeGroup から継承されます。) |
![]() | MergeLogic | オーバーライドされます。 マージ ロジックを取得します。 |
![]() | Name | コード グループの名前を取得または設定します。 ( CodeGroup から継承されます。) |
![]() | PermissionSetName | コード グループの名前付きアクセス許可セットの名前を取得します。 ( CodeGroup から継承されます。) |
![]() | PolicyStatement | コード グループに関連付けられているポリシー ステートメントを取得または設定します。 ( CodeGroup から継承されます。) |

FirstMatchCodeGroup メソッド

名前 | 説明 | |
---|---|---|
![]() | AddChild | 子コード グループを現在のコード グループに追加します。 ( CodeGroup から継承されます。) |
![]() | Copy | オーバーライドされます。 コード グループの詳細コピーを作成します。 |
![]() | Equals | オーバーロードされます。 2 つのコード グループが等しいかどうかを確認します。 ( CodeGroup から継承されます。) |
![]() | FromXml | オーバーロードされます。 XML エンコーディングから、特定の状態のセキュリティ オブジェクトを再構築します。 ( CodeGroup から継承されます。) |
![]() | GetHashCode | 現在のコード グループのハッシュ コードを取得します。 ( CodeGroup から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | RemoveChild | 指定した子コード グループを削除します。 ( CodeGroup から継承されます。) |
![]() | Resolve | オーバーライドされます。 一連の証拠について、コード グループおよびその子孫のポリシーを解決します。 |
![]() | ResolveMatchingCodeGroups | オーバーライドされます。 一致しているコード グループを解決します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | ToXml | オーバーロードされます。 セキュリティ オブジェクトとその現在の状態を表す XML エンコーディングを作成します。 ( CodeGroup から継承されます。) |

FirstMatchCodeGroup メンバ
コード グループのポリシー ステートメントと、一致した最初の子コード グループのポリシー ステートメントの和集合によってセキュリティ ポリシーを定義できます。このクラスは継承できません。
FirstMatchCodeGroup データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | AttributeString | コード グループのポリシー ステートメントの属性の文字列形式を取得します。(CodeGroup から継承されます。) |
![]() | Children | コード グループの子コード グループを順序付けして示したリストを取得または設定します。(CodeGroup から継承されます。) |
![]() | Description | コード グループの説明を取得または設定します。(CodeGroup から継承されます。) |
![]() | MembershipCondition | コード グループのメンバシップ条件を取得または設定します。(CodeGroup から継承されます。) |
![]() | MergeLogic | オーバーライドされます。 マージ ロジックを取得します。 |
![]() | Name | コード グループの名前を取得または設定します。(CodeGroup から継承されます。) |
![]() | PermissionSetName | コード グループの名前付きアクセス許可セットの名前を取得します。(CodeGroup から継承されます。) |
![]() | PolicyStatement | コード グループに関連付けられているポリシー ステートメントを取得または設定します。(CodeGroup から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | AddChild | 子コード グループを現在のコード グループに追加します。 (CodeGroup から継承されます。) |
![]() | Copy | オーバーライドされます。 コード グループの詳細コピーを作成します。 |
![]() | Equals | オーバーロードされます。 2 つのコード グループが等しいかどうかを確認します。 (CodeGroup から継承されます。) |
![]() | FromXml | オーバーロードされます。 XML エンコーディングから、特定の状態のセキュリティ オブジェクトを再構築します。 (CodeGroup から継承されます。) |
![]() | GetHashCode | 現在のコード グループのハッシュ コードを取得します。 (CodeGroup から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | RemoveChild | 指定した子コード グループを削除します。 (CodeGroup から継承されます。) |
![]() | Resolve | オーバーライドされます。 一連の証拠について、コード グループおよびその子孫のポリシーを解決します。 |
![]() | ResolveMatchingCodeGroups | オーバーライドされます。 一致しているコード グループを解決します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | ToXml | オーバーロードされます。 セキュリティ オブジェクトとその現在の状態を表す XML エンコーディングを作成します。 (CodeGroup から継承されます。) |

Weblioに収録されているすべての辞書からFirstMatchCodeGroupを検索する場合は、下記のリンクをクリックしてください。

- FirstMatchCodeGroupのページへのリンク