SecurityAction 열거형
선언적 보안을 사용하여 수행할 수 있는 보안 동작을 지정합니다.
네임스페이스: System.Security.Permissions
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration SecurityAction
‘사용 방법
Dim instance As SecurityAction
[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum SecurityAction
[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum class SecurityAction
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public enum SecurityAction
SerializableAttribute
ComVisibleAttribute(true)
public enum SecurityAction
멤버
멤버 이름 | 설명 | |
---|---|---|
Assert | 스택의 상위 호출자에게 리소스에 대한 액세스 권한이 없더라도(Assert 메서드 사용 참조) 호출 코드를 사용하여 현재 권한 개체로 식별되는 리소스에 액세스할 수 있습니다. | |
Demand | 호출 스택의 모든 상위 호출자에게 현재 권한 개체가 지정하는 사용 권한을 부여해야 합니다(보안 요청 참조). | |
Deny | 호출자에게 리소스에 대한 액세스 권한이 있더라도(Deny 메서드 사용 참조) 현재 권한 개체가 지정하는 리소스에 액세스할 수 없습니다. | |
InheritanceDemand | 클래스를 상속하거나 메서드를 재정의하는 파생 클래스에는 지정된 사용 권한을 부여해야 합니다. | |
LinkDemand | 직접 실행 호출자에게 지정된 사용 권한을 부여해야 합니다.
선언적 보안 및 링크 요청에 대한 자세한 내용은 클래스 및 멤버 범위와 함께 사용되는 선언적 보안을 참조하십시오. |
|
PermitOnly | 코드에 다른 리소스에 액세스할 권한이 있더라도(PermitOnly 메서드 사용 참조) 이 권한 개체가 지정하는 리소스만 액세스할 수 있습니다. | |
RequestMinimum | 코드를 실행하는 데 필요한 최소 사용 권한에 대한 요청입니다. 이 동작은 어셈블리 범위 내에서만 사용할 수 있습니다. | |
RequestOptional | 실행에 필요하지 않은 옵션인 추가 사용 권한에 대한 요청입니다. 이 요청은 특별히 요청되지 않은 다른 모든 권한을 암시적으로 거부합니다. 이 동작은 어셈블리 범위 내에서만 사용할 수 있습니다. | |
RequestRefuse | 잘못 사용될 수 있는 사용 권한을 호출 코드에 부여하지 않도록 하는 요청입니다. 이 동작은 어셈블리 범위 내에서만 사용할 수 있습니다. |
설명
다음 표에서는 각 보안 동작이 발생하는 시간 및 지원하는 대상에 대해 설명합니다.
보안 동작의 선언 |
동작 발생 시간 |
지원 대상 |
---|---|---|
LinkDemand |
Just-In-Time 컴파일 |
클래스, 메서드 |
InheritanceDemand |
로드 시간 |
클래스, 메서드 |
Demand |
런타임 |
클래스, 메서드 |
Assert |
런타임 |
클래스, 메서드 |
Deny |
런타임 |
클래스, 메서드 |
PermitOnly |
런타임 |
클래스, 메서드 |
RequestMinimum |
허가 시간 |
어셈블리 |
RequestOptional |
허가 시간 |
어셈블리 |
RequestRefuse |
허가 시간 |
어셈블리 |
특성 대상에 대한 자세한 내용은 Attribute를 참조하십시오.
항목 | 위치 |
---|---|
방법: RequestRefuse 플래그를 사용하여 권한 거부 | .NET Framework: Security |
방법: RequestOptional 플래그를 사용하여 선택적 권한 요청 | .NET Framework: Security |
방법: RequestMinimum 플래그를 사용하여 최소 권한 요청 | .NET Framework: Security |
방법: RequestOptional 플래그를 사용하여 선택적 권한 요청 | .NET Framework: 보안 |
방법: RequestRefuse 플래그를 사용하여 권한 거부 | .NET Framework: 보안 |
방법: RequestMinimum 플래그를 사용하여 최소 권한 요청 | .NET Framework: 보안 |
예제
이 예제에서는 이 어셈블리의 코드에 IsolatedStoragePermission이 필요함을 CLR에 알리는 방법과 격리된 저장소에 대해 쓰기와 읽기를 수행하는 방법을 보여 줍니다.
using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;
// Notify the CLR to grant this assembly the IsolatedStorageFilePermission.
// This allows the assembly to work with storage files that are isolated
// by user and assembly.
[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public sealed class App
{
static void Main()
{
// Attempt to create a storage file that is isolated by user and assembly.
// IsolatedStorageFilePermission granted to the attribute at the top of this file
// allows CLR to load this assembly and execution of this statement.
using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly()))
{
// Write some data out to the isolated file.
using (StreamWriter sw = new StreamWriter(s))
{
sw.Write("This is some test data.");
}
}
// Attempt to open the file that was previously created.
using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly()))
{
// Read the data from the file and display it.
using (StreamReader sr = new StreamReader(s))
{
Console.WriteLine(sr.ReadLine());
}
}
}
}
// This code produces the following output.
//
// Some test data.
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO::IsolatedStorage;
using namespace System::IO;
// Notify the CLR to grant this assembly the IsolatedStorage-
// FilePermission. This allows the assembly to work with storage
// files that are isolated by user and assembly.
[assembly: IsolatedStorageFilePermission(
SecurityAction::RequestMinimum, UsageAllowed =
IsolatedStorageContainment::AssemblyIsolationByUser)];
int main()
{
try
{
// Attempt to create a storage file that is isolated by
// user and assembly. IsolatedStorageFilePermission
// granted to the attribute at the top of this file
// allows CLR to load this assembly and execution of this
// statement.
Stream^ fileCreateStream = gcnew
IsolatedStorageFileStream(
"AssemblyData",
FileMode::Create,
IsolatedStorageFile::GetUserStoreForAssembly());
StreamWriter^ streamWriter = gcnew StreamWriter(
fileCreateStream);
try
{
// Write some data out to the isolated file.
streamWriter->Write("This is some test data.");
streamWriter->Close();
}
finally
{
delete fileCreateStream;
delete streamWriter;
}
}
catch (IOException^ ex)
{
Console::WriteLine(ex->Message);
}
try
{
Stream^ fileOpenStream =
gcnew IsolatedStorageFileStream(
"AssemblyData",
FileMode::Open,
IsolatedStorageFile::GetUserStoreForAssembly());
// Attempt to open the file that was previously created.
StreamReader^ streamReader = gcnew StreamReader(
fileOpenStream);
try
{
// Read the data from the file and display it.
Console::WriteLine(streamReader->ReadLine());
streamReader->Close();
}
finally
{
delete fileOpenStream;
delete streamReader;
}
}
catch (FileNotFoundException^ ex)
{
Console::WriteLine(ex->Message);
}
catch (IOException^ ex)
{
Console::WriteLine(ex->Message);
}
}
// This code produces the following output.
//
// This is some test data.
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0에서 지원