MutexAccessRule Classe
Definição
Representa um conjunto de direitos de acesso permitidos ou negados para um usuário ou grupo.Represents a set of access rights allowed or denied for a user or group. Essa classe não pode ser herdada.This class cannot be inherited.
public ref class MutexAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class MutexAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class MutexAccessRule : System.Security.AccessControl.AccessRule
type MutexAccessRule = class
inherit AccessRule
[<System.Security.SecurityCritical>]
type MutexAccessRule = class
inherit AccessRule
Public NotInheritable Class MutexAccessRule
Inherits AccessRule
- Herança
- Atributos
Exemplos
O exemplo de código a seguir demonstra a criação e o uso de MutexAccessRule objetos.The following code example demonstrates the creation and use of MutexAccessRule objects. O exemplo cria um MutexSecurity objeto, adiciona regras que permitem e negam vários direitos para o usuário atual e exibe o par de regras resultante.The example creates a MutexSecurity object, adds rules that allow and deny various rights for the current user, and displays the resulting pair of rules. Em seguida, o exemplo permite novos direitos para o usuário atual e exibe o resultado, mostrando que os novos direitos são mesclados com a Allow regra existente.The example then allows new rights for the current user and displays the result, showing that the new rights are merged with the existing Allow rule.
Observação
Este exemplo não anexa o objeto de segurança a um Mutex objeto.This example does not attach the security object to a Mutex object. Exemplos que anexam objetos de segurança podem ser encontrados em Mutex.GetAccessControl e Mutex.SetAccessControl .Examples that attach security objects can be found in Mutex.GetAccessControl and Mutex.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.
MutexSecurity mSec = new MutexSecurity();
// Add a rule that grants the current user the
// right to enter or release the mutex.
MutexAccessRule rule = new MutexAccessRule(user,
MutexRights.Synchronize | MutexRights.Modify,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
// Add a rule that denies the current user the
// right to change permissions on the mutex.
rule = new MutexAccessRule(user,
MutexRights.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 mutex. This rule
// is merged with the existing Allow rule.
rule = new MutexAccessRule(user,
MutexRights.ReadPermissions,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
ShowSecurity(mSec);
}
private static void ShowSecurity(MutexSecurity security)
{
Console.WriteLine("\r\nCurrent access rules:\r\n");
foreach(MutexAccessRule 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.MutexRights);
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 MutexSecurity()
' Add a rule that grants the current user the
' right to enter or release the mutex.
Dim rule As New MutexAccessRule(user, _
MutexRights.Synchronize _
Or MutexRights.Modify, _
AccessControlType.Allow)
mSec.AddAccessRule(rule)
' Add a rule that denies the current user the
' right to change permissions on the mutex.
rule = New MutexAccessRule(user, _
MutexRights.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 mutex. This rule
' is merged with the existing Allow rule.
rule = New MutexAccessRule(user, _
MutexRights.ReadPermissions, _
AccessControlType.Allow)
mSec.AddAccessRule(rule)
ShowSecurity(mSec)
End Sub
Private Shared Sub ShowSecurity(ByVal security As MutexSecurity)
Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)
For Each ar As MutexAccessRule In _
security.GetAccessRules(True, True, GetType(NTAccount))
Console.WriteLine(" User: {0}", ar.IdentityReference)
Console.WriteLine(" Type: {0}", ar.AccessControlType)
Console.WriteLine(" Rights: {0}", ar.MutexRights)
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
Comentários
A MutexAccessRule classe é um de um conjunto de classes que o .NET Framework fornece para gerenciar a segurança de controle de acesso do Windows em mutexes do sistema nomeados.The MutexAccessRule class is one of a set of classes that the .NET Framework provides for managing Windows access control security on named system mutexes. Para obter uma visão geral dessas classes e sua relação com as estruturas subjacentes de controle de acesso do Windows, consulte MutexSecurity .For an overview of these classes, and their relationship to the underlying Windows access control structures, see MutexSecurity.
Observação
A segurança de controle de acesso do Windows é significativa apenas para mutexes do sistema nomeados.Windows access control security is meaningful only for named system mutexes. Se um Mutex objeto representar um mutex local, o controle de acesso será irrelevante.If a Mutex object represents a local mutex, access control is irrelevant.
Para obter uma lista das regras atualmente aplicadas a um mutex nomeado, use o Mutex.GetAccessControl método para obter um MutexSecurity objeto e, em seguida, use seu GetAccessRules método para obter uma coleção de MutexAccessRule objetos.To get a list of the rules currently applied to a named mutex, use the Mutex.GetAccessControl method to get a MutexSecurity object, and then use its GetAccessRules method to obtain a collection of MutexAccessRule objects.
MutexAccessRule os objetos não mapeiam um-para-um com entradas de controle de acesso na DACL (lista de controle de acesso discricionário) subjacente.MutexAccessRule objects do not map one-to-one with access control entries in the underlying discretionary access control list (DACL). Quando você obtém o conjunto de todas as regras de acesso para um mutex, o conjunto contém o número mínimo de regras atualmente necessárias para expressar todas as entradas de controle de acesso.When you get the set of all access rules for a mutex, the set contains the minimum number of rules currently required to express all the access control entries.
Observação
As entradas de controle de acesso subjacentes são alteradas conforme você aplica e Remove regras.The underlying access control entries change as you apply and remove rules. As informações em regras são mescladas, se possível, para manter o menor número de entradas de controle de acesso.The information in rules is merged if possible, to maintain the smallest number of access control entries. Assim, quando você lê a lista atual de regras, ela pode não parecer exatamente como a lista de todas as regras que você adicionou.Thus, when you read the current list of rules, it might not look exactly like the list of all the rules you have added.
Use MutexAccessRule objetos para especificar direitos de acesso para permitir ou negar a um usuário ou grupo.Use MutexAccessRule objects to specify access rights to allow or deny to a user or group. Um MutexAccessRule objeto sempre representa o acesso permitido ou o acesso negado, nunca ambos.A MutexAccessRule object always represents either allowed access or denied access, never both.
Para aplicar uma regra a um mutex do sistema nomeado, use o Mutex.GetAccessControl método para obter o MutexSecurity objeto.To apply a rule to a named system mutex, use the Mutex.GetAccessControl method to get the MutexSecurity object. Modifique o MutexSecurity objeto usando seus métodos para adicionar a regra e, em seguida, use o Mutex.SetAccessControl método para anexar novamente o objeto de segurança.Modify the MutexSecurity object by using its methods to add the rule, and then use the Mutex.SetAccessControl method to reattach the security object.
Importante
As alterações feitas em um MutexSecurity objeto não afetam os níveis de acesso do mutex nomeado até que você chame o Mutex.SetAccessControl método para atribuir o objeto de segurança alterado ao mutex nomeado.Changes you make to a MutexSecurity object do not affect the access levels of the named mutex until you call the Mutex.SetAccessControl method to assign the altered security object to the named mutex.
MutexAccessRule os objetos são imutáveis.MutexAccessRule objects are immutable. A segurança de um mutex é modificada usando os métodos da MutexSecurity classe para adicionar ou remover regras; como você faz isso, as entradas de controle de acesso subjacentes são modificadas.Security for a mutex is modified using the methods of the MutexSecurity class to add or remove rules; as you do this, the underlying access control entries are modified.
Construtores
| MutexAccessRule(IdentityReference, MutexRights, AccessControlType) |
Inicializa uma nova instância da classe MutexAccessRule, especificando o usuário ou grupo ao qual a regra se aplica, os direitos de acesso e se estes são permitidos ou negados.Initializes a new instance of the MutexAccessRule class, specifying the user or group the rule applies to, the access rights, and whether the specified access rights are allowed or denied. |
| MutexAccessRule(String, MutexRights, AccessControlType) |
Inicializa uma nova instância da classe MutexAccessRule, especificando o nome do usuário ou do grupo ao qual a regra se aplica, os direitos de acesso e se eles são permitidos ou negados.Initializes a new instance of the MutexAccessRule class, specifying the name of the user or group the rule applies to, the access rights, and whether the specified access rights are allowed or denied. |
Propriedades
| AccessControlType |
Obtém o valor de AccessControlType associado a esse objeto AccessRule.Gets the AccessControlType value associated with this AccessRule object. (Herdado de AccessRule) |
| AccessMask |
Obtém a máscara de acesso para essa regra.Gets the access mask for this rule. (Herdado de AuthorizationRule) |
| IdentityReference |
Obtém o IdentityReference ao qual essa regra se aplica.Gets the IdentityReference to which this rule applies. (Herdado de AuthorizationRule) |
| InheritanceFlags |
Obtém o valor de sinalizadores que determinam como a essa regra é herdada por objetos filhos.Gets the value of flags that determine how this rule is inherited by child objects. (Herdado de AuthorizationRule) |
| IsInherited |
Obtém um valor que indica se esta regra é definida explicitamente ou é herdada de um objeto de contêiner pai.Gets a value indicating whether this rule is explicitly set or is inherited from a parent container object. (Herdado de AuthorizationRule) |
| MutexRights |
Obtém os direitos permitidos ou negados pela regra de acesso.Gets the rights allowed or denied by the access rule. |
| PropagationFlags |
Obtém o valor dos sinalizadores de propagação, que determinam como a herança dessa regra é propagada a objetos filho.Gets the value of the propagation flags, which determine how inheritance of this rule is propagated to child objects. Esta propriedade é significativa somente quando o valor de enumeração InheritanceFlags não é None.This property is significant only when the value of the InheritanceFlags enumeration is not None. (Herdado de AuthorizationRule) |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |