2009-06-30 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Security / SecurityException.cs
index 514317e11ea89afc694c43c2ad2a76dc1d70943a..e87fad90e5e7399022024afed7a676ba47569765 100644 (file)
@@ -49,16 +49,25 @@ namespace System.Security {
                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
 
@@ -182,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) 
@@ -251,7 +268,7 @@ namespace System.Security {
                        _firstperm = permThatFailed;
                        if (_firstperm != null)
                                permissionType = _firstperm.GetType ();
-                       // FIXME ? evidence ?
+                       _evidence = evidence;
                }
 
                // Methods
@@ -268,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) {
@@ -295,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
                }
        }
 }