This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / System.Security / SecurityException.cs
1 //
2 // System.Security.SecurityException.cs
3 //
4 // Authors:
5 //      Nick Drochak(ndrochak@gol.com)
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) Nick Drochak
9 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
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:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
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.
33 //
34
35 //
36 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
37 //
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:
45 // 
46 // The above copyright notice and this permission notice shall be
47 // included in all copies or substantial portions of the Software.
48 // 
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.
56 //
57
58 using System.Runtime.Serialization;
59 using System.Globalization;
60 using System.Text;
61
62 namespace System.Security {
63
64         [Serializable]
65         public class SecurityException : SystemException {
66
67                 // Fields
68                 string permissionState;
69                 Type permissionType;
70                 private string _granted;
71                 private string _refused;
72
73                 // Properties
74                 public string PermissionState
75                 {
76                         get { return permissionState; }
77                 }
78
79                 public Type PermissionType
80                 {
81                         get { return permissionType; }
82                 }
83 #if ! NET_1_0
84                 public string GrantedSet {
85                         get { return _granted; }
86                 }
87
88                 public string RefusedSet {
89                         get { return _refused; }
90                 }
91 #endif
92                 // Constructors
93                 public SecurityException ()
94                         : base (Locale.GetText ("A security error has been detected."))
95                 {
96                         base.HResult = unchecked ((int)0x8013150A);
97                 }
98
99                 public SecurityException (string message) 
100                         : base (message)
101                 {
102                         base.HResult = unchecked ((int)0x8013150A);
103                 }
104                 
105                 protected SecurityException (SerializationInfo info, StreamingContext context) 
106                         : base (info, context)
107                 {
108                         base.HResult = unchecked ((int)0x8013150A);
109                         permissionState = info.GetString ("PermissionState");
110                 }
111                 
112                 public SecurityException (string message, Exception inner) 
113                         : base (message, inner)
114                 {
115                         base.HResult = unchecked ((int)0x8013150A);
116                 }
117                 
118                 public SecurityException (string message, Type type) 
119                         :  base (message) 
120                 {
121                         base.HResult = unchecked ((int)0x8013150A);
122                         permissionType = type;
123                 }
124                 
125                 public SecurityException (string message, Type type, string state) 
126                         : base (message) 
127                 {
128                         base.HResult = unchecked ((int)0x8013150A);
129                         permissionType = type;
130                         permissionState = state;
131                 }
132
133                 internal SecurityException (string message, PermissionSet granted, PermissionSet refused) 
134                         : base (message)
135                 {
136                         base.HResult = unchecked ((int)0x8013150A);
137                         _granted = granted.ToString ();
138                         _refused = refused.ToString ();
139                 }
140
141                 // Methods
142                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
143                 {
144                         base.GetObjectData (info, context);
145                         info.AddValue ("PermissionState", permissionState);
146                 }
147
148                 public override string ToString ()
149                 {
150                         StringBuilder sb = new StringBuilder (base.ToString ());
151                         if (permissionState != null) {
152                                 sb.Append (Environment.NewLine);
153                                 sb.Append ("State: ");
154                                 sb.Append (permissionState);
155                         }
156                         if (permissionType != null) {
157                                 sb.Append (Environment.NewLine);
158                                 sb.Append ("Type: ");
159                                 sb.Append (permissionType.ToString ());
160                         }
161 #if ! NET_1_0
162                         if (_granted != null) {
163                                 sb.Append (Environment.NewLine);
164                                 sb.Append ("Granted: ");
165                                 sb.Append (_granted.ToString ());
166                         }
167                         if (_refused != null) {
168                                 sb.Append (Environment.NewLine);
169                                 sb.Append ("Refused: ");
170                                 sb.Append (_refused.ToString ());
171                         }
172 #endif
173                         return sb.ToString ();
174                 }
175         }
176 }