17 private IDRole[] m_array;
27 m_array =
new IDRole[1];
28 m_array[0] =
new IDRole();
29 m_array[0].m_authenticated =
true;
30 m_array[0].m_id =
null;
31 m_array[0].m_role =
null;
34 m_array =
new IDRole[1];
35 m_array[0] =
new IDRole();
36 m_array[0].m_authenticated =
false;
38 m_array[0].m_role =
"";
50 m_array =
new IDRole[1];
51 m_array[0] =
new IDRole();
52 m_array[0].m_authenticated =
true;
53 m_array[0].m_id = name;
54 m_array[0].m_role = role;
64 m_array =
new IDRole[1];
65 m_array[0] =
new IDRole();
66 m_array[0].m_authenticated = isAuthenticated;
67 m_array[0].m_id = name;
68 m_array[0].m_role = role;
76 private bool IsEmpty()
78 for (
int i = 0; i < m_array.Length; i++)
80 if (m_array[i].m_id ==
null || !m_array[i].m_id.Equals(
"") || m_array[i].m_role ==
null || !m_array[i].m_role.Equals(
"") || m_array[i].m_authenticated)
88 private bool VerifyType(IPermission perm)
90 if (perm ==
null || perm.GetType() != GetType())
102 for (
int i = 0; i < m_array.Length; i++)
104 if (m_array[i].m_id !=
null || m_array[i].m_role !=
null || !m_array[i].m_authenticated)
134 for (
int i = 0; i < m_array.Length; i++)
137 for (
int j = 0; j < principalPermission.m_array.Length; j++)
139 if (principalPermission.m_array[j].m_authenticated == m_array[i].m_authenticated && (principalPermission.m_array[j].m_id ==
null || (m_array[i].m_id !=
null && m_array[i].m_id.Equals(principalPermission.m_array[j].m_id))) && (principalPermission.m_array[j].m_role ==
null || (m_array[i].m_role !=
null && m_array[i].m_role.Equals(principalPermission.m_array[j].m_role))))
168 if (!VerifyType(target))
174 return target.
Copy();
182 for (
int i = 0; i < m_array.Length; i++)
184 for (
int j = 0; j < principalPermission.m_array.Length; j++)
186 if (principalPermission.m_array[j].m_authenticated != m_array[i].m_authenticated)
190 if (principalPermission.m_array[j].m_id ==
null || m_array[i].m_id ==
null || m_array[i].m_id.Equals(principalPermission.m_array[j].m_id))
196 IDRole iDRole =
new IDRole();
197 iDRole.m_id = ((principalPermission.m_array[j].m_id ==
null) ? m_array[i].m_id : principalPermission.m_array[j].m_id);
198 if (principalPermission.m_array[j].m_role ==
null || m_array[i].m_role ==
null || m_array[i].m_role.Equals(principalPermission.m_array[j].m_role))
200 iDRole.m_role = ((principalPermission.m_array[j].m_role ==
null) ? m_array[i].m_role : principalPermission.m_array[j].m_role);
206 iDRole.m_authenticated = principalPermission.m_array[j].m_authenticated;
209 else if (principalPermission.m_array[j].m_role ==
null || m_array[i].m_role ==
null || m_array[i].m_role.Equals(principalPermission.m_array[j].m_role))
215 IDRole iDRole2 =
new IDRole();
217 iDRole2.m_role = ((principalPermission.m_array[j].m_role ==
null) ? m_array[i].m_role : principalPermission.m_array[j].m_role);
218 iDRole2.m_authenticated = principalPermission.m_array[j].m_authenticated;
227 IDRole[] array =
new IDRole[list.Count];
232 array[num++] = (IDRole)enumerator.
Current;
247 if (!VerifyType(other))
256 int num = m_array.Length + principalPermission.m_array.Length;
257 IDRole[] array =
new IDRole[num];
259 for (i = 0; i < m_array.Length; i++)
261 array[i] = m_array[i];
263 for (
int j = 0; j < principalPermission.m_array.Length; j++)
265 array[i + j] = principalPermission.m_array[j];
278 if (obj !=
null && permission ==
null)
286 if (permission !=
null && !permission.
IsSubsetOf(
this))
299 for (
int i = 0; i < m_array.Length; i++)
301 num += m_array[i].GetHashCode();
314 private void ThrowSecurityException()
322 assemblyName = callingAssembly.
GetName();
325 evidence = callingAssembly.
Evidence;
331 PermissionSet.RevertAssert();
332 throw new SecurityException(Environment.GetResourceString(
"Security_PrincipalPermission"), assemblyName,
null,
null,
null,
SecurityAction.Demand,
this,
this, evidence);
337 [SecuritySafeCritical]
343 if (principal ==
null)
345 ThrowSecurityException();
351 int num = m_array.Length;
353 for (
int i = 0; i < num; i++)
355 if (m_array[i].m_authenticated)
360 if (m_array[i].m_role ==
null)
367 flag = ((windowsPrincipal ==
null || !(m_array[i].Sid !=
null)) ? principal.
IsInRole(m_array[i].m_role) : windowsPrincipal.
IsInRole(m_array[i].Sid));
381 ThrowSecurityException();
390 XMLUtil.AddClassAttribute(securityElement, GetType(),
"System.Security.Permissions.PrincipalPermission");
392 int num = m_array.Length;
393 for (
int i = 0; i < num; i++)
397 return securityElement;
407 if (elem.InternalChildren !=
null && elem.InternalChildren.
Count != 0)
409 int count = elem.InternalChildren.
Count;
411 m_array =
new IDRole[count];
415 IDRole iDRole =
new IDRole();
417 m_array[num++] = iDRole;
422 m_array =
new IDRole[0];
433 int IBuiltInPermission.GetTokenIndex()
435 return GetTokenIndex();
438 internal static int GetTokenIndex()
static Assembly GetExecutingAssembly()
Gets the assembly that contains the code that is currently executing.
static IPrincipal CurrentPrincipal
Gets or sets the thread's current principal (for role-based security).
Enables code to check the Windows group membership of a Windows user.
Allows a permission to expose an unrestricted state.
void FromXml(SecurityElement elem)
Reconstructs a permission with a specified state from an XML encoding.
Describes a set of security permissions applied to code. This class cannot be inherited.
PrincipalPermission(string name, string role)
Initializes a new instance of the T:System.Security.Permissions.PrincipalPermission class for the spe...
bool MoveNext()
Advances the enumerator to the next element of the collection.
override bool IsInRole(string role)
Determines whether the current principal belongs to the Windows user group with the specified name.
static Assembly GetCallingAssembly()
Returns the T:System.Reflection.Assembly of the method that invoked the currently executing method.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Defines the basic functionality of a principal object.
IPermission Union(IPermission other)
Creates a permission that is the union of the current permission and the specified permission.
override string ToString()
Creates and returns a string representing the current permission.
virtual AssemblyName GetName()
Gets an T:System.Reflection.AssemblyName for this assembly.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
void Demand()
Determines at run time whether the current principal matches the principal specified by the current p...
The exception that is thrown for invalid casting or explicit conversion.
SecurityElement ToXml()
Creates an XML encoding of the permission and its current state.
IPermission Copy()
Creates and returns an identical copy of the current permission.
override int GetHashCode()
Gets a hash code for the T:System.Security.Permissions.PrincipalPermission object that is suitable fo...
bool IsUnrestricted()
Returns a value indicating whether the current permission is unrestricted.
bool IsSubsetOf(IPermission target)
Determines whether the current permission is a subset of the specified permission.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
SecurityAction
Specifies the security actions that can be performed using declarative security.
PrincipalPermission(PermissionState state)
Initializes a new instance of the T:System.Security.Permissions.PrincipalPermission class with the sp...
Provides information about, and means to manipulate, the current environment and platform....
bool IsAuthenticated
Gets a value that indicates whether the user has been authenticated.
IIdentity Identity
Gets the identity of the current principal.
Represents a collection that can contain many different types of permissions.
Represents the XML object model for encoding security objects. This class cannot be inherited.
IPermission Intersect(IPermission target)
Creates and returns a permission that is the intersection of the current permission and the specified...
Defines the methods that convert permission object state to and from XML element representation.
object Current
Gets the element in the collection at the current position of the enumerator.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Defines the underlying structure of all code access permissions.
Defines methods implemented by permission types.
virtual Evidence Evidence
Gets the evidence for this assembly.
Describes an assembly's unique identity in full.
bool IsSubsetOf(IPermission target)
Determines whether the current permission is a subset of the specified permission.
The exception that is thrown when one of the arguments provided to a method is not valid.
bool IsInRole(string role)
Determines whether the current principal belongs to the specified role.
override bool Equals(object obj)
Determines whether the specified T:System.Security.Permissions.PrincipalPermission object is equal to...
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Defines the set of information that constitutes input to security policy decisions....
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
ArrayList Children
Gets or sets the array of child elements of the XML element.
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
Defines the basic functionality of an identity object.
Allows checks against the active principal (see T:System.Security.Principal.IPrincipal) using the lan...
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
string Name
Gets the name of the current user.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
IPermission Copy()
Creates and returns an identical copy of the current permission.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Supports a simple iteration over a non-generic collection.
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...
PrincipalPermission(string name, string role, bool isAuthenticated)
Initializes a new instance of the T:System.Security.Permissions.PrincipalPermission class for the spe...
Creates and controls a thread, sets its priority, and gets its status.