FileSystemAccessRule Klasa

Definicja

Reprezentuje abstrakcję wpisu kontroli dostępu (ACE), który definiuje regułę dostępu dla pliku lub katalogu. Klasa ta nie może być dziedziczona.

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
Dziedziczenie
FileSystemAccessRule
Atrybuty

Przykłady

Poniższy przykład kodu używa klasy do dodania FileSecurity , a następnie usunięcia wpisu kontroli dostępu (ACE) z pliku. Aby uruchomić ten przykład, musisz podać prawidłowe konto użytkownika lub grupy.

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

Uwagi

Klasa FileSystemAccessRule reprezentuje abstrakcję bazowego wpisu kontroli dostępu (ACE), który określa konto użytkownika, typ dostępu do zapewnienia (odczyt, zapis itd.) oraz to, czy zezwolić na to prawo, czy zezwolić na to prawo. Ta klasa może również określić, jak reguły dostępu są propagowane do obiektów podrzędnych.

Użyj klasy , FileSystemAccessRule aby utworzyć nową regułę dostępu. Regułę można utrwalać przy użyciu FileSecurity klasy or DirectorySecurity .

Konstruktory

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

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

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu odwołania do konta użytkownika, wartość określającą typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, czy też odmawiać operacji.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości określającej typ operacji skojarzonej z regułą dostępu oraz wartość opisujący, czy zezwolić na operację, czy jej odmówić.

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

Inicjuje nowe wystąpienie FileSystemAccessRule klasy przy użyciu nazwy konta użytkownika, wartości, która określa typ operacji skojarzonej z regułą dostępu, wartość określającą sposób dziedziczenia praw, wartość określającą sposób propagacji praw oraz wartość określającą, czy mają być propagowane prawa, oraz wartość określającą, czy zezwolić na operację, czy jej odmówić.

Właściwości

AccessControlType

AccessControlType Pobiera wartość skojarzona z tym AccessRule obiektem.

(Odziedziczone po AccessRule)
AccessMask

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

(Odziedziczone po AuthorizationRule)
FileSystemRights

FileSystemRights Pobiera flagi skojarzone z bieżącym FileSystemAccessRule obiektem.

IdentityReference

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

(Odziedziczone po AuthorizationRule)
InheritanceFlags

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

(Odziedziczone po AuthorizationRule)
IsInherited

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

(Odziedziczone po AuthorizationRule)
PropagationFlags

Pobiera wartość flag propagacji, które określają, jak 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 .

(Odziedziczone po AuthorizationRule)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

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

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

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

(Odziedziczone po Object)
ToString()

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

(Odziedziczone po Object)

Dotyczy