Udostępnij przez


EventWaitHandleAccessRule Klasa

Definicja

Reprezentuje zestaw praw dostępu dozwolonych lub odrzuconych dla użytkownika lub grupy. Tej klasy nie można dziedziczyć.

public ref class EventWaitHandleAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class EventWaitHandleAccessRule : System.Security.AccessControl.AccessRule
type EventWaitHandleAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type EventWaitHandleAccessRule = class
    inherit AccessRule
Public NotInheritable Class EventWaitHandleAccessRule
Inherits AccessRule
Dziedziczenie
EventWaitHandleAccessRule
Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano tworzenie i używanie EventWaitHandleAccessRule obiektów. W przykładzie tworzony jest EventWaitHandleSecurity obiekt, dodaje reguły zezwalające i odmawiające różnych praw dla bieżącego użytkownika oraz wyświetlające wynikową parę reguł. W tym przykładzie można następnie uzyskać nowe prawa dla bieżącego użytkownika i wyświetlić wynik pokazujący, że nowe prawa są scalane z istniejącą Allow regułą.

Uwaga / Notatka

W tym przykładzie obiekt zabezpieczeń nie jest dołączany do EventWaitHandle obiektu. Przykłady dołączania obiektów zabezpieczeń można znaleźć w temacie EventWaitHandle.GetAccessControl i EventWaitHandle.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.
        EventWaitHandleSecurity mSec = new EventWaitHandleSecurity();

        // Add a rule that grants the current user the 
        // right to wait on or signal the event.
        EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the event.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.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 event. This rule
        // is merged with the existing Allow rule.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        ShowSecurity(mSec);
    }

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

        foreach(EventWaitHandleAccessRule 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.EventWaitHandleRights);
            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 EventWaitHandleSecurity()

        ' Add a rule that grants the current user the 
        ' right to wait on or signal the event.
        Dim rule As New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.Synchronize _
            Or EventWaitHandleRights.Modify, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the event.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.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 event. This rule
        ' is merged with the existing Allow rule.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ShowSecurity(mSec)

    End Sub 

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

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

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.EventWaitHandleRights)
            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

Uwagi

Uwaga / Notatka

Ten typ jest obsługiwany tylko w systemie Windows.

Klasa EventWaitHandleAccessRule jest jednym z zestawów klas, które program .NET Framework zapewnia do zarządzania zabezpieczeniami kontroli dostępu systemu Windows dla nazwanych zdarzeń systemowych. Aby zapoznać się z omówieniem tych klas i ich relacji z podstawowymi strukturami kontroli dostępu systemu Windows, zobacz EventWaitHandleSecurity.

Uwaga / Notatka

Zabezpieczenia kontroli dostępu systemu Windows mają znaczenie tylko dla nazwanych zdarzeń systemowych. EventWaitHandle Jeśli obiekt reprezentuje zdarzenie lokalne, kontrola dostępu jest nieistotna.

Aby uzyskać listę reguł stosowanych obecnie do nazwanego zdarzenia, użyj metody w celu pobrania EventWaitHandleSecurity obiektu, a następnie użyj EventWaitHandle.GetAccessControl jej GetAccessRules metody w celu uzyskania kolekcji EventWaitHandleAccessRule obiektów.

EventWaitHandleAccessRule obiekty nie mapują pozycji "jeden do jednego" z wpisami kontroli dostępu na podstawowej liście kontroli dostępu (DACL). Po pobraniu zestawu wszystkich reguł dostępu dla zdarzenia zestaw zawiera minimalną liczbę reguł, które są obecnie wymagane do wyrażenia wszystkich wpisów kontroli dostępu.

Uwaga / Notatka

Podstawowe wpisy kontroli dostępu zmieniają się podczas stosowania i usuwania reguł. Informacje w regułach są scalane, jeśli to możliwe, aby zachować najmniejszą liczbę wpisów kontroli dostępu. W związku z tym po otrzymaniu bieżącej listy reguł może ona nie wyglądać dokładnie tak jak lista wszystkich dodanych reguł.

Użyj EventWaitHandleAccessRule obiektów, aby określić prawa dostępu, aby zezwolić lub odmówić użytkownikowi lub grupie. EventWaitHandleAccessRule Obiekt zawsze reprezentuje dozwolony dostęp lub odmowa dostępu, nigdy nie oba.

Aby zastosować regułę do nazwanego zdarzenia systemowego, użyj EventWaitHandle.GetAccessControl metody w celu pobrania EventWaitHandleSecurity obiektu. Zmodyfikuj EventWaitHandleSecurity obiekt przy użyciu jego metod, aby dodać regułę, a następnie użyj EventWaitHandle.SetAccessControl metody , aby ponownie dołączyć obiekt zabezpieczeń.

Ważne

Zmiany wprowadzone w EventWaitHandleSecurity obiekcie nie mają wpływu na poziomy dostępu nazwanego zdarzenia, dopóki nie wywołasz EventWaitHandle.SetAccessControl metody w celu przypisania zmienionego obiektu zabezpieczeń do nazwanego zdarzenia.

EventWaitHandleAccessRule obiekty są niezmienne. Zabezpieczenia zdarzenia są modyfikowane przy użyciu metod EventWaitHandleSecurity klasy w celu dodawania lub usuwania reguł. W ten sposób bazowe wpisy kontroli dostępu są modyfikowane.

Konstruktorów

Nazwa Opis
EventWaitHandleAccessRule(IdentityReference, EventWaitHandleRights, AccessControlType)

Inicjuje nowe wystąpienie EventWaitHandleAccessRule klasy, określając użytkownika lub grupę, do których ma zastosowanie reguła, prawa dostępu i czy określone prawa dostępu są dozwolone, czy blokowane.

EventWaitHandleAccessRule(String, EventWaitHandleRights, AccessControlType)

Inicjuje nowe wystąpienie EventWaitHandleAccessRule klasy, określając nazwę użytkownika lub grupy, do których ma zastosowanie reguła, prawa dostępu i czy określone prawa dostępu są dozwolone, czy blokowane.

Właściwości

Nazwa Opis
AccessControlType

AccessControlType Pobiera wartość skojarzona z tym AccessRule obiektem.

(Dziedziczone od AccessRule)
AccessMask

Pobiera maskę dostępu dla tej reguły.

(Dziedziczone od AuthorizationRule)
EventWaitHandleRights

Pobiera prawa dozwolone lub odrzucane przez regułę dostępu.

IdentityReference

Pobiera element IdentityReference , do którego ma zastosowanie ta reguła.

(Dziedziczone od AuthorizationRule)
InheritanceFlags

Pobiera wartość flag, które określają, jak ta reguła jest dziedziczona przez obiekty podrzędne.

(Dziedziczone od AuthorizationRule)
IsInherited

Pobiera wartość wskazującą, czy ta reguła jest jawnie ustawiona, czy dziedziczona z obiektu kontenera nadrzędnego.

(Dziedziczone od AuthorizationRule)
PropagationFlags

Pobiera wartość flag propagacji, które określają, w jaki sposób dziedziczenie tej reguły jest propagowane do obiektów podrzędnych. Ta właściwość jest znacząca tylko wtedy, gdy wartość InheritanceFlags wyliczenia nie Nonejest .

(Dziedziczone od AuthorizationRule)

Metody

Nazwa Opis
Equals(Object)

Określa, czy określony obiekt jest równy bieżącemu obiektowi.

(Dziedziczone od Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Dziedziczone od Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Dziedziczone od Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Dziedziczone od Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Dziedziczone od Object)

Dotyczy

Zobacz także