FileSystemAccessRule Třída

Definice

Představuje abstrakci položky řízení přístupu (ACE), která definuje pravidlo přístupu pro soubor nebo adresář. Tuto třídu nelze dědit.

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
Dědičnost
FileSystemAccessRule
Atributy

Příklady

Následující příklad kódu používá FileSecurity třídu k přidání a následnému odebrání položky řízení přístupu (ACE) ze souboru. Abyste mohli tento příklad spustit, musíte zadat platný uživatelský nebo skupinový účet.

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

Poznámky

Třída FileSystemAccessRule představuje abstrakci podkladové položky řízení přístupu (ACE), která určuje uživatelský účet, typ přístupu, který se má poskytnout (čtení, zápis atd.) a zda má být toto právo povoleno nebo odepřeno. Tato třída může také určit způsob šíření pravidel přístupu do podřízených objektů.

FileSystemAccessRule Pomocí třídy vytvořte nové pravidlo přístupu. Pravidlo můžete zachovat pomocí FileSecurity třídy nebo DirectorySecurity .

Konstruktory

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Inicializuje novou instanci FileSystemAccessRule třídy pomocí odkazu na uživatelský účet, hodnotu, která určuje typ operace přidružené k pravidlu přístupu, a hodnotu, která určuje, zda má být operace povolena nebo odepřena.

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

Inicializuje novou instanci FileSystemAccessRule třídy pomocí odkazu na uživatelský účet, hodnotu, která určuje typ operace přidružené k pravidlu přístupu, hodnotu, která určuje způsob dědění práv, hodnotu určující způsob šíření práv a hodnotu, která určuje, zda se má operace povolit nebo odepřít.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Inicializuje novou instanci FileSystemAccessRule třídy pomocí názvu uživatelského účtu, hodnoty, která určuje typ operace přidružené k pravidlu přístupu, a hodnotu, která popisuje, zda povolit nebo zakázat operaci.

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

Inicializuje novou instanci FileSystemAccessRule třídy pomocí názvu uživatelského účtu, hodnoty, která určuje typ operace přidružené k pravidlu přístupu, hodnotu, která určuje způsob dědění práv, hodnotu určující způsob šíření práv a hodnotu, která určuje, zda se má operace povolit nebo odepřít.

Vlastnosti

AccessControlType

Získá hodnotu přidruženou AccessControlType k tomuto AccessRule objektu.

(Zděděno od AccessRule)
AccessMask

Získá masku přístupu pro toto pravidlo.

(Zděděno od AuthorizationRule)
FileSystemRights

FileSystemRights Získá příznaky přidružené k aktuálnímu FileSystemAccessRule objektu.

IdentityReference

Získá, IdentityReference na který se toto pravidlo vztahuje.

(Zděděno od AuthorizationRule)
InheritanceFlags

Získá hodnotu příznaků, které určují, jak je toto pravidlo zděděno podřízenými objekty.

(Zděděno od AuthorizationRule)
IsInherited

Získá hodnotu určující, zda je toto pravidlo explicitně nastaveno nebo je zděděno z nadřazeného objektu kontejneru.

(Zděděno od AuthorizationRule)
PropagationFlags

Získá hodnotu příznaků šíření, které určují, jak se dědičnost tohoto pravidla šíří do podřízených objektů. Tato vlastnost je významná pouze v případě, že hodnota výčtu InheritanceFlags není None.

(Zděděno od AuthorizationRule)

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro