SemaphoreAccessRule クラス

定義

ユーザーまたはグループに許可されたアクセス権セットまたは拒否されたアクセス権セットを表します。 このクラスは継承できません。

public ref class SemaphoreAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class SemaphoreAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class SemaphoreAccessRule : System.Security.AccessControl.AccessRule
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class SemaphoreAccessRule : System.Security.AccessControl.AccessRule
type SemaphoreAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type SemaphoreAccessRule = class
    inherit AccessRule
[<System.Runtime.InteropServices.ComVisible(false)>]
type SemaphoreAccessRule = class
    inherit AccessRule
Public NotInheritable Class SemaphoreAccessRule
Inherits AccessRule
継承
SemaphoreAccessRule
属性

次のコード例では、ルールとルールの分離 Allow を示し Deny 、互換性のあるルールの権限の組み合わせを示します。 この例では、オブジェクトを SemaphoreSecurity 作成し、現在のユーザーのさまざまな権限を許可および拒否するルールを追加し、結果の規則のペアを表示します。 次に、現在のユーザーに対して新しい権限を許可し、結果を表示し、新しい権限が既存 Allow のルールとマージされていることを示します。

注意

この例では、セキュリティ オブジェクトをオブジェクトに Semaphore アタッチしません。 セキュリティ オブジェクトをアタッチする例はSemaphore.GetAccessControlSemaphore.SetAccessControl

using System;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;

public class Example
{
    public static void Main()
    {
        // Create a string representing the current user.
        string user = Environment.UserDomainName + "\\" + 
            Environment.UserName;

        // Create a security object that grants no access.
        SemaphoreSecurity mSec = new SemaphoreSecurity();

        // Add a rule that grants the current user the 
        // right to enter or release the semaphore.
        SemaphoreAccessRule rule = new SemaphoreAccessRule(user, 
            SemaphoreRights.Synchronize | SemaphoreRights.Modify, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the semaphore.
        rule = new SemaphoreAccessRule(user, 
            SemaphoreRights.ChangePermissions, 
            AccessControlType.Deny);
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        ShowSecurity(mSec);

        // Add a rule that allows the current user the 
        // right to read permissions on the semaphore. This rule
        // is merged with the existing Allow rule.
        rule = new SemaphoreAccessRule(user, 
            SemaphoreRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        ShowSecurity(mSec);
    }

    private static void ShowSecurity(SemaphoreSecurity security)
    {
        Console.WriteLine("\r\nCurrent access rules:\r\n");

        foreach(SemaphoreAccessRule ar in 
            security.GetAccessRules(true, true, typeof(NTAccount)))
        {
            Console.WriteLine("        User: {0}", ar.IdentityReference);
            Console.WriteLine("        Type: {0}", ar.AccessControlType);
            Console.WriteLine("      Rights: {0}", ar.SemaphoreRights);
            Console.WriteLine();
        }
    }
}

/*This code example produces output similar to following:

Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, Synchronize


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, ReadPermissions, Synchronize
 */
Imports System.Threading
Imports System.Security.AccessControl
Imports System.Security.Principal

Public Class Example

    Public Shared Sub Main()

        ' Create a string representing the current user.
        Dim user As String = Environment.UserDomainName _ 
            & "\" & Environment.UserName

        ' Create a security object that grants no access.
        Dim mSec As New SemaphoreSecurity()

        ' Add a rule that grants the current user the 
        ' right to enter or release the semaphore.
        Dim rule As New SemaphoreAccessRule(user, _
            SemaphoreRights.Synchronize _
            Or SemaphoreRights.Modify, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the semaphore.
        rule = New SemaphoreAccessRule(user, _
            SemaphoreRights.ChangePermissions, _
            AccessControlType.Deny)
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        ShowSecurity(mSec)

        ' Add a rule that allows the current user the 
        ' right to read permissions on the semaphore. This 
        ' rule is merged with the existing Allow rule.
        rule = New SemaphoreAccessRule(user, _
            SemaphoreRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ShowSecurity(mSec)

    End Sub 

    Private Shared Sub ShowSecurity(ByVal security As SemaphoreSecurity)
        Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)

        For Each ar As SemaphoreAccessRule In _
            security.GetAccessRules(True, True, GetType(NTAccount))

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.SemaphoreRights)
            Console.WriteLine()
        Next

    End Sub
End Class 

'This code example produces output similar to following:
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, Synchronize
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, ReadPermissions, Synchronize

注釈

このSemaphoreAccessRuleクラスは、.NET Frameworkが、名前付きシステム セマフォのアクセス制御セキュリティWindows管理するために提供されるクラスのセットの 1 つです。 これらのクラスの概要と、基になるWindowsアクセス制御構造体との関係については、次を参照してくださいSemaphoreSecurity

注意

Windowsアクセス制御のセキュリティは、名前付きシステム セマフォに対してのみ意味があります。 オブジェクトが Semaphore ローカル セマフォを表す場合、アクセス制御は関係ありません。

名前付きセマフォに現在適用されている規則の一覧を取得するには、メソッドを Semaphore.GetAccessControl 使用してオブジェクトを SemaphoreSecurity 取得し、そのメソッドを GetAccessRules 使用してオブジェクトの SemaphoreAccessRule コレクションを取得します。

SemaphoreAccessRule オブジェクトは、基になる随意アクセス制御リスト (DACL) のアクセス制御エントリと一対一にマップされません。 セマフォのすべてのアクセス規則のセットを取得すると、そのセットには、すべてのアクセス制御エントリを表すために現在必要な最小数の規則が含まれます。

注意

ルールを適用および削除すると、基になるアクセス制御エントリが変更されます。 可能であれば、アクセス制御エントリの最小数を維持するために、ルール内の情報がマージされます。 したがって、現在のルールの一覧を読むと、追加したすべてのルールの一覧とまったく同じようには見えない場合があります。

オブジェクトを使用して SemaphoreAccessRule 、ユーザーまたはグループに対して許可または拒否するアクセス権を指定します。 オブジェクトは SemaphoreAccessRule 常に許可されたアクセスまたは拒否されたアクセスを表し、両方を表すことはありません。

名前付きシステム セマフォにルールを適用するには、メソッドを Semaphore.GetAccessControl 使用してオブジェクトを SemaphoreSecurity 取得します。 規則を SemaphoreSecurity 追加するメソッドを使用してオブジェクトを変更し、そのメソッドを Semaphore.SetAccessControl 使用してセキュリティ オブジェクトを再アタッチします。

重要

オブジェクトに対して SemaphoreSecurity 行った変更は、変更されたセキュリティ オブジェクトを名前付きセマフォに割り当てるメソッドを呼び出 Semaphore.SetAccessControl すまで、名前付きセマフォのアクセス レベルには影響しません。

SemaphoreAccessRule オブジェクトは不変です。 セマフォのセキュリティは、規則を追加または削除するためにクラスのメソッドを SemaphoreSecurity 使用して変更されます。このようにすると、基になるアクセス制御エントリが変更されます。

コンストラクター

SemaphoreAccessRule(IdentityReference, SemaphoreRights, AccessControlType)

規則を適用するユーザーまたはグループ、アクセス権、および指定したアクセス権を許可するかどうかを指定して、SemaphoreAccessRule クラスの新しいインスタンスを初期化します。

SemaphoreAccessRule(String, SemaphoreRights, AccessControlType)

規則を適用するユーザーまたはグループの名前、アクセス権、および指定したアクセス権を許可するかどうかを指定して、SemaphoreAccessRule クラスの新しいインスタンスを初期化します。

プロパティ

AccessControlType

この AccessControlType オブジェクトに関連付けられている AccessRule 値を取得します。

(継承元 AccessRule)
AccessMask

この規則のアクセス マスクを取得します。

(継承元 AuthorizationRule)
IdentityReference

この規則を適用する IdentityReference を取得します。

(継承元 AuthorizationRule)
InheritanceFlags

この規則を子オブジェクトが継承する方法を決定するフラグの値を取得します。

(継承元 AuthorizationRule)
IsInherited

この規則を明示的に設定するか、または親コンテナー オブジェクトから継承するかを指定する値を取得します。

(継承元 AuthorizationRule)
PropagationFlags

反映フラグの値を取得します。このフラグから、この規則を子オブジェクトに反映させる方法を判断します。 このプロパティは、InheritanceFlags 列挙体の値が None でない場合にのみ重要です。

(継承元 AuthorizationRule)
SemaphoreRights

アクセス規則で許可されたアクセス権または拒否されたアクセス権を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください