2 // System.Security.PermissionSet.cs
\r
5 // Nick Drochak(ndrochak@gol.com)
\r
11 using System.Collections;
\r
12 using System.Security.Permissions;
\r
13 using System.Security;
\r
14 using System.Runtime.Serialization;
\r
16 namespace System.Security
\r
18 ///<summary> Represents a collection that can contain different kinds of permissions and perform security operations.</summary>
\r
19 public class PermissionSet: ISecurityEncodable, ICollection, IEnumerable, IStackWalk, IDeserializationCallback
\r
21 ///<summary> Constructs a new instance of the System.Security.PermissionSet class with the specified value.</summary>
\r
22 ///<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
23 ///<exception cref="System.ArgumentException">state is not a valid System.Security.Permissions.PermissionState value.</exception>
\r
24 public PermissionSet(PermissionState state)
\r
26 if (!Enum.IsDefined(typeof(System.Security.Permissions.PermissionState), state))
\r
28 throw new System.ArgumentException(); // state is not a valid System.Security.Permissions.PermissionState value.
\r
32 ///<summary> Constructs a new instance of the System.Security.PermissionSet class with the values of the specified System.Security.PermissionSet instance. </summary>
\r
33 ///<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
34 ///<exception cref="System.ArgumentException">permSet is not an instance of System.Security.PermissionSet.</exception>
\r
35 public PermissionSet(PermissionSet permSet)
\r
37 // LAMESPEC: This would be handled by the compiler. No way permSet is not a PermissionSet.
\r
40 // throw new System.ArgumentException(); // permSet is not an instance of System.Security.PermissionSet.
\r
44 ///<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
45 ///<param name="perm">The System.Security.IPermission object to add.</param>
\r
46 ///<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
47 ///<exception cref="System.ArgumentException">perm is not a System.Security.IPermission object.</exception>
\r
48 public virtual IPermission AddPermission(IPermission perm)
\r
50 // LAMESPEC: This would be handled by the compiler. No way perm is not an IPermission.
\r
53 // throw new System.ArgumentException(); // perm is not a System.Security.IPermission object.
\r
58 ///<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
59 ///<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
60 public virtual void Assert()
\r
62 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
65 ///<summary>Returns a new System.Security.PermissionSet containing copies of the objects in the current instance.</summary>
\r
66 ///<returns>A new System.Security.PermissionSet that is value equal to the current instance.</returns>
\r
67 public virtual PermissionSet Copy()
\r
72 ///<summary>Copies the permission objects in the current instance to the specified location in the specified System.Array.</summary>
\r
73 ///<param name="array">The destination System.Array.</param>
\r
74 ///<param name="index">A System.Int32 that specifies the zero-based starting position in the array at which to begin copying.</param>
\r
75 ///<exception cref="System.ArgumentException">array has more than one dimension.</exception>
\r
76 ///<exception cref="System.IndexOutOfRangeException">index is outside the range of allowable values for array.</exception>
\r
77 ///<exception cref="System.ArgumentNullException">array is null.</exception>
\r
78 public virtual void CopyTo(Array array, int index)
\r
82 throw new System.ArgumentException("Array has more than one dimension"); // array has more than one dimension.
\r
84 if (index < 0 || index >= array.Length)
\r
86 throw new System.IndexOutOfRangeException(); // index is outside the range of allowable values for array.
\r
90 throw new System.ArgumentNullException(); // array is null.
\r
94 ///<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
95 ///<exception cref="System.Security.SecurityException">A caller does not have the permission specified by the current instance.</exception>
\r
96 public virtual void Demand()
\r
98 throw new System.Security.SecurityException(); // A caller does not have the permission specified by the current instance.
\r
101 ///<summary>Denies access to the resources secured by the objects contained in the current instance through the code that calls this method.</summary>
\r
102 ///<exception cref="System.Security.SecurityException">A previous call to Deny has already restricted the permissions for the current stack frame.</exception>
\r
103 public virtual void Deny()
\r
105 throw new System.Security.SecurityException(); // A previous call to Deny has already restricted the permissions for the current stack frame.
\r
108 ///<summary>Reconstructs the state of a System.Security.PermissionSet object using the specified XML encoding.</summary>
\r
109 ///<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
110 ///<exception cref="System.ArgumentNullException">et is null.</exception>
\r
111 ///<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
112 public virtual void FromXml(SecurityElement et)
\r
116 throw new System.ArgumentNullException("et"); // et is null.
\r
120 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
124 ///<summary> Returns an enumerator used to iterate over the permissions in the current instance.</summary>
\r
125 ///<returns>A System.Collections.IEnumerator object for the permissions of the set.</returns>
\r
126 public virtual IEnumerator GetEnumerator()
\r
131 ///<summary> Determines whether the current instance is a subset of the specified object.</summary>
\r
132 ///<param name="target">A System.Security.PermissionSet instance that is to be tested for the subset relationship. </param>
\r
133 ///<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
134 public virtual bool IsSubsetOf(PermissionSet target)
\r
139 ///<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
140 ///<exception cref="System.Security.SecurityException">A previous call to PermitOnly has already set the permissions for the current stack frame.</exception>
\r
141 public virtual void PermitOnly()
\r
145 throw new System.Security.SecurityException(); // A previous call to PermitOnly has already set the permissions for the current stack frame.
\r
149 ///<summary> Returns a System.String representation of the state of the current instance.</summary>
\r
150 ///<returns>A System.Stringcontaining the XML representation of the state of the current instance.</returns>
\r
151 public override string ToString()
\r
156 ///<summary>Returns the XML encoding of the current instance.</summary>
\r
157 ///<returns>A System.Security.SecurityElement containing an XML encoding of the state of the current instance.</returns>
\r
158 public virtual SecurityElement ToXml()
\r
163 ///<summary> Returns a System.Security.PermissionSet object that is the union of the current instance and the specified object.</summary>
\r
164 ///<param name="other">A System.Security.PermissionSet instance to be combined with the current instance.</param>
\r
165 ///<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
166 public virtual PermissionSet Union(PermissionSet other)
\r
171 ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.Count.]</summary>
\r
172 int ICollection.Count
\r
180 ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.IsSynchronized.]</summary>
\r
181 bool ICollection.IsSynchronized
\r
189 ///<summary>Implemented to support the System.Collections.ICollection interface. [Note: For more information, see System.Collections.ICollection.SyncRoot.]</summary>
\r
190 object ICollection.SyncRoot
\r
198 void IDeserializationCallback.OnDeserialization(object sender){}
\r