2 // System.Security.SecurityException.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot (spouliot@motus.com)
9 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
38 // Permission is hereby granted, free of charge, to any person obtaining
39 // a copy of this software and associated documentation files (the
40 // "Software"), to deal in the Software without restriction, including
41 // without limitation the rights to use, copy, modify, merge, publish,
42 // distribute, sublicense, and/or sell copies of the Software, and to
43 // permit persons to whom the Software is furnished to do so, subject to
44 // the following conditions:
46 // The above copyright notice and this permission notice shall be
47 // included in all copies or substantial portions of the Software.
49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
53 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
54 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
55 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
58 using System.Runtime.Serialization;
59 using System.Globalization;
62 namespace System.Security {
65 public class SecurityException : SystemException {
68 string permissionState;
70 private string _granted;
71 private string _refused;
74 public string PermissionState
76 get { return permissionState; }
79 public Type PermissionType
81 get { return permissionType; }
84 public string GrantedSet {
85 get { return _granted; }
88 public string RefusedSet {
89 get { return _refused; }
93 public SecurityException ()
94 : base (Locale.GetText ("A security error has been detected."))
96 base.HResult = unchecked ((int)0x8013150A);
99 public SecurityException (string message)
102 base.HResult = unchecked ((int)0x8013150A);
105 protected SecurityException (SerializationInfo info, StreamingContext context)
106 : base (info, context)
108 base.HResult = unchecked ((int)0x8013150A);
109 permissionState = info.GetString ("PermissionState");
112 public SecurityException (string message, Exception inner)
113 : base (message, inner)
115 base.HResult = unchecked ((int)0x8013150A);
118 public SecurityException (string message, Type type)
121 base.HResult = unchecked ((int)0x8013150A);
122 permissionType = type;
125 public SecurityException (string message, Type type, string state)
128 base.HResult = unchecked ((int)0x8013150A);
129 permissionType = type;
130 permissionState = state;
133 internal SecurityException (string message, PermissionSet granted, PermissionSet refused)
136 base.HResult = unchecked ((int)0x8013150A);
137 _granted = granted.ToString ();
138 _refused = refused.ToString ();
142 public override void GetObjectData (SerializationInfo info, StreamingContext context)
144 base.GetObjectData (info, context);
145 info.AddValue ("PermissionState", permissionState);
148 public override string ToString ()
150 StringBuilder sb = new StringBuilder (base.ToString ());
151 if (permissionState != null) {
152 sb.Append (Environment.NewLine);
153 sb.Append ("State: ");
154 sb.Append (permissionState);
156 if (permissionType != null) {
157 sb.Append (Environment.NewLine);
158 sb.Append ("Type: ");
159 sb.Append (permissionType.ToString ());
162 if (_granted != null) {
163 sb.Append (Environment.NewLine);
164 sb.Append ("Granted: ");
165 sb.Append (_granted.ToString ());
167 if (_refused != null) {
168 sb.Append (Environment.NewLine);
169 sb.Append ("Refused: ");
170 sb.Append (_refused.ToString ());
173 return sb.ToString ();