2009-06-30 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Security / SecurityException.cs
index 4f6d74333c8b22fdddd8a215f2463ae4db22e5bb..e87fad90e5e7399022024afed7a676ba47569765 100644 (file)
@@ -41,25 +41,33 @@ namespace System.Security {
 
        [Serializable]
 #if NET_2_0
-       public class SecurityException : SystemException, _Exception {
-#else
-       public class SecurityException : SystemException {
+       [ComVisible (true)]
 #endif
+       public class SecurityException : SystemException {
                // Fields
                string permissionState;
                Type permissionType;
                private string _granted;
                private string _refused;
-               private SecurityAction _action;
                private object _demanded;
+               private IPermission _firstperm;
+//             private IPermission _permfailed;
+               private MethodInfo _method;
+               private Evidence _evidence;
+
+#if !NET_2_0
+       #pragma warning disable 169
+#endif
+               private SecurityAction _action;
                private object _denyset;
                private object _permitset;
                private AssemblyName _assembly;
-               private IPermission _firstperm;
-               private IPermission _permfailed;
-               private MethodInfo _method;
                private string _url;
                private SecurityZone _zone;
+               
+#if !NET_2_0
+       #pragma warning restore 169
+#endif 
 
                // Properties
 
@@ -91,13 +99,6 @@ namespace System.Security {
                        set { _method = value; }
                }
 
-               [Obsolete]
-               [ComVisible (false)]
-               public IPermission PermissionThatFailed {
-                       get { return _permfailed; }
-                       set { _permfailed = value; }
-               }
-
                [ComVisible (false)]
                public object PermitOnlySetInstance {
                        [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
@@ -190,7 +191,15 @@ namespace System.Security {
                        : base (info, context)
                {
                        base.HResult = unchecked ((int)0x8013150A);
-                       permissionState = info.GetString ("PermissionState");
+                       // depending on the security policy the info about PermissionState may
+                       // not be available (but the serializable must work)
+                       SerializationInfoEnumerator e = info.GetEnumerator ();
+                       while (e.MoveNext ()) {
+                               if (e.Name == "PermissionState") {
+                                       permissionState = (string) e.Value;
+                                       break;
+                               }
+                       }
                }
                
                public SecurityException (string message, Exception inner) 
@@ -259,7 +268,7 @@ namespace System.Security {
                        _firstperm = permThatFailed;
                        if (_firstperm != null)
                                permissionType = _firstperm.GetType ();
-                       // FIXME ? evidence ?
+                       _evidence = evidence;
                }
 
                // Methods
@@ -276,6 +285,9 @@ namespace System.Security {
 
                public override string ToString ()
                {
+#if NET_2_1
+                       return base.ToString ();
+#else
                        StringBuilder sb = new StringBuilder (base.ToString ());
                        try {
                                if (permissionType != null) {
@@ -303,11 +315,20 @@ namespace System.Security {
                                if (_firstperm != null) {
                                        sb.AppendFormat ("{0}Failed Permission: {1}", Environment.NewLine, FirstPermissionThatFailed);
                                }
+                               if (_evidence != null) {
+                                       sb.AppendFormat ("{0}Evidences:", Environment.NewLine);
+                                       foreach (object o in _evidence) {
+                                               // Hash evidence is way much too verbose to be useful to anyone
+                                               if (!(o is Hash))
+                                                       sb.AppendFormat ("{0}\t{1}", Environment.NewLine, o);
+                                       }
+                               }
                        }
                        catch (SecurityException) {
                                // some informations can't be displayed
                        }
                        return sb.ToString ();
+#endif
                }
        }
 }