//
// System.Security.CodeAccessPermission.cs
//
-// Author:
-// Miguel de Icaza (miguel@ximian.com)
+// Authors:
+// Miguel de Icaza (miguel@ximian.com)
+// Nick Drochak, ndrochak@gol.com
//
// (C) Ximian, Inc. http://www.ximian.com
+// Copyright (C) 2001 Nick Drochak, All Rights Reserved
//
+using System.Text;
+
namespace System.Security {
[Serializable]
- public abstract class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk
- {
- ///<summary>Constructs a new instance of the System.Security.CodeAccessPermission class.</summary>
- protected CodeAccessPermission(){}
-
- ///<summary> Asserts that calling code can access the resource identified by the current instance through the code that calls this method, even if callers have not been granted permission to access the resource. </summary>
- ///<exception cref="System.Security.SecurityException">The calling code does not have System.Security.Permissions.SecurityPermissionFlag.Assertion. </exception>
- public void Assert()
- {
- }
+ public abstract class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk {
- ///<summary> Returns a System.Security.CodeAccessPermission containing the same values as the current instance.</summary>
- ///<returns> A new System.Security.CodeAccessPermission instance that is value equal to the current instance.</returns>
- public abstract IPermission Copy();
+ protected CodeAccessPermission () {}
- ///<summary>Forces a System.Security.SecurityException if all callers do not have the permission specified by the current instance.</summary>
- ///<exception cref="System.Security.SecurityException"> A caller does not have the permission specified by the current instance. A caller has called System.Security.CodeAccessPermission.Deny for the resource protected by the current instance. </exception>
- public void Demand()
- {
- }
+ [MonoTODO()]
+ public void Assert () {}
+
+ public abstract IPermission Copy ();
+
+ [MonoTODO()]
+ public void Demand () {}
- ///<summary> Denies access to the resources specified by the current instance through the code that calls this method.</summary>
- public void Deny(){}
+ [MonoTODO()]
+ public void Deny () {}
- ///<summary> Reconstructs the state of a System.Security.CodeAccessPermission object using the specified XML encoding.</summary>
- ///<param name="elem">A System.Security.SecurityElement instance containing the XML encoding to use to reconstruct the state of a System.Security.CodeAccessPermission object.</param>
- ///<exception cref="System.ArgumentException">elem does not contain the XML encoding for a instance of the same type as the current instance.The version number of elem is not valid.</exception>
- public abstract void FromXml(SecurityElement elem);
+ public abstract void FromXml (SecurityElement elem);
- ///<summary> Returns a System.Security.CodeAccessPermission object that is the intersection of the current instance and the specified object.</summary>
- ///<param name="target">A System.Security.CodeAccessPermission instance to intersect with the current instance.</param>
- ///<returns> A new System.Security.CodeAccessPermission instance that represents the intersection of the current instance andtarget. If the intersection is empty or target is null, returns null. If the current instance is unrestricted, returns a copy of target. Iftarget is unrestricted, returns a copy of the current instance.</returns>
- ///<exception cref="System.ArgumentException">target is not null and is not a System.Security.CodeAccessPermission object.</exception>
- public abstract IPermission Intersect(IPermission target);
+ public abstract IPermission Intersect (IPermission target);
- ///<summary>Determines whether the current instance is a subset of the specified object.</summary>
- ///<param name="target">A System.Security.CodeAccessPermission instance that is to be tested for the subset relationship.</param>
- ///<returns>true if the current instance is a subset of target; otherwise, false. If the current instance is unrestricted, and target is not, returnsfalse. If target is unrestricted, returns true.</returns>
- ///<exception cref="System.ArgumentException">target is not null and is not of type System.Security.CodeAccessPermission.</exception>
- public abstract bool IsSubsetOf(IPermission target);
+ public abstract bool IsSubsetOf (IPermission target);
- ///<summary> Returns the XML representation of the state of the current instance.</summary>
- ///<returns> A System.String containing the XML representation of the state of the current instance.</returns>
public override string ToString()
{
SecurityElement elem = ToXml ();
return elem == null ? null : elem.ToString ();
}
- ///<summary> Returns the XML encoding of the current instance.</summary>
- ///<returns>A System.Security.SecurityElement containing an XML encoding of the state of the current instance.</returns>
- public abstract SecurityElement ToXml();
+ public abstract SecurityElement ToXml ();
- ///<summary> Returns a System.Security.CodeAccessPermission object that is the union of the current instance and the specified object.</summary>
- ///<param name="other">A System.Security.IPermission object of the same type as the current instance to be combined with the current instance.</param>
- ///<returns>If other is null, returns a copy of the current instance using the System.Security.IPermission.Copy method.</returns>
- ///<exception cref="System.ArgumentException">other is not of type System.Security.CodeAccessPermission.</exception>
- ///<exception cref="System.NotSupportedException">other is not null.</exception>
- public virtual IPermission Union(IPermission other)
+ [MonoTODO("Incomplete")]
+ public virtual IPermission Union (IPermission other)
{
- if (!(other is System.Security.CodeAccessPermission))
- {
- throw new System.ArgumentException(); // other is not of type System.Security.CodeAccessPermission.
- }
- if (null != other)
- {
- throw new System.NotSupportedException(); // other is not null.
- }
- return null;
+ if (!(other is System.Security.CodeAccessPermission))
+ throw new System.ArgumentException(); // other is not of type System.Security.CodeAccessPermission.
+ if (null != other)
+ throw new System.NotSupportedException(); // other is not null.
+ return null;
}
- public void PermitOnly(){}
+ [MonoTODO()]
+ public void PermitOnly () {}
+
+ [MonoTODO()]
+ public static void RevertAll () {}
+
+ [MonoTODO()]
+ public static void RevertAssert () {}
+
+ [MonoTODO()]
+ public static void RevertDeny () {}
+
+ [MonoTODO()]
+ public static void RevertPermitOnly () {}
+
+ // snippet moved from FileIOPermission (nickd) to be reused in all derived classes
+ internal SecurityElement Element (object o, int version)
+ {
+ SecurityElement se = new SecurityElement ("IPermission");
+ Type type = this.GetType ();
+ StringBuilder asmName = new StringBuilder (type.Assembly.ToString ());
+ asmName.Replace ('\"', '\'');
+ se.AddAttribute ("class", type.FullName + ", " + asmName);
+ se.AddAttribute ("version", version.ToString ());
+ return se;
+ }
}
}
-//\r
-// System.Security.NamedPermissionSet\r
-//\r
-// Author:\r
-// Dan Lewis (dihlewis@yahoo.co.uk)\r
-//\r
-// (C) 2002\r
-//\r
-// Stubbed.\r
-//\r
-\r
-using System;\r
-using System.Security.Permissions;\r
-\r
-namespace System.Security {\r
- \r
- [MonoTODO]\r
- [Serializable]\r
- public sealed class NamedPermissionSet : PermissionSet {\r
- public NamedPermissionSet (string name, PermissionSet set) : base (set) {\r
- this.name = name;\r
- this.description = "";\r
- }\r
-\r
- public NamedPermissionSet (string name, PermissionState state) : base (state) {\r
- this.name = name;\r
- this.description = "";\r
- }\r
-\r
- public NamedPermissionSet (NamedPermissionSet set) : this (set.name, set) {\r
- }\r
-\r
- public NamedPermissionSet (string name) : this (name, PermissionState.None) {\r
- }\r
-\r
- public string Description {\r
- get { return description; }\r
- set { description = value; }\r
- }\r
-\r
- public string Name {\r
- get { return name; }\r
- set { name = value; }\r
- }\r
-\r
- public override PermissionSet Copy () {\r
- return null;\r
- }\r
-\r
- public NamedPermissionSet Copy (string name) {\r
- return null;\r
- }\r
-\r
- public override void FromXml (SecurityElement e) {\r
- }\r
-\r
- public override SecurityElement ToXml () {\r
- return null;\r
- }\r
-\r
- // private\r
-\r
- private string name;\r
- private string description;\r
- }\r
-}\r
+//
+// System.Security.NamedPermissionSet
+//
+// Authors:
+// Dan Lewis (dihlewis@yahoo.co.uk)
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2002
+// Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Security.Permissions;
+
+namespace System.Security {
+
+ [Serializable]
+ public sealed class NamedPermissionSet : PermissionSet {
+
+ public NamedPermissionSet (string name, PermissionSet set) : base (set)
+ {
+ Name = name;
+ }
+
+ public NamedPermissionSet (string name, PermissionState state) : base (state)
+ {
+ Name = name;
+ }
+
+ public NamedPermissionSet (NamedPermissionSet set) : this (set.name, set) {}
+
+ public NamedPermissionSet (string name) : this (name, PermissionState.None) {}
+
+ public string Description {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public string Name {
+ get { return name; }
+ set {
+ if ((name == null) || (name == String.Empty))
+ throw new ArgumentException ("invalid name");
+ name = value;
+ }
+ }
+
+ public override PermissionSet Copy ()
+ {
+ return new NamedPermissionSet (this);
+ }
+
+ public NamedPermissionSet Copy (string name)
+ {
+ NamedPermissionSet nps = new NamedPermissionSet (this);
+ nps.Name = name;
+ return nps;
+ }
+
+ public override void FromXml (SecurityElement e)
+ {
+ FromXml (e, "System.Security.NamedPermissionSet");
+ Name = (e.Attributes ["Name"] as string);
+ Description = (e.Attributes ["Description"] as string);
+ }
+
+ public override SecurityElement ToXml ()
+ {
+ SecurityElement se = base.ToXml ();
+ if (name != null)
+ se.AddAttribute ("Name", name);
+ if (description != null)
+ se.AddAttribute ("Description", description);
+ return se;
+ }
+
+ // private
+
+ private string name;
+ private string description;
+ }
+}
-//\r
-// System.Security.PermissionSet.cs\r
-//\r
-// Author:\r
-// Nick Drochak(ndrochak@gol.com)\r
-//\r
-// (C) Nick Drochak\r
-//\r
-\r
-using System;\r
-using System.Collections;\r
-using System.Security.Permissions;\r
-using System.Security;\r
-using System.Runtime.Serialization;\r
-\r
-namespace System.Security\r
-{\r
- ///<summary> Represents a collection that can contain different kinds of permissions and perform security operations.</summary>\r
- [Serializable]\r
- public class PermissionSet: ISecurityEncodable, ICollection, IEnumerable, IStackWalk, IDeserializationCallback\r
- {\r
- ///<summary> Constructs a new instance of the System.Security.PermissionSet class with the specified value.</summary>\r
- ///<param name="state">A System.Security.Permissions.PermissionState value. This value is either System.Security.Permissions.PermissionState.None or System.Security.Permissions.PermissionState.Unrestricted, to specify fully restricted or fully unrestricted access. </param>\r
- ///<exception cref="System.ArgumentException">state is not a valid System.Security.Permissions.PermissionState value.</exception>\r
- public PermissionSet(PermissionState state)\r
- {\r
- if (!Enum.IsDefined(typeof(System.Security.Permissions.PermissionState), state))\r
- {\r
- throw new System.ArgumentException(); // state is not a valid System.Security.Permissions.PermissionState value.\r
- }\r
- }\r
-\r
- ///<summary> Constructs a new instance of the System.Security.PermissionSet class with the values of the specified System.Security.PermissionSet instance. </summary>\r
- ///<param name="permSet">The System.Security.PermissionSet instance with which to initialize the values of the new instance, or null to initialize an empty permission set.</param>\r
- ///<exception cref="System.ArgumentException">permSet is not an instance of System.Security.PermissionSet.</exception>\r
- public PermissionSet(PermissionSet permSet)\r
- {\r
- // LAMESPEC: This would be handled by the compiler. No way permSet is not a PermissionSet.\r
- //if (false)\r
- //{\r
- // throw new System.ArgumentException(); // permSet is not an instance of System.Security.PermissionSet.\r
- //}\r
- }\r
-\r
- ///<summary> Adds the specified System.Security.IPermission object to the current instance if that permission does not already exist in the current instance.</summary>\r
- ///<param name="perm">The System.Security.IPermission object to add.</param>\r
- ///<returns>The System.Security.IPermission is added if perm is notnull and a permission of the same type as perm does not already exist in the current instance. If perm is null, returns null. If a permission of the same type asperm already exists in the current instance, the union of the existing permission and perm is added to the current instance and is returned.</returns>\r
- ///<exception cref="System.ArgumentException">perm is not a System.Security.IPermission object.</exception>\r
- public virtual IPermission AddPermission(IPermission perm)\r
- {\r
- // LAMESPEC: This would be handled by the compiler. No way perm is not an IPermission.\r
- //if (false)\r
- //{\r
- // throw new System.ArgumentException(); // perm is not a System.Security.IPermission object.\r
- //}\r
- return null;\r
- }\r
-\r
- ///<summary>Asserts that calling code can access the resources identified by the permissions contained in the current instance through the code that calls this method, even if callers have not been granted permission to access the resource. </summary>\r
- ///<exception cref="System.Security.SecurityException">The asserting code does not have sufficient permission to call this method.-or-This method was called with permissions already asserted for the current stack frame.</exception>\r
- public virtual void Assert()\r
- {\r
- throw new System.Security.SecurityException(); // The asserting code does not have sufficient permission to call this method.-or-This method was called with permissions already asserted for the current stack frame.\r
- }\r
-\r
- ///<summary>Returns a new System.Security.PermissionSet containing copies of the objects in the current instance.</summary>\r
- ///<returns>A new System.Security.PermissionSet that is value equal to the current instance.</returns>\r
- public virtual PermissionSet Copy()\r
- {\r
- return null;\r
- }\r
-\r
- ///<summary>Copies the permission objects in the current instance to the specified location in the specified System.Array.</summary>\r
- ///<param name="array">The destination System.Array.</param>\r
- ///<param name="index">A System.Int32 that specifies the zero-based starting position in the array at which to begin copying.</param>\r
- ///<exception cref="System.ArgumentException">array has more than one dimension.</exception>\r
- ///<exception cref="System.IndexOutOfRangeException">index is outside the range of allowable values for array.</exception>\r
- ///<exception cref="System.ArgumentNullException">array is null.</exception>\r
- public virtual void CopyTo(Array array, int index)\r
- {\r
- if (array.Rank > 1)\r
- {\r
- throw new System.ArgumentException("Array has more than one dimension"); // array has more than one dimension.\r
- }\r
- if (index < 0 || index >= array.Length)\r
- {\r
- throw new System.IndexOutOfRangeException(); // index is outside the range of allowable values for array.\r
- }\r
- if (null == array)\r
- {\r
- throw new System.ArgumentNullException(); // array is null.\r
- }\r
- }\r
-\r
- ///<summary>Forces a System.Security.SecurityException if all callers do not have the permissions specified by the objects contained in the current instance.</summary>\r
- ///<exception cref="System.Security.SecurityException">A caller does not have the permission specified by the current instance.</exception>\r
- public virtual void Demand()\r
- {\r
- throw new System.Security.SecurityException(); // A caller does not have the permission specified by the current instance.\r
- }\r
-\r
- ///<summary>Denies access to the resources secured by the objects contained in the current instance through the code that calls this method.</summary>\r
- ///<exception cref="System.Security.SecurityException">A previous call to Deny has already restricted the permissions for the current stack frame.</exception>\r
- public virtual void Deny()\r
- {\r
- throw new System.Security.SecurityException(); // A previous call to Deny has already restricted the permissions for the current stack frame.\r
- }\r
-\r
- ///<summary>Reconstructs the state of a System.Security.PermissionSet object using the specified XML encoding.</summary>\r
- ///<param name="et">A System.Security.SecurityElement instance containing the XML encoding to use to reconstruct the state of a System.Security.PermissionSet object.</param>\r
- ///<exception cref="System.ArgumentNullException">et is null.</exception>\r
- ///<exception cref="System.ArgumentException">et does not contain an XML encoding for a System.Security.PermissionSet instance.An error occurred while reconstructing et.</exception>\r
- public virtual void FromXml(SecurityElement et)\r
- {\r
- if (null == et)\r
- {\r
- throw new System.ArgumentNullException("et"); // et is null.\r
- }\r
- if (true)\r
- {\r
- throw new System.ArgumentException("et does not contain an XML encoding for a System.Security.PermissionSet instance."); // et does not contain an XML encoding for a System.Security.PermissionSet instance.An error occurred while reconstructing et.\r
- }\r
- }\r
-\r
- ///<summary> Returns an enumerator used to iterate over the permissions in the current instance.</summary>\r
- ///<returns>A System.Collections.IEnumerator object for the permissions of the set.</returns>\r
- public virtual IEnumerator GetEnumerator()\r
- {\r
- return null;\r
- }\r
-\r
- ///<summary> Determines whether the current instance is a subset of the specified object.</summary>\r
- ///<param name="target">A System.Security.PermissionSet instance that is to be tested for the subset relationship. </param>\r
- ///<returns>true if the current instance is a subset of target; otherwise, false. If the current instance is unrestricted, andtarget is not, returns false. If target is unrestricted, returns true.</returns>\r
- public virtual bool IsSubsetOf(PermissionSet target)\r
- {\r
- return false;\r
- }\r
-\r
- ///<summary> Specifies that only the resources described by the current instance can be accessed by calling code, even if the code has been granted permission to access other resources.</summary>\r
- ///<exception cref="System.Security.SecurityException">A previous call to PermitOnly has already set the permissions for the current stack frame.</exception>\r
- public virtual void PermitOnly()\r
- {\r
- if (true)\r
- {\r
- throw new System.Security.SecurityException(); // A previous call to PermitOnly has already set the permissions for the current stack frame.\r
- }\r
- }\r
-\r
- ///<summary> Returns a System.String representation of the state of the current instance.</summary>\r
- ///<returns>A System.Stringcontaining the XML representation of the state of the current instance.</returns>\r
- public override string ToString()\r
- {\r
- return null;\r
- }\r
-\r
- ///<summary>Returns the XML encoding of the current instance.</summary>\r
- ///<returns>A System.Security.SecurityElement containing an XML encoding of the state of the current instance.</returns>\r
- public virtual SecurityElement ToXml()\r
- {\r
- return null;\r
- }\r
-\r
- ///<summary> Returns a System.Security.PermissionSet object that is the union of the current instance and the specified object.</summary>\r
- ///<param name="other">A System.Security.PermissionSet instance to be combined with the current instance.</param>\r
- ///<returns> A new System.Security.PermissionSet instance that represents the union of the current instance and other. If the current instance or other is unrestricted, returns a System.Security.PermissionSet instance that is unrestricted.</returns>\r
- public virtual PermissionSet Union(PermissionSet other)\r
- {\r
- return null;\r
- }\r
-\r
- ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.Count.]</summary>\r
- int ICollection.Count \r
- {\r
- get\r
- {\r
- return 0;\r
- }\r
- }\r
-\r
- ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.IsSynchronized.]</summary>\r
- bool ICollection.IsSynchronized \r
- {\r
- get\r
- {\r
- return false;\r
- }\r
- }\r
-\r
- ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.SyncRoot.]</summary>\r
- object ICollection.SyncRoot \r
- {\r
- get\r
- {\r
- return null;\r
- }\r
- }\r
-\r
- void IDeserializationCallback.OnDeserialization(object sender){}\r
-\r
- }\r
-}\r
+//
+// System.Security.PermissionSet.cs
+//
+// Authors:
+// Nick Drochak(ndrochak@gol.com)
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) Nick Drochak
+// Portions (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Collections;
+using System.Security.Permissions;
+using System.Security;
+using System.Runtime.Serialization;
+
+namespace System.Security {
+
+ [Serializable]
+ public class PermissionSet: ISecurityEncodable, ICollection, IEnumerable, IStackWalk, IDeserializationCallback {
+
+ private PermissionState state;
+ private ArrayList list;
+
+ public PermissionSet (PermissionState state)
+ {
+ if (!Enum.IsDefined(typeof(System.Security.Permissions.PermissionState), state))
+ throw new System.ArgumentException(); // state is not a valid System.Security.Permissions.PermissionState value.
+ this.state = state;
+ list = new ArrayList ();
+ }
+
+ public PermissionSet (PermissionSet permSet) : this (PermissionState.Unrestricted)
+ {
+ // LAMESPEC: This would be handled by the compiler. No way permSet is not a PermissionSet.
+ //if (!(permSet is PermissionSet))
+ // throw new System.ArgumentException(); // permSet is not an instance of System.Security.PermissionSet.
+ if (permSet != null) {
+ foreach (IPermission p in permSet.list)
+ list.Add (p);
+ }
+ }
+
+ public virtual IPermission AddPermission (IPermission perm)
+ {
+ if (perm == null)
+ return null;
+
+ IPermission existing = GetPermission (perm.GetType ());
+ if (existing != null)
+ perm = perm.Union (existing);
+
+ list.Add (perm);
+ return perm;
+ }
+
+ [MonoTODO()]
+ public virtual void Assert ()
+ {
+ }
+
+ [MonoTODO()]
+ public virtual PermissionSet Copy ()
+ {
+ return null;
+ }
+
+ public virtual void CopyTo (Array array, int index)
+ {
+ if (array.Rank > 1)
+ throw new System.ArgumentException("Array has more than one dimension"); // array has more than one dimension.
+ if (index < 0 || index >= array.Length)
+ throw new System.IndexOutOfRangeException(); // index is outside the range of allowable values for array.
+ if (null == array)
+ throw new System.ArgumentNullException(); // array is null.
+ list.CopyTo (array, index);
+ }
+
+ [MonoTODO()]
+ public virtual void Demand ()
+ {
+ }
+
+ [MonoTODO()]
+ public virtual void Deny ()
+ {
+ }
+
+ // to be re-used by NamedPermissionSet (and other derived classes)
+ internal void FromXml (SecurityElement et, string className)
+ {
+ if (et == null)
+ throw new ArgumentNullException ("et");
+ if (et.Tag != "PermissionSet")
+ throw new ArgumentException ("not PermissionSet");
+ if (!(et.Attributes ["class"] as string).StartsWith (className))
+ throw new ArgumentException ("not " + className);
+ if ((et.Attributes ["version"] as string) != "1")
+ throw new ArgumentException ("wrong version");
+
+ if ((et.Attributes ["Unrestricted"] as string) == "true")
+ state = PermissionState.Unrestricted;
+ else
+ state = PermissionState.None;
+ }
+
+ public virtual void FromXml (SecurityElement et)
+ {
+ FromXml (et, "System.Security.PermissionSet");
+ foreach (SecurityElement se in et.Children) {
+ string className = (se.Attributes ["class"] as string);
+ Type classType = Type.GetType (className);
+ IPermission p = (IPermission) Activator.CreateInstance (classType);
+ p.FromXml (se);
+ list.Add (p);
+ }
+ }
+
+ public virtual IEnumerator GetEnumerator ()
+ {
+ return list.GetEnumerator ();
+ }
+
+ [MonoTODO()]
+ public virtual bool IsSubsetOf (PermissionSet target)
+ {
+ return false;
+ }
+
+ [MonoTODO()]
+ public virtual void PermitOnly ()
+ {
+ }
+
+ public bool ContainsNonCodeAccessPermissions ()
+ {
+ foreach (IPermission p in list) {
+ if (! p.GetType ().IsSubclassOf (typeof(CodeAccessPermission)))
+ return true;
+ }
+ return false;
+ }
+
+ // undocumented behavior
+ [MonoTODO()]
+ public static byte[] ConvertPermissionSet (string inFormat, byte[] inData, string outFormat)
+ {
+ return null;
+ }
+
+ public virtual IPermission GetPermission (Type permClass)
+ {
+ foreach (object o in list) {
+ if (o.GetType ().Equals (permClass))
+ return (IPermission) o;
+ }
+ return null;
+ }
+
+ [MonoTODO()]
+ public virtual PermissionSet Intersect (PermissionSet other)
+ {
+ return null;
+ }
+
+ public virtual bool IsEmpty ()
+ {
+ // note: Unrestricted isn't empty
+ return ((state == PermissionState.Unrestricted) ? false : (list.Count == 0));
+ }
+
+ public virtual bool IsUnrestricted ()
+ {
+ return (state == PermissionState.Unrestricted);
+ }
+
+ public virtual IPermission RemovePermission (Type permClass)
+ {
+ foreach (object o in list) {
+ if (o.GetType ().Equals (permClass)) {
+ list.Remove (o);
+ return (IPermission) o;
+ }
+ }
+ return null;
+ }
+
+ public virtual IPermission SetPermission (IPermission perm)
+ {
+ if (perm is IUnrestrictedPermission)
+ state = PermissionState.None;
+ RemovePermission (perm.GetType ());
+ list.Add (perm);
+ return perm;
+ }
+
+ public override string ToString ()
+ {
+ return ToXml ().ToString ();
+ }
+
+ public virtual SecurityElement ToXml ()
+ {
+ SecurityElement se = new SecurityElement ("PermissionSet");
+ se.AddAttribute ("class", GetType ().FullName);
+ se.AddAttribute ("version", "1");
+ if (state == PermissionState.Unrestricted)
+ se.AddAttribute ("Unrestricted", "true");
+ else {
+ foreach (IPermission p in list)
+ se.AddChild (p.ToXml ());
+ }
+ return se;
+ }
+
+ [MonoTODO()]
+ public virtual PermissionSet Union (PermissionSet other)
+ {
+ return null;
+ }
+
+ public int Count {
+ get { return list.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return list.IsSynchronized; }
+ }
+
+ public virtual bool IsReadOnly {
+ get { return false; } // always false
+ }
+
+ public object SyncRoot {
+ get { return list.SyncRoot; }
+ }
+
+ [MonoTODO()]
+ void IDeserializationCallback.OnDeserialization (object sender)
+ {
+ }
+ }
+}
-//\r
-// System.Security.SecurityManager.cs\r
-//\r
-// Author:\r
-// Nick Drochak(ndrochak@gol.com)\r
-//\r
-// (C) Nick Drochak\r
-//\r
-\r
-using System.Security.Policy;\r
-using System.Collections;\r
-\r
-namespace System.Security {\r
-\r
- public sealed class SecurityManager {\r
- private static bool checkExecutionRights;\r
- private static bool securityEnabled;\r
+//
+// System.Security.SecurityManager.cs
+//
+// Author:
+// Nick Drochak(ndrochak@gol.com)
+//
+// (C) Nick Drochak
+//
+
+using System.Security.Policy;
+using System.Collections;
+
+namespace System.Security {
+
+ public sealed class SecurityManager {
+
+ private static bool checkExecutionRights;
+ private static bool securityEnabled;
private SecurityManager () {}
-\r
- public static bool CheckExecutionRights {\r
- get{\r
- return checkExecutionRights;\r
- }\r
- set{\r
- checkExecutionRights = value;\r
- }\r
- }\r
-\r
- public static bool SecurityEnabled {\r
- get{\r
- return securityEnabled;\r
- }\r
- set{\r
- securityEnabled = value;\r
- }\r
- }\r
-\r
- public static bool IsGranted(IPermission perm){\r
- return false;\r
- }\r
-\r
- public static PolicyLevel LoadPolicyLevelFromFile(\r
- string path, \r
- PolicyLevelType type)\r
- {\r
- return null;\r
- }\r
-\r
- public static PolicyLevel LoadPolicyLevelFromString(\r
- string str, \r
- PolicyLevelType type)\r
- {\r
- if (null == str){ \r
- throw new ArgumentNullException("str");\r
- }\r
- return null;\r
- }\r
-\r
- public static IEnumerator PolicyHierarchy(){\r
- return null;\r
- }\r
-\r
- public static PermissionSet ResolvePolicy(Evidence evidence){\r
- return null;\r
- }\r
-\r
- public static PermissionSet ResolvePolicy(\r
- Evidence evidence,\r
- PermissionSet reqdPset,\r
- PermissionSet optPset,\r
- PermissionSet denyPset,\r
- out PermissionSet denied)\r
- {\r
- denied = null;\r
- return null;\r
- }\r
-\r
- public static IEnumerator ResolvePolicyGroups(Evidence evidence){\r
- return null;\r
- }\r
-\r
- public static void SavePolicy(){}\r
-\r
- public static void SavePolicyLevel(PolicyLevel level){}\r
-\r
- }\r
+
+ public static bool CheckExecutionRights {
+ get { return checkExecutionRights; }
+ set { checkExecutionRights = value; }
+ }
+
+ public static bool SecurityEnabled {
+ get { return securityEnabled; }
+ set { securityEnabled = value; }
+ }
+
+ [MonoTODO("Incomplete")]
+ public static bool IsGranted (IPermission perm)
+ {
+ if (perm == null)
+ return false;
+ if (!securityEnabled)
+ return true;
+ return false;
+ }
+
+ [MonoTODO()]
+ public static PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type)
+ {
+ return null;
+ }
+
+ [MonoTODO()]
+ public static PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type)
+ {
+ if (null == str)
+ throw new ArgumentNullException("str");
+ return null;
+ }
+
+ [MonoTODO()]
+ public static IEnumerator PolicyHierarchy ()
+ {
+ return null;
+ }
+
+ [MonoTODO()]
+ public static PermissionSet ResolvePolicy (Evidence evidence)
+ {
+ return null;
+ }
+
+ [MonoTODO()]
+ public static PermissionSet ResolvePolicy (Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
+ {
+ denied = null;
+ return null;
+ }
+
+ [MonoTODO()]
+ public static IEnumerator ResolvePolicyGroups (Evidence evidence)
+ {
+ return null;
+ }
+
+ [MonoTODO()]
+ public static void SavePolicy () {}
+
+ [MonoTODO()]
+ public static void SavePolicyLevel (PolicyLevel level) {}
+ }
}