次の方法で共有


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

注釈

この種類は、Windows でのみサポートされています。

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

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

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

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

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

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

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

Important

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

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

コンストラクター

名前 説明
SemaphoreAccessRule(IdentityReference, SemaphoreRights, AccessControlType)

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

SemaphoreAccessRule(String, SemaphoreRights, AccessControlType)

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

プロパティ

名前 説明
AccessControlType

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

(継承元 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)

適用対象

こちらもご覧ください