SemaphoreAccessRule Costruttori
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della classe SemaphoreAccessRule.
Overload
| Nome | Descrizione |
|---|---|
| SemaphoreAccessRule(IdentityReference, SemaphoreRights, AccessControlType) |
Inizializza una nuova istanza della SemaphoreAccessRule classe , specificando l'utente o il gruppo a cui si applica la regola, i diritti di accesso e se i diritti di accesso specificati sono consentiti o negati. |
| SemaphoreAccessRule(String, SemaphoreRights, AccessControlType) |
Inizializza una nuova istanza della SemaphoreAccessRule classe , specificando il nome dell'utente o del gruppo a cui si applica la regola, i diritti di accesso e se i diritti di accesso specificati sono consentiti o negati. |
SemaphoreAccessRule(IdentityReference, SemaphoreRights, AccessControlType)
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
Inizializza una nuova istanza della SemaphoreAccessRule classe , specificando l'utente o il gruppo a cui si applica la regola, i diritti di accesso e se i diritti di accesso specificati sono consentiti o negati.
public:
SemaphoreAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::SemaphoreRights eventRights, System::Security::AccessControl::AccessControlType type);
public SemaphoreAccessRule(System.Security.Principal.IdentityReference identity, System.Security.AccessControl.SemaphoreRights eventRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.SemaphoreAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.SemaphoreRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.SemaphoreAccessRule
Public Sub New (identity As IdentityReference, eventRights As SemaphoreRights, type As AccessControlType)
Parametri
- identity
- IdentityReference
L'utente o il gruppo a cui si applica la regola. Deve essere di tipo o di un tipo SecurityIdentifier , ad esempio NTAccount , che può essere convertito nel tipo SecurityIdentifier.
- eventRights
- SemaphoreRights
Combinazione bit per bit di SemaphoreRights valori che specificano i diritti consentiti o negati.
- type
- AccessControlType
Uno dei AccessControlType valori che specifica se i diritti sono consentiti o negati.
Eccezioni
eventRights specifica un valore non valido.
oppure
type specifica un valore non valido.
identity non è né di tipo né di un tipo SecurityIdentifier , NTAccount ad esempio che può essere convertito in tipo SecurityIdentifier.
Commenti
Per immettere un Semaphoreoggetto , ad esempio chiamando il WaitOne metodo , un utente deve avere SemaphoreRights.Synchronize accesso. Per uscire dal semaforo, chiamando il Release metodo , l'utente deve avere SemaphoreRights.Modify accesso.
Si applica a
SemaphoreAccessRule(String, SemaphoreRights, AccessControlType)
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
- Origine:
- SemaphoreSecurity.cs
Inizializza una nuova istanza della SemaphoreAccessRule classe , specificando il nome dell'utente o del gruppo a cui si applica la regola, i diritti di accesso e se i diritti di accesso specificati sono consentiti o negati.
public:
SemaphoreAccessRule(System::String ^ identity, System::Security::AccessControl::SemaphoreRights eventRights, System::Security::AccessControl::AccessControlType type);
public SemaphoreAccessRule(string identity, System.Security.AccessControl.SemaphoreRights eventRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.SemaphoreAccessRule : string * System.Security.AccessControl.SemaphoreRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.SemaphoreAccessRule
Public Sub New (identity As String, eventRights As SemaphoreRights, type As AccessControlType)
Parametri
- identity
- String
Nome dell'utente o del gruppo a cui si applica la regola.
- eventRights
- SemaphoreRights
Combinazione bit per bit di SemaphoreRights valori che specificano i diritti consentiti o negati.
- type
- AccessControlType
Uno dei AccessControlType valori che specifica se i diritti sono consentiti o negati.
Eccezioni
eventRights specifica un valore non valido.
oppure
type specifica un valore non valido.
eventRights è zero.
identity è null.
oppure
identity è una stringa di lunghezza zero.
oppure
identity è più lungo di 512 caratteri.
Esempio
Nell'esempio di codice seguente viene illustrato l'uso di questo costruttore per creare SemaphoreAccessRule oggetti. Nell'esempio viene creato un SemaphoreSecurity oggetto , vengono aggiunte regole che consentono e negano vari diritti per l'utente corrente e visualizza la coppia di regole risultante. Nell'esempio vengono quindi consentiti nuovi diritti per l'utente corrente e viene visualizzato il risultato, che mostra che i nuovi diritti vengono uniti alla regola esistente Allow .
Note
In questo esempio non viene associato l'oggetto di sicurezza a un Semaphore oggetto . Esempi che collegano oggetti di sicurezza sono disponibili in Semaphore.GetAccessControl e Semaphore.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
Commenti
Per immettere un Semaphoreoggetto , ad esempio chiamando il WaitOne metodo , un utente deve avere SemaphoreRights.Synchronize accesso. Per uscire dal semaforo, chiamando il Release metodo , l'utente deve avere SemaphoreRights.Modify accesso.
Questo costruttore equivale alla creazione di un NTAccount oggetto, passando identity al NTAccount.NTAccount(String) costruttore e passando l'oggetto appena creato NTAccount al SemaphoreAccessRule(IdentityReference, SemaphoreRights, AccessControlType) costruttore.