Merge pull request #3962 from mkorkalo/fix_MonoBtlsContext_memory_leak
[mono.git] / mcs / class / referencesource / System.Web / IntSecurity.cs
1 namespace System.Web {
2     using System.Web;
3     using System.Web.Util;
4     using System.Security;
5     using System.Security.Permissions;
6
7     internal static class InternalSecurityPermissions {
8
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;
18
19         //
20         // Static permissions as properties, created on demand
21         //
22
23         internal static IStackWalk Unrestricted {
24             get {
25                 if (_unrestricted == null)
26                     _unrestricted = new PermissionSet(PermissionState.Unrestricted);
27
28                 Debug.Trace("Permissions", "Unrestricted Set");
29                 return _unrestricted;
30             }
31         }
32
33         internal static IStackWalk UnmanagedCode {
34             get {
35                 if (_unmanagedCode == null)
36                     _unmanagedCode = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
37
38                 Debug.Trace("Permissions", "UnmanagedCode");
39                 return _unmanagedCode;
40             }
41         }
42
43         internal static IStackWalk ControlPrincipal {
44             get {
45                 if (_controlPrincipal == null)
46                     _controlPrincipal = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
47
48                 Debug.Trace("Permissions", "ControlPrincipal");
49                 return _controlPrincipal;
50             }
51         }
52
53         internal static IStackWalk Reflection {
54             get {
55                 if (_reflection == null)
56                     _reflection = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
57
58                 Debug.Trace("Permissions", "Reflection");
59                 return _reflection;
60             }
61         }
62
63         internal static IStackWalk AppPathDiscovery {
64             get {
65                 if (_appPathDiscovery == null)
66                     _appPathDiscovery = new FileIOPermission(FileIOPermissionAccess.PathDiscovery, HttpRuntime.AppDomainAppPathInternal);
67
68                 Debug.Trace("Permissions", "AppPathDiscovery");
69                 return _appPathDiscovery;
70             }
71         }
72
73         internal static IStackWalk ControlThread {
74             get {
75                 if (_controlThread == null)
76                     _controlThread = new SecurityPermission(SecurityPermissionFlag.ControlThread);
77
78                 Debug.Trace("Permissions", "ControlThread");
79                 return _controlThread;
80             }
81         }
82
83         internal static IStackWalk AspNetHostingPermissionLevelLow {
84             get {
85                 if (_levelLow == null)
86                     _levelLow = new AspNetHostingPermission(AspNetHostingPermissionLevel.Low);
87
88                 Debug.Trace("Permissions", "AspNetHostingPermissionLevelLow");
89                 return _levelLow;
90             }
91         }
92
93         internal static IStackWalk AspNetHostingPermissionLevelMedium {
94             get {
95                 if (_levelMedium == null)
96                     _levelMedium = new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium);
97
98                 Debug.Trace("Permissions", "AspNetHostingPermissionLevelMedium");
99                 return _levelMedium;
100             }
101         }
102
103         internal static IStackWalk AspNetHostingPermissionLevelHigh {
104             get {
105                 if (_levelHigh == null)
106                     _levelHigh = new AspNetHostingPermission(AspNetHostingPermissionLevel.High);
107
108                 Debug.Trace("Permissions", "AspNetHostingPermissionLevelHigh");
109                 return _levelHigh;
110             }
111         }
112
113
114         // Parameterized permissions
115
116         internal static IStackWalk FileReadAccess(String filename) {
117             Debug.Trace("Permissions", "FileReadAccess(" + filename + ")");
118             return new FileIOPermission(FileIOPermissionAccess.Read, filename);
119         }
120
121         internal static IStackWalk FileWriteAccess(String filename) {
122             Debug.Trace("Permissions", "FileWriteAccess(" + filename + ")");
123             return new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Append, filename);
124         }
125
126         internal static IStackWalk PathDiscovery(String path) {
127             Debug.Trace("Permissions", "PathDiscovery(" + path + ")");
128             return new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path);
129         }
130
131     }
132 }