2009-06-30 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Security / PermissionSet.cs
index 0fa4ec50da4f206b2d1739de244df7c015a62e59..1ac01aefc570a1b0c17db5df6ffc48336567945d 100644 (file)
@@ -49,6 +49,7 @@ namespace System.Security {
 #if NET_2_0
        [ComVisible (true)]
 #endif
+       [MonoTODO ("CAS support is experimental (and unsupported).")]
        public class PermissionSet: ISecurityEncodable, ICollection, IEnumerable, IStackWalk, IDeserializationCallback {
 
                private const string tagName = "PermissionSet";
@@ -57,7 +58,6 @@ namespace System.Security {
 
                private PermissionState state;
                private ArrayList list;
-               private int _hashcode;
                private PolicyLevel _policyLevel;
                private bool _declsec;
                private bool _readOnly;
@@ -116,7 +116,11 @@ namespace System.Security {
 
                // methods
 
+#if NET_2_0
+               public IPermission AddPermission (IPermission perm)
+#else
                public virtual IPermission AddPermission (IPermission perm)
+#endif
                {
                        if ((perm == null) || _readOnly)
                                return perm;
@@ -149,9 +153,13 @@ namespace System.Security {
                        return perm;
                }
 
-               [MonoTODO ("Imperative mode isn't supported")]
+               [MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
                [SecurityPermission (SecurityAction.Demand, Assertion = true)]
+#if NET_2_0
+               public void Assert ()
+#else
                public virtual void Assert ()
+#endif
                {
                        int count = this.Count;
 
@@ -200,7 +208,11 @@ namespace System.Security {
                        }
                }
 
+#if NET_2_0
+               public void Demand ()
+#else
                public virtual void Demand ()
+#endif
                {
                        // Note: SecurityEnabled only applies to CAS permissions
                        // so we're not checking for it (yet)
@@ -215,7 +227,7 @@ namespace System.Security {
                        bool call_cas_only = this.IsUnrestricted ();
                        // non CAS permissions (e.g. PrincipalPermission) do not requires a stack walk
                        for (int i = 0; i < n; i++) {
-                               CodeAccessPermission p = (CodeAccessPermission) list [i];
+                               IPermission p = (IPermission) list [i];
                                Type t = p.GetType ();
                                if (t.IsSubclassOf (typeof (CodeAccessPermission))) {
                                        _ignored [i] = false;
@@ -276,8 +288,12 @@ namespace System.Security {
                        }
                }
 
-               [MonoTODO ("Imperative mode isn't supported")]
+               [MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
+#if NET_2_0
+               public void Deny ()
+#else
                public virtual void Deny ()
+#endif
                {
                        if (!SecurityManager.SecurityEnabled)
                                return;
@@ -329,14 +345,18 @@ namespace System.Security {
                        }
                }
 
+#if NET_2_0
+               public IEnumerator GetEnumerator ()
+#else
                public virtual IEnumerator GetEnumerator ()
+#endif
                {
                        return list.GetEnumerator ();
                }
 
-               public virtual bool IsSubsetOf (PermissionSet target)
-               {
 #if NET_2_0
+               public bool IsSubsetOf (PermissionSet target)
+               {
                        // if target is empty we must be empty too
                        if ((target == null) || (target.IsEmpty ()))
                                return this.IsEmpty ();
@@ -346,6 +366,9 @@ namespace System.Security {
                                return true;
                        if (this.IsUnrestricted ())
                                return false;
+#else
+               public virtual bool IsSubsetOf (PermissionSet target)
+               {
 #endif
                        if (this.IsUnrestricted () && ((target == null) || !target.IsUnrestricted ()))
                                return false;
@@ -375,8 +398,12 @@ namespace System.Security {
                        return true;
                }
 
-               [MonoTODO ("Imperative mode isn't supported")]
+               [MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
+#if NET_2_0
+               public void PermitOnly ()
+#else
                public virtual void PermitOnly ()
+#endif
                {
                        if (!SecurityManager.SecurityEnabled)
                                return;
@@ -400,7 +427,7 @@ namespace System.Security {
                        return false;
                }
 
-               [MonoTODO ("little documentation in Fx 2.0 beta 1")]
+               // FIXME little documentation in Fx 2.0 beta 1
                public static byte[] ConvertPermissionSet (string inFormat, byte[] inData, string outFormat) 
                {
                        if (inFormat == null)
@@ -472,7 +499,11 @@ namespace System.Security {
                        throw new SerializationException (String.Format (Locale.GetText ("Unknown output format {0}."), outFormat));
                }
 
-               public virtual IPermission GetPermission (Type permClass) 
+#if NET_2_0
+               public IPermission GetPermission (Type permClass)
+#else
+               public virtual IPermission GetPermission (Type permClass)
+#endif
                {
                        if ((permClass == null) || (list.Count == 0))
                                return null;
@@ -485,7 +516,11 @@ namespace System.Security {
                        return null;
                }
 
-               public virtual PermissionSet Intersect (PermissionSet other) 
+#if NET_2_0
+               public PermissionSet Intersect (PermissionSet other)
+#else
+               public virtual PermissionSet Intersect (PermissionSet other)
+#endif
                {
                        // no intersection possible
                        if ((other == null) || (other.IsEmpty ()) || (this.IsEmpty ()))
@@ -545,7 +580,11 @@ namespace System.Security {
                        }
                }
 
-               public virtual bool IsEmpty () 
+#if NET_2_0
+               public bool IsEmpty ()
+#else
+               public virtual bool IsEmpty ()
+#endif
                {
                        // note: Unrestricted isn't empty
                        if (state == PermissionState.Unrestricted)
@@ -561,12 +600,20 @@ namespace System.Security {
                        return true;
                }
 
-               public virtual bool IsUnrestricted () 
+#if NET_2_0
+               public bool IsUnrestricted ()
+#else
+               public virtual bool IsUnrestricted ()
+#endif
                {
                        return (state == PermissionState.Unrestricted);
                }
 
-               public virtual IPermission RemovePermission (Type permClass) 
+#if NET_2_0
+               public IPermission RemovePermission (Type permClass)
+#else
+               public virtual IPermission RemovePermission (Type permClass)
+#endif
                {
                        if ((permClass == null) || _readOnly)
                                return null;
@@ -580,7 +627,11 @@ namespace System.Security {
                        return null;
                }
 
-               public virtual IPermission SetPermission (IPermission perm) 
+#if NET_2_0
+               public IPermission SetPermission (IPermission perm)
+#else
+               public virtual IPermission SetPermission (IPermission perm)
+#endif
                {
                        if ((perm == null) || _readOnly)
                                return perm;
@@ -620,7 +671,11 @@ namespace System.Security {
                        return se;
                }
 
+#if NET_2_0
+               public PermissionSet Union (PermissionSet other)
+#else
                public virtual PermissionSet Union (PermissionSet other)
+#endif
                {
                        if (other == null)
                                return this.Copy ();
@@ -717,7 +772,7 @@ namespace System.Security {
                        return (list.Count == 0) ? (int) state : base.GetHashCode ();
                }
 
-               [MonoTODO ("(2.0) what's it doing here? There's probably a reason this was added here.")]
+               // FIXME what's it doing here? There's probably a reason this was added here.
                static public void RevertAssert ()
                {
                        CodeAccessPermission.RevertAssert ();
@@ -756,7 +811,7 @@ namespace System.Security {
                                if (frame.Deny != null) {
                                        // but have restrictions (some denied permissions)
                                        CodeAccessPermission.ThrowSecurityException (this, "Deny", frame, SecurityAction.Demand, null);
-                               } else if (frame.PermitOnly != null) {
+                               } else if ((frame.PermitOnly != null) && !frame.PermitOnly.IsUnrestricted ()) {
                                        // but have restrictions (only some permitted permissions)
                                        CodeAccessPermission.ThrowSecurityException (this, "PermitOnly", frame, SecurityAction.Demand, null);
                                }