SemaphoreAccessRule 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一组允许或拒绝用户或组进行访问的权限。 此类不能被继承。
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
		- 继承
 
- 属性
 
示例
下面的代码示例演示了规则和Deny规则之间的Allow分离,并演示了兼容规则中权限的组合。 该示例创建一个 SemaphoreSecurity 对象,添加允许和拒绝当前用户的各种权限的规则,并显示生成的规则对。 然后,该示例为当前用户允许新权限并显示结果,显示新权限与现有 Allow 规则合并。
注意
此示例不将安全对象附加到 对象 Semaphore 。 可以在 和 Semaphore.SetAccessControl中找到Semaphore.GetAccessControl附加安全对象的示例。
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 访问控制安全性。 有关这些类及其与基础 Windows 访问控制结构的关系的概述,请参阅 SemaphoreSecurity。
注意
Windows 访问控制安全性仅对命名系统信号灯有意义。 Semaphore如果对象表示本地信号灯,则访问控制无关紧要。
若要获取当前应用于命名信号量的规则列表,请使用 Semaphore.GetAccessControl 方法获取 SemaphoreSecurity 对象,然后使用其 GetAccessRules 方法获取对象的集合 SemaphoreAccessRule 。
SemaphoreAccessRule 对象不会在基础自由访问控制列表中映射具有访问控制条目的一对一 (DACL) 。 获取信号灯的所有访问规则集时,该集包含当前表示所有访问控制条目所需的最小规则数。
注意
应用和删除规则时,基础访问控制条目会更改。 如果可能,将合并规则中的信息,以保持最少数量的访问控制条目。 因此,在阅读当前规则列表时,它看起来可能与添加的所有规则的列表不完全相同。
使用 SemaphoreAccessRule 对象指定允许或拒绝用户或组的访问权限。 对象 SemaphoreAccessRule 始终表示允许的访问或拒绝的访问,从不同时表示这两者。
若要将规则应用于命名系统信号量,请使用 Semaphore.GetAccessControl 方法获取 SemaphoreSecurity 对象。 SemaphoreSecurity通过使用对象的方法添加规则来修改对象,然后使用 Semaphore.SetAccessControl 方法重新附加安全对象。
重要
在调用 Semaphore.SetAccessControl 方法将SemaphoreSecurity更改的安全对象分配给命名信号灯之前,对对象所做的更改不会影响命名信号灯的访问级别。
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) |