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

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

PolicyLevel.AddNamedPermissionSet メソッド

NamedPermissionSet現在のポリシー レベル追加します

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

Public Sub AddNamedPermissionSet ( _
    permSet As NamedPermissionSet _
)
Dim instance As PolicyLevel
Dim permSet As NamedPermissionSet

instance.AddNamedPermissionSet(permSet)
public void AddNamedPermissionSet (
    NamedPermissionSet permSet
)
public:
void AddNamedPermissionSet (
    NamedPermissionSet^ permSet
)
public void AddNamedPermissionSet (
    NamedPermissionSet permSet
)
public function AddNamedPermissionSet (
    permSet : NamedPermissionSet
)

パラメータ

permSet

現在のポリシー レベル追加する NamedPermissionSet。

例外例外
例外種類条件

ArgumentNullException

permSet パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentException

permSet パラメータが、PolicyLevel の既存NamedPermissionSet と同じ名前です。

解説解説
使用例使用例

名前を指定してアクセス許可ポリシー レベル追加する方法次のコード例示します。このコード例は、PolicyLevel クラストピック取り上げているコード例一部分です。

' Create a custom named permission set based on the LocalIntranet permission
 set.
Private Shared Sub CreateCompanyPermission()
    Dim policyEnumerator As IEnumerator = SecurityManager.PolicyHierarchy()
    ' Move through the policy levels to the Machine policy level.
    While policyEnumerator.MoveNext()
        Dim currentLevel As PolicyLevel = CType(policyEnumerator.Current,
 PolicyLevel)
        If currentLevel.Label = "Machine"
 Then
            ' Enumerate the permission sets in the Machine policy level.
            Dim namedPermissions As IList =
 currentLevel.NamedPermissionSets
            Dim namedPermission As IEnumerator
 = namedPermissions.GetEnumerator()
            ' Locate the LocalIntranet permission set.
            While namedPermission.MoveNext()
                If CType(namedPermission.Current, NamedPermissionSet).Name
 = "LocalIntranet" Then
                    ' The current permission set is a copy of the LocalIntranet
 permission set.
                    ' It can be modified to provide the permissions
 for the new permission set.
                    ' Rename the copy to the name chosen for the new
 permission set.
                    CType(namedPermission.Current, NamedPermissionSet).Name = "MyCompany"
                    Dim permissions As IEnumerator
 = CType(namedPermission.Current, NamedPermissionSet).GetEnumerator()
                    ' Remove the current security permission from the
 permission set and replace it 
                    ' with a new security permission that does not have
 the right to assert permissions.
                    While permissions.MoveNext()
                        If permissions.Current.GetType().ToString()
 = "System.Security.Permissions.SecurityPermission"
 Then
                            ' Remove the current security permission.
                            CType(namedPermission.Current, NamedPermissionSet).RemovePermission(permissions.Current.GetType())
                            ' Add a new security permission that only
 allows execution.
                            CType(namedPermission.Current, NamedPermissionSet).AddPermission(New
 SecurityPermission(SecurityPermissionFlag.Execution))
                            Exit While
                        End If
                    End While
                    Try
                        ' If you run this application twice, the following
 instruction throws
                        ' an exception because the named permission
 set is already present.
                        ' You can remove the custom named permission
 set using Caspole.exe or the  
                        ' .NET Framework Configuration tool 
                        currentLevel.AddNamedPermissionSet(CType(namedPermission.Current,
 NamedPermissionSet))
                        SecurityManager.SavePolicy()
                        ' Catch the exception for a duplicate permission
 set.
                    Catch e As System.ArgumentException
                        Console.WriteLine(e.Message)
                        Return
                    End Try
                    Console.WriteLine(CType(namedPermission.Current, NamedPermissionSet).ToString())
                    Exit While
                End If
            End While
        End If
    End While
End Sub 'CreateCompanyPermission

// Create a custom named permission set based on the LocalIntranet permission
 set.
private static void CreateCompanyPermission()
{
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();
    // Move through the policy levels to the Machine policy level.
    while(policyEnumerator.MoveNext())
    {
        PolicyLevel currentLevel = (PolicyLevel)policyEnumerator.Current;
        if(currentLevel.Label == "Machine")
        {
            // Enumerate the permission sets in the Machine policy level.
            IList namedPermissions = currentLevel.NamedPermissionSets;
            IEnumerator namedPermission = namedPermissions.GetEnumerator();
            // Locate the LocalIntranet permission set.
            while(namedPermission.MoveNext())
            {
                if(((NamedPermissionSet)namedPermission.Current).Name
 == "LocalIntranet")
                {
                    // The current permission set is a copy of the LocalIntranet
 permission set.
                    // It can be modified to provide the permissions
 for the new permission set.
                    // Rename the copy to the name chosen for the new
 permission set.
                    ((NamedPermissionSet)namedPermission.Current).Name = "MyCompany";
                    IEnumerator permissions = ((NamedPermissionSet)namedPermission.Current).GetEnumerator();
                    // Remove the current security permission from the
 permission set and replace it
                    // with a new security permission that does not
 have the right to assert permissions.
                    while(permissions.MoveNext())
                    {
                        if(permissions.Current.GetType().ToString()
 == "System.Security.Permissions.SecurityPermission")
                        {
                            // Remove the current security permission.
                            ((NamedPermissionSet)namedPermission.Current).RemovePermission(permissions.Current.GetType());
                            // Add a new security permission that only
 allows execution.
                            ((NamedPermissionSet)namedPermission.Current).AddPermission(new
 SecurityPermission(SecurityPermissionFlag.Execution));
                            break;
                        }
                    }
                    try
                    {
                        // If you run this application twice, the following
 instruction throws
                        // an exception because the named permission
 set is already present.
                        // You can remove the custom named permission
 set using Caspole.exe or the
                        // .NET Framework Configuration tool
                        currentLevel.AddNamedPermissionSet(((NamedPermissionSet)namedPermission.Current));
                        SecurityManager.SavePolicy();
                    }
                        // Catch the exception for a duplicate permission
 set.
                    catch ( System.ArgumentException e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                    Console.WriteLine(((NamedPermissionSet)namedPermission.Current).ToString());
                    break;
                }
            }
        }
    }
}
// Create a custom named permission set based on the LocalIntranet permission
 set.
void CreateCompanyPermission()
{
   IEnumerator^ policyEnumerator = SecurityManager::PolicyHierarchy();

   // Move through the policy levels to the Machine policy level.
   while ( policyEnumerator->MoveNext() )
   {
      PolicyLevel^ currentLevel = dynamic_cast<PolicyLevel^>(policyEnumerator->Current);
      if ( currentLevel->Label->Equals( "Machine"
 ) )
      {
         // Enumerate the permission sets in the Machine policy level.
         IList^ namedPermissions = currentLevel->NamedPermissionSets;
         IEnumerator^ namedPermission = namedPermissions->GetEnumerator();

         // Locate the LocalIntranet permission set.
         while ( namedPermission->MoveNext() )
         {
            if ( (dynamic_cast<NamedPermissionSet^>(namedPermission->Current))->Name->Equals(
 "LocalIntranet" ) )
            {
               // The current permission set is a copy of the LocalIntranet
 permission set.
               // It can be modified to provide the permissions for
 the new permission set.
               // Rename the copy to the name chosen for the new permission
 set.
               (dynamic_cast<NamedPermissionSet^>(namedPermission->Current))->Name
 = "MyCompany";
               IEnumerator^ permissions = (dynamic_cast<NamedPermissionSet^>(namedPermission->Current))->GetEnumerator();

               // Remove the current security permission from the permission
 set and replace it 
               // with a new security permission that does not have
 the right to assert permissions.
               while ( permissions->MoveNext() )
               {
                  if ( permissions->Current->GetType()->ToString()->Equals(
 "System.Security.Permissions.SecurityPermission" ) )
                  {
                     // Remove the current security permission.
                     (dynamic_cast<NamedPermissionSet^>(namedPermission->Current))->RemovePermission(
 permissions->Current->GetType() );

                     // Add a new security permission that only allows
 execution.
                     (dynamic_cast<NamedPermissionSet^>(namedPermission->Current))->AddPermission(
 gcnew SecurityPermission( SecurityPermissionFlag::Execution ) );
                     break;
                  }
               }
               try
               {
                  // If you run this application twice, the following
 instruction throws
                  // an exception because the named permission set is
 already present.
                  // You can remove the custom named permission set
 using Caspole.exe or the  
                  // .NET Framework Configuration tool 
                  currentLevel->AddNamedPermissionSet( safe_cast<NamedPermissionSet^>(namedPermission->Current)
 );
                  SecurityManager::SavePolicy();
               }
               // Catch the exception for a duplicate permission set.
               catch ( System::ArgumentException^ e ) 
               {
                  Console::WriteLine( e->Message );
                  return;
               }

               Console::WriteLine(  );
               break;
            }
         }
      }
   }
}
// Create a custom named permission set based on the LocalIntranet
// permission set.
private static void CreateCompanyPermission()
{
    IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();

    // Move through the policy levels to the Machine policy level.
    while (policyEnumerator.MoveNext()) {
        PolicyLevel currentLevel = 
            ((PolicyLevel)(policyEnumerator.get_Current()));
        if (currentLevel.get_Label().equalsIgnoreCase("Machine"))
 {
            // Enumerate the permission sets in the Machine policy level.
            IList namedPermissions =
                currentLevel.get_NamedPermissionSets();
            IEnumerator namedPermission = 
                namedPermissions.GetEnumerator();

            // Locate the LocalIntranet permission set.
            while (namedPermission.MoveNext()) {
                if (((NamedPermissionSet)(namedPermission.get_Current()))
                        .get_Name().equalsIgnoreCase("LocalIntranet"))
 {
                    // The current permission set is a copy of the
                    // LocalIntranet permission set.It can be modified
                    // to provide the permissions for the new permission
                    // set.Rename the copy to the name chosen for the
 new
                    // permission set.
                    ((NamedPermissionSet)(namedPermission.get_Current())).
                        set_Name("MyCompany");

                    IEnumerator permissions = ((NamedPermissionSet)
                        (namedPermission.get_Current())).GetEnumerator();

                    // Remove the current security permission from the
                    // permission set and replace it with a new security
                    // permission that does not have the right to assert
                    // permissions.
                    while (permissions.MoveNext()) {
                        if (
                            permissions.get_Current().GetType().ToString()
                            .equalsIgnoreCase("System.Security."
                            + "Permissions.SecurityPermission")) {
                            // Remove the current security permission.
                            ((NamedPermissionSet)
                                (namedPermission.get_Current()))
                                .RemovePermission(permissions.get_Current()
                                .GetType());

                            // Add a new security permission that only
                            // allows execution.
                            ((NamedPermissionSet)
                            (namedPermission.get_Current()))
                            .AddPermission(new SecurityPermission
                            (SecurityPermissionFlag.Execution));
                            break;
                        }
                    }

                    try {
                        // If you run this application twice, the following
                        // instruction throws an exception because the
                        // named permission set is already present.You
 can
                        // remove the custom named permission set using
                        // Caspole.exe or the
                        // .NET Framework Configuration tool
                        currentLevel.AddNamedPermissionSet(
                            ((NamedPermissionSet)
                            (namedPermission.get_Current())));
                        SecurityManager.SavePolicy();
                    }
                    // Catch the exception for a duplicate permission
 set.
                    catch (System.ArgumentException e) {
                        Console.WriteLine(e.get_Message());
                        return;
                    }
                    Console.WriteLine(((NamedPermissionSet)
                        (namedPermission.get_Current())).ToString());
                    break;
                }
            }
        }
    }
} //CreateCompanyPermission
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
PolicyLevel クラス
PolicyLevel メンバ
System.Security.Policy 名前空間



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS