FileSystemAccessRule 클래스

정의

파일이나 디렉터리에 대한 액세스 규칙을 정의하는 ACE(액세스 제어 항목)를 추상적으로 나타낸 클래스입니다. 이 클래스는 상속될 수 없습니다.

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
상속
FileSystemAccessRule
특성

예제

다음 코드 예제에서는 클래스를 FileSecurity 추가 하 고 파일에서 ACE (액세스 제어 항목)를 제거 합니다. 이 예제를 실행하려면 유효한 사용자 또는 그룹 계정을 제공해야 합니다.

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

설명

클래스는 FileSystemAccessRule 사용자 계정, 제공할 액세스 유형(읽기, 쓰기 등) 및 해당 권한을 허용하거나 거부할지 여부를 지정하는 ACE(기본 액세스 제어 항목)의 추상화입니다. 이 클래스는 액세스 규칙이 자식 개체에 전파되는 방법을 지정할 수도 있습니다.

클래스를 FileSystemAccessRule 사용하여 새 액세스 규칙을 만듭니다. 또는 DirectorySecurity 클래스를 사용하여 FileSecurity 규칙을 유지할 수 있습니다.

생성자

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

사용자 계정에 대한 참조, 액세스 규칙과 관련된 작업 형식을 지정하는 값 및 작업의 허용 여부를 지정하는 값을 사용하여 FileSystemAccessRule 클래스의 새 인스턴스를 만듭니다.

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

사용자 계정에 대한 참조, 액세스 규칙과 관련된 작업 형식을 지정하는 값, 권한이 상속되는 방법을 결정하는 값, 권한이 전파되는 방법을 결정하는 값 및 작업의 허용 여부를 지정하는 값을 사용하여 FileSystemAccessRule 클래스의 새 인스턴스를 초기화합니다.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

사용자 계정의 이름, 액세스 규칙과 관련된 작업 형식을 지정하는 값 및 작업의 허용 여부를 설명하는 값을 사용하여 FileSystemAccessRule 클래스의 새 인스턴스를 만듭니다.

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

사용자 계정의 이름, 액세스 규칙과 관련된 작업 형식을 지정하는 값, 권한이 상속되는 방법을 결정하는 값, 권한이 전파되는 방법을 결정하는 값 및 작업의 허용 여부를 지정하는 값을 사용하여 FileSystemAccessRule 클래스의 새 인스턴스를 초기화합니다.

속성

AccessControlType

AccessControlType 개체와 관련된 AccessRule 값을 가져옵니다.

(다음에서 상속됨 AccessRule)
AccessMask

이 규칙의 액세스 마스크를 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
FileSystemRights

현재 FileSystemRights 개체와 관련된 FileSystemAccessRule 플래그를 가져옵니다.

IdentityReference

이 규칙이 적용되는 IdentityReference를 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
InheritanceFlags

이 규칙이 자식 개체에서 상속되는 방식을 결정하는 플래그 값을 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
IsInherited

이 규칙이 명시적으로 설정되는지 아니면 부모 컨테이너 개체에서 상속되는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 AuthorizationRule)
PropagationFlags

이 규칙의 상속이 자식 개체에 전파되는 방법을 결정하는 전파 플래그의 값을 가져옵니다. 이 속성은 InheritanceFlags 열거형의 값이 None이 아닐 때만 중요합니다.

(다음에서 상속됨 AuthorizationRule)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상