FileSystemAccessRule Klasse

Definition

Stellt eine Abstaktion eines Zugriffssteuerungseintrags (Access Control Entry - ACE) dar, der Zugriffsregeln für eine Datei oder ein Verzeichnis darstellt. Diese Klasse kann nicht vererbt werden.

public ref class FileSystemAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
type FileSystemAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type FileSystemAccessRule = class
    inherit AccessRule
Public NotInheritable Class FileSystemAccessRule
Inherits AccessRule
Vererbung
FileSystemAccessRule
Attribute

Beispiele

Im folgenden Codebeispiel wird die FileSecurity -Klasse verwendet, um einer Datei einen Zugriffssteuerungseintrag (Access Control Entry, ACE) hinzuzufügen und daraus zu entfernen. Sie müssen ein gültiges Benutzer- oder Gruppenkonto angeben, um dieses Beispiel auszuführen.

using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;

// Adds an ACL entry on the specified file for the specified account.

void AddFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{
    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Add the FileSystemAccessRule to the security settings. 
    fSecurity->AddAccessRule(gcnew FileSystemAccessRule
                                   (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

// Removes an ACL entry on the specified file for the specified account.

void RemoveFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{

    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Remove the FileSystemAccessRule from the security settings. 
    fSecurity->RemoveAccessRule(gcnew FileSystemAccessRule
                                      (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

int main()
{
    try
    {
        String^ fileName = "test.xml";

        Console::WriteLine("Adding access control entry for " + fileName);

        // Add the access control entry to the file.
        AddFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Removing access control entry from " + fileName);

        // Remove the access control entry from the file.
        RemoveFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Done.");
    }
    catch (Exception^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}
using System;
using System.IO;
using System.Security.AccessControl;

namespace FileSystemExample
{
    class FileExample
    {
        public static void Main()
        {
            try
            {
                string fileName = "test.xml";

                Console.WriteLine("Adding access control entry for "
                    + fileName);

                // Add the access control entry to the file.
                AddFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Removing access control entry from "
                    + fileName);

                // Remove the access control entry from the file.
                RemoveFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Add the FileSystemAccessRule to the security settings.
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Remove the FileSystemAccessRule from the security settings.
            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }
    }
}
Imports System.IO
Imports System.Security.AccessControl



Module FileExample

    Sub Main()
        Try
            Dim fileName As String = "test.xml"

            Console.WriteLine("Adding access control entry for " & fileName)

            ' Add the access control entry to the file.
            AddFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Removing access control entry from " & fileName)

            ' Remove the access control entry from the file.
            RemoveFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Done.")
        Catch e As Exception
            Console.WriteLine(e)
        End Try

    End Sub


    ' Adds an ACL entry on the specified file for the specified account.
    Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
  
        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim accessRule As FileSystemAccessRule = _
            New FileSystemAccessRule(account, rights, controlType)

        fSecurity.AddAccessRule(accessRule)

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub


    ' Removes an ACL entry on the specified file for the specified account.
    Sub RemoveFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Remove the FileSystemAccessRule from the security settings. 
        fSecurity.RemoveAccessRule(New FileSystemAccessRule(account, _
            rights, controlType))

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub
End Module

Hinweise

Die FileSystemAccessRule -Klasse stellt eine Abstraktion eines zugrunde liegenden Zugriffssteuerungseintrags (ACE) dar, der ein Benutzerkonto, den Typ des bereitzustellenden Zugriffs (Lesen, Schreiben usw.) angibt und angibt, ob dieses Recht zugelassen oder verweigert werden soll. Diese Klasse kann auch angeben, wie Zugriffsregeln an untergeordnete Objekte weitergegeben werden.

Verwenden Sie die FileSystemAccessRule -Klasse, um eine neue Zugriffsregel zu erstellen. Sie können die Regel mit der - oder DirectorySecurity -FileSecurityKlasse beibehalten.

Konstruktoren

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Initialisiert eine neue Instanz der FileSystemAccessRule-Klasse mit einem Verweis auf ein Benutzerkonto, einem Wert, der die der Zugriffsregel zugeordnete Operation angibt, und einem Wert, der angibt, ob die Operation zugelassen oder verweigert werden soll.

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Initialisiert eine neue Instanz der FileSystemAccessRule-Klasse mit einem Verweis auf ein Benutzerkonto, einem Wert, der die der Zugriffsregel zugeordnete Operation angibt, einem Wert, der angibt, wie Rechte geerbt werden, einem Wert, der angibt, wie Rechte weitergegeben werden, und einem Wert, der angibt, ob die Operation zugelassen oder verweigert werden soll.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Initialisiert eine neue Instanz der FileSystemAccessRule-Klasse mit den Namen eines Benutzerkontos, einem Wert, der die der Zugriffsregel zugeordnete Operation angibt, und einem Wert, der angibt, ob die Operation zugelassen oder verweigert werden soll.

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Initialisiert eine neue Instanz der FileSystemAccessRule-Klasse mit dem Namen eines Benutzerkontos, einem Wert, der die der Zugriffsregel zugeordnete Operation angibt, einem Wert, der angibt, wie Rechte geerbt werden, einem Wert, der angibt, wie Rechte weitergegeben werden, und einem Wert, der angibt, ob die Operation zugelassen oder verweigert werden soll.

Eigenschaften

AccessControlType

Ruft den AccessControlType-Wert ab, der diesem AccessRule-Objekt zugeordnet ist.

(Geerbt von AccessRule)
AccessMask

Ruft die Zugriffsmaske für diese Regel ab.

(Geerbt von AuthorizationRule)
FileSystemRights

Ruft die FileSystemRights-Flags ab, die dem aktuellen FileSystemAccessRule-Objekt zugeordnet sind.

IdentityReference

Ruft den IdentityReference ab, für den diese Regel gilt.

(Geerbt von AuthorizationRule)
InheritanceFlags

Ruft den Wert von Flags ab, die bestimmen, wie diese Regel von untergeordneten Objekten geerbt wird.

(Geerbt von AuthorizationRule)
IsInherited

Ruft einen Wert ab, der angibt, ob diese Regel explizit festgelegt oder von einem übergeordneten Containerobjekt geerbt wird.

(Geerbt von AuthorizationRule)
PropagationFlags

Ruft den Wert der Weitergabeflags ab, die bestimmen, wie die Vererbung dieser Regel an untergeordnete Objekte weitergegeben wird. Diese Eigenschaft ist nur dann wesentlich, wenn der Wert der InheritanceFlags-Enumeration nicht None ist.

(Geerbt von AuthorizationRule)

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für: