SecurityManager.SavePolicy メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SecurityManager.SavePolicy メソッドの意味・解説 

SecurityManager.SavePolicy メソッド

変更されセキュリティ ポリシーの状態を保存します

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

Public Shared Sub SavePolicy
SecurityManager.SavePolicy
public static void SavePolicy
 ()
public:
static void SavePolicy ()
public static void SavePolicy
 ()
例外例外
例外種類条件

SecurityException

このメソッド呼び出すコードに SecurityPermissionFlag.ControlPolicy がありません。

解説解説
使用例使用例

詳細については、SecurityManager クラストピック参照してください

' Create new code groups using the custom named permission sets previously
 created.
Private Shared Sub CreateCodeGroups()
    ' Create instances of the named permission sets created earlier
 to establish the 
    ' permissions for the new code groups.
    Dim companyCodeSet As New
 NamedPermissionSet("MyCompany", PermissionState.Unrestricted)
    Dim departmentCodeSet As New
 NamedPermissionSet("MyDepartment", PermissionState.Unrestricted)
    ' Create new code groups using the named permission sets.
    Dim policyMyCompany As New
 PolicyStatement(companyCodeSet, PolicyStatementAttribute.LevelFinal)
    Dim policyMyDepartment As New
 PolicyStatement(departmentCodeSet, PolicyStatementAttribute.Exclusive)
    ' Create new code groups using UnionCodeGroup.
    Dim myCompanyZone = New UnionCodeGroup(New
 ZoneMembershipCondition(SecurityZone.Intranet), policyMyCompany)
    myCompanyZone.Name = "MyCompanyCodeGroup"

    Dim b1 As Byte() = {0,
 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 49,
 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 97, 123, 196, 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 230, 152, 218, 8, 206, 206, 170, 84, 111,
 145, 26, 208, 158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199, 111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91,
 212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180}
    Dim blob As New StrongNamePublicKeyBlob(b1)

    Dim myDepartmentZone = New UnionCodeGroup(New
 StrongNameMembershipCondition(blob, Nothing, Nothing),
 policyMyDepartment)
    myDepartmentZone.Name = "MyDepartmentCodeGroup"

    ' Move through the policy levels looking for the Machine policy
 level.
    ' Create two new code groups at that level.
    Dim policyEnumerator As IEnumerator = SecurityManager.PolicyHierarchy()
    While policyEnumerator.MoveNext()
        ' At the Machine level delete already existing copies of the
 custom code groups,
        ' then create the new code groups. 
        Dim currentLevel As PolicyLevel = CType(policyEnumerator.Current,
 PolicyLevel)
        If currentLevel.Label = "Machine"
 Then

            ' Remove old instances of the custom groups.
            DeleteCustomCodeGroups()
            ' Add the new code groups.
            '*******************************************************
            ' To add a child code group, add the child to the parent
 prior to adding 
            ' the parent to the root.
            myCompanyZone.AddChild(myDepartmentZone)
            ' Add the parent to the root code group.
            currentLevel.RootCodeGroup.AddChild(myCompanyZone)
            SecurityManager.SavePolicy()
        End If
    End While
    ' Save the security policy.
    SecurityManager.SavePolicy()
    Console.WriteLine("Security policy modified.")
    Console.WriteLine("New code groups added at the Machine policy
 level.")
End Sub 'CreateCodeGroups

// Create new code groups using the custom named permission sets previously
 created.
private static void CreateCodeGroups()
{
    // Create instances of the named permission sets created earlier
 to establish the
    // permissions for the new code groups.
    NamedPermissionSet companyCodeSet = new NamedPermissionSet("MyCompany"
,PermissionState.Unrestricted);
    NamedPermissionSet departmentCodeSet = new NamedPermissionSet("MyDepartment"
,PermissionState.Unrestricted);
    // Create new code groups using the named permission sets.
    PolicyStatement policyMyCompany = new PolicyStatement(companyCodeSet
,PolicyStatementAttribute.LevelFinal);
    PolicyStatement policyMyDepartment = new PolicyStatement(departmentCodeSet
,PolicyStatementAttribute.Exclusive);
    // Create new code groups using UnionCodeGroup.
    CodeGroup myCompanyZone = new UnionCodeGroup(new
 ZoneMembershipCondition(SecurityZone.Intranet), policyMyCompany);
    myCompanyZone.Name = "MyCompanyCodeGroup";

    byte[] b1 = { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0,
 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 237, 146, 145, 51, 34, 97, 123, 196,
 90, 174, 41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 230, 152, 218, 8, 206, 206, 170,84, 111, 145, 26, 208, 158, 240, 246, 219, 228, 34, 31, 163, 11,
 130, 16, 199, 111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59, 9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66, 66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108, 210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19, 227, 107, 25, 133, 70, 2, 220,
 83, 206, 71, 102, 245, 104, 252, 87, 109, 190, 56, 34, 180};
    StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);

    CodeGroup myDepartmentZone = new UnionCodeGroup(new
 StrongNameMembershipCondition(blob,null , null
 ), policyMyDepartment);
    myDepartmentZone.Name = "MyDepartmentCodeGroup";

    // Move through the policy levels looking for the Machine policy
 level.
    // Create two new code groups at that level.
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
    while(policyEnumerator.MoveNext())
    {
        // At the Machine level delete already existing copies of the
 custom code groups,
        // then create the new code groups.
        PolicyLevel currentLevel = (PolicyLevel)policyEnumerator.Current;
        if (currentLevel.Label == "Machine")
        {

            // Remove old instances of the custom groups.
            DeleteCustomCodeGroups();
            // Add the new code groups.
            //*******************************************************
            // To add a child code group, add the child to the parent
 prior to adding
            // the parent to the root.
            myCompanyZone.AddChild(myDepartmentZone);
            // Add the parent to the root code group.
            currentLevel.RootCodeGroup.AddChild(myCompanyZone);
            SecurityManager.SavePolicy();
        }
    }
    // Save the security policy.
    SecurityManager.SavePolicy();
    Console.WriteLine("Security policy modified.");
    Console.WriteLine("New code groups added at the Machine policy level.");
}
// Create new code groups using the custom named permission sets previously
 created.
void CreateCodeGroups()
{
   // Create instances of the named permission sets created earlier
 to establish the 
   // permissions for the new code groups.
   NamedPermissionSet^ companyCodeSet = gcnew NamedPermissionSet( "MyCompany",PermissionState::Unrestricted
 );
   NamedPermissionSet^ departmentCodeSet = gcnew NamedPermissionSet( "MyDepartment",PermissionState::Unrestricted
 );

   // Create new code groups using the named permission sets.
   PolicyStatement^ policyMyCompany = gcnew PolicyStatement( companyCodeSet,PolicyStatementAttribute::LevelFinal
 );
   PolicyStatement^ policyMyDepartment = gcnew PolicyStatement( departmentCodeSet,PolicyStatementAttribute::Exclusive
 );

   // Create new code groups using UnionCodeGroup.
   CodeGroup^ myCompanyZone = gcnew UnionCodeGroup( gcnew ZoneMembershipCondition(
 SecurityZone::Intranet ),policyMyCompany );
   myCompanyZone->Name = "MyCompanyCodeGroup";
   array<Byte>^b1 = {0,36,0,0,4,128,0,0,148,0,0,0,6,2,0,0,0,36,0,0,82,83,65
,49,0,4,0,0,1,0,1,0,237,146,145,51,34,97,123,196,90,174,41,170,173,221,41,193,175
,39,7,151,178,0,230,152,218,8,206,206,170,84,111,145,26,208,158,240,246,219,228,34,31,163,11,130,16,199,111,224,4,112,46,84,0,104,229,38,39,63,53,189,0,157,32,38
,34,109,0,171,114,244,34,59,9,232,150,192,247,175,104,143,171,42,219,66,66,194,191,218,121,59,92,42,37,158,13,108,210,189,9,203,204,32,48,91,212,101,193,19,227,107,25,133,70,2,220,83,206,71,102,245,104,252,87,109,190,56,34,180};
   StrongNamePublicKeyBlob^ blob = gcnew StrongNamePublicKeyBlob( b1 );
   CodeGroup^ myDepartmentZone = gcnew UnionCodeGroup( gcnew StrongNameMembershipCondition(
 blob,nullptr,nullptr ),policyMyDepartment );
   myDepartmentZone->Name = "MyDepartmentCodeGroup";

   // Move through the policy levels looking for the Machine policy
 level.
   // Create two new code groups at that level.
   IEnumerator^ policyEnumerator = SecurityManager::PolicyHierarchy();
   while ( policyEnumerator->MoveNext() )
   {
      // At the Machine level delete already existing copies of the
 custom code groups,
      // then create the new code groups. 
      PolicyLevel^ currentLevel = dynamic_cast<PolicyLevel^>(policyEnumerator->Current);
      if ( currentLevel->Label->Equals( "Machine"
 ) )
      {
         // Remove old instances of the custom groups.
         DeleteCustomCodeGroups();
         
         // Add the new code groups.
         //*******************************************************
         // To add a child code group, add the child to the parent prior
 to adding 
         // the parent to the root.
         myCompanyZone->AddChild( myDepartmentZone );

         // Add the parent to the root code group.
         currentLevel->RootCodeGroup->AddChild( myCompanyZone );
         SecurityManager::SavePolicy();
      }
   }

   SecurityManager::SavePolicy();
   Console::WriteLine( "Security policy modified." );
   Console::WriteLine( "New code groups added at the Machine policy level."
 );
}
// Create new code groups using the custom named permission sets previously
// created.
private static void CreateCodeGroups()
{
    // Create instances of the named permission sets created earlier
 to
    // establish the permissions for the new code groups.
    NamedPermissionSet companyCodeSet = new NamedPermissionSet
        ("MyCompany", PermissionState.Unrestricted);
    NamedPermissionSet departmentCodeSet = new NamedPermissionSet
        ("MyDepartment", PermissionState.Unrestricted);

    // Create new code groups using the named permission sets.
    PolicyStatement policyMyCompany = new PolicyStatement
        (companyCodeSet, PolicyStatementAttribute.LevelFinal);
    PolicyStatement policyMyDepartment = new PolicyStatement
        (departmentCodeSet, PolicyStatementAttribute.Exclusive);

    // Create new code groups using UnionCodeGroup.
    CodeGroup myCompanyZone = new UnionCodeGroup
        (new ZoneMembershipCondition(SecurityZone.Intranet),
        policyMyCompany);

    myCompanyZone.set_Name("MyCompanyCodeGroup");

    ubyte b1[] =  { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0,
                    0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 
                    1, 0, 237, 146, 145, 51, 34, 97, 123, 196, 90, 174,
                    41, 170, 173, 221, 41, 193, 175, 39, 7, 151, 178, 0, 
                    230, 152, 218, 8, 206, 206, 170, 84, 111, 145, 26, 208,
                    158, 240, 246, 219, 228, 34, 31, 163, 11, 130, 16, 199,
                    111, 224, 4, 112, 46, 84, 0, 104, 229, 38, 39, 63, 53, 
                    189, 0, 157, 32, 38, 34, 109, 0, 171, 114, 244, 34, 59,
                    9, 232, 150, 192, 247, 175, 104, 143, 171, 42, 219, 66,
                    66, 194, 191, 218, 121, 59, 92, 42, 37, 158, 13, 108,
                    210, 189, 9, 203, 204, 32, 48, 91, 212, 101, 193, 19,
                    227, 107, 25, 133, 70, 2, 220, 83, 206, 71, 102, 245,
                    104, 252, 87, 109, 190, 56, 34, 180 };
    
    StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(b1);
    CodeGroup myDepartmentZone =
        new UnionCodeGroup(new StrongNameMembershipCondition
        (blob, null, null), policyMyDepartment);

    myDepartmentZone.set_Name("MyDepartmentCodeGroup");

    // Move through the policy levels looking for the Machine policy
 level.
    // Create two new code groups at that level.
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
    
    while (policyEnumerator.MoveNext()) {
        // At the Machine level delete already existing copies of the
        // custom code groups,then create the new code groups.
        PolicyLevel currentLevel = 
            ((PolicyLevel)(policyEnumerator.get_Current()));
        if (currentLevel.get_Label().equalsIgnoreCase("Machine"))
 {
            // Remove old instances of the custom groups.
            DeleteCustomCodeGroups();

            // Add the new code groups.
            //*******************************************************
            // To add a child code group, add the child to the parent
            // prior to adding the parent to the root.
            myCompanyZone.AddChild(myDepartmentZone);

            // Add the parent to the root code group.
            currentLevel.get_RootCodeGroup().AddChild(myCompanyZone);
            SecurityManager.SavePolicy();
        }
    }
    // Save the security policy.
    SecurityManager.SavePolicy();
    Console.WriteLine("Security policy modified.");
    Console.WriteLine("New code groups added at the Machine"
        + " policy level.");
} //CreateCodeGroups

.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「SecurityManager.SavePolicy メソッド」の関連用語

SecurityManager.SavePolicy メソッドのお隣キーワード
検索ランキング

   

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



SecurityManager.SavePolicy メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS