2 // System.Security.SecurityException.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
9 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Globalization;
33 using System.Reflection;
34 using System.Runtime.InteropServices;
35 using System.Runtime.Serialization;
36 using System.Security.Permissions;
37 using System.Security.Policy;
40 namespace System.Security {
44 public class SecurityException : SystemException, _Exception {
46 public class SecurityException : SystemException {
49 string permissionState;
51 private string _granted;
52 private string _refused;
54 private SecurityAction _action;
55 private object _demanded;
56 private object _denyset;
57 private object _permitset;
58 private AssemblyName _assembly;
59 private IPermission _firstperm;
60 private IPermission _permfailed;
61 private MethodInfo _method;
63 private SecurityZone _zone;
69 public SecurityAction Action {
70 get { return _action; }
71 set { _action = value; }
74 public object Demanded {
75 get { return _demanded; }
76 set { _demanded = value; }
79 public object DenySetInstance {
80 get { return _denyset; }
81 set { _denyset = value; }
84 public AssemblyName FailedAssemblyInfo {
85 get { return _assembly; }
86 set { _assembly = value; }
89 public IPermission FirstPermissionThatFailed {
90 get { return _firstperm; }
91 set { _firstperm = value; }
94 public MethodInfo Method {
95 get { return _method; }
96 set { _method = value; }
100 public IPermission PermissionThatFailed {
101 get { return _permfailed; }
102 set { _permfailed = value; }
105 public object PermitOnlySetInstance {
106 get { return _permitset; }
107 set { _permitset = value; }
112 set { _url = value; }
115 public SecurityZone Zone {
116 get { return _zone; }
117 set { _zone = value; }
121 public string PermissionState {
122 get { return permissionState; }
124 set { permissionState = value; }
128 public Type PermissionType {
129 get { return permissionType; }
131 set { permissionType = value; }
136 public string GrantedSet {
137 get { return _granted; }
139 set { _granted = value; }
143 public string RefusedSet {
144 get { return _refused; }
146 set { _refused = value; }
152 public SecurityException ()
153 : base (Locale.GetText ("A security error has been detected."))
155 base.HResult = unchecked ((int)0x8013150A);
158 public SecurityException (string message)
161 base.HResult = unchecked ((int)0x8013150A);
164 protected SecurityException (SerializationInfo info, StreamingContext context)
165 : base (info, context)
167 base.HResult = unchecked ((int)0x8013150A);
168 permissionState = info.GetString ("PermissionState");
171 public SecurityException (string message, Exception inner)
172 : base (message, inner)
174 base.HResult = unchecked ((int)0x8013150A);
177 public SecurityException (string message, Type type)
180 base.HResult = unchecked ((int)0x8013150A);
181 permissionType = type;
184 public SecurityException (string message, Type type, string state)
187 base.HResult = unchecked ((int)0x8013150A);
188 permissionType = type;
189 permissionState = state;
192 internal SecurityException (string message, PermissionSet granted, PermissionSet refused)
195 base.HResult = unchecked ((int)0x8013150A);
196 _granted = granted.ToString ();
197 _refused = refused.ToString ();
201 public SecurityException (string message, object deny, object permitOnly, MethodInfo method,
202 object demanded, IPermission permThatFailed)
206 _permitset = permitOnly;
208 _demanded = demanded;
209 _permfailed = permThatFailed;
212 public SecurityException (string message, AssemblyName assemblyName, PermissionSet grant,
213 PermissionSet refused, MethodInfo method, SecurityAction action, object demanded,
214 IPermission permThatFailed, Evidence evidence)
217 _assembly = assemblyName;
218 _granted = grant.ToString ();
219 _refused = refused.ToString ();
222 _demanded = demanded;
223 _permfailed = permThatFailed;
224 // FIXME ? evidence ?
229 public override void GetObjectData (SerializationInfo info, StreamingContext context)
231 base.GetObjectData (info, context);
232 info.AddValue ("PermissionState", permissionState);
235 public override string ToString ()
237 StringBuilder sb = new StringBuilder (base.ToString ());
238 if (permissionState != null) {
239 sb.Append (Environment.NewLine);
240 sb.Append ("State: ");
241 sb.Append (permissionState);
243 if (permissionType != null) {
244 sb.Append (Environment.NewLine);
245 sb.Append ("Type: ");
246 sb.Append (permissionType.ToString ());
249 if (_granted != null) {
250 sb.Append (Environment.NewLine);
251 sb.Append ("Granted: ");
252 sb.Append (_granted.ToString ());
254 if (_refused != null) {
255 sb.Append (Environment.NewLine);
256 sb.Append ("Refused: ");
257 sb.Append (_refused.ToString ());
260 return sb.ToString ();