5 using System.Security.Permissions;
7 internal static class InternalSecurityPermissions {
9 private static IStackWalk _unrestricted;
10 private static IStackWalk _unmanagedCode;
11 private static IStackWalk _controlPrincipal;
12 private static IStackWalk _reflection;
13 private static IStackWalk _appPathDiscovery;
14 private static IStackWalk _controlThread;
15 private static IStackWalk _levelLow;
16 private static IStackWalk _levelMedium;
17 private static IStackWalk _levelHigh;
20 // Static permissions as properties, created on demand
23 internal static IStackWalk Unrestricted {
25 if (_unrestricted == null)
26 _unrestricted = new PermissionSet(PermissionState.Unrestricted);
28 Debug.Trace("Permissions", "Unrestricted Set");
33 internal static IStackWalk UnmanagedCode {
35 if (_unmanagedCode == null)
36 _unmanagedCode = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
38 Debug.Trace("Permissions", "UnmanagedCode");
39 return _unmanagedCode;
43 internal static IStackWalk ControlPrincipal {
45 if (_controlPrincipal == null)
46 _controlPrincipal = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
48 Debug.Trace("Permissions", "ControlPrincipal");
49 return _controlPrincipal;
53 internal static IStackWalk Reflection {
55 if (_reflection == null)
56 _reflection = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
58 Debug.Trace("Permissions", "Reflection");
63 internal static IStackWalk AppPathDiscovery {
65 if (_appPathDiscovery == null)
66 _appPathDiscovery = new FileIOPermission(FileIOPermissionAccess.PathDiscovery, HttpRuntime.AppDomainAppPathInternal);
68 Debug.Trace("Permissions", "AppPathDiscovery");
69 return _appPathDiscovery;
73 internal static IStackWalk ControlThread {
75 if (_controlThread == null)
76 _controlThread = new SecurityPermission(SecurityPermissionFlag.ControlThread);
78 Debug.Trace("Permissions", "ControlThread");
79 return _controlThread;
83 internal static IStackWalk AspNetHostingPermissionLevelLow {
85 if (_levelLow == null)
86 _levelLow = new AspNetHostingPermission(AspNetHostingPermissionLevel.Low);
88 Debug.Trace("Permissions", "AspNetHostingPermissionLevelLow");
93 internal static IStackWalk AspNetHostingPermissionLevelMedium {
95 if (_levelMedium == null)
96 _levelMedium = new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium);
98 Debug.Trace("Permissions", "AspNetHostingPermissionLevelMedium");
103 internal static IStackWalk AspNetHostingPermissionLevelHigh {
105 if (_levelHigh == null)
106 _levelHigh = new AspNetHostingPermission(AspNetHostingPermissionLevel.High);
108 Debug.Trace("Permissions", "AspNetHostingPermissionLevelHigh");
114 // Parameterized permissions
116 internal static IStackWalk FileReadAccess(String filename) {
117 Debug.Trace("Permissions", "FileReadAccess(" + filename + ")");
118 return new FileIOPermission(FileIOPermissionAccess.Read, filename);
121 internal static IStackWalk FileWriteAccess(String filename) {
122 Debug.Trace("Permissions", "FileWriteAccess(" + filename + ")");
123 return new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Append, filename);
126 internal static IStackWalk PathDiscovery(String path) {
127 Debug.Trace("Permissions", "PathDiscovery(" + path + ")");
128 return new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path);