[Serializable] |
To match the active IPrincipal and associated IIdentity, both the specified identity and role must match. If null identity string is used, it is interpreted as a request to match any identity. Use of null role string will match any role. By implication, passing null parameter for name or role to PrincipalPermission will match the identity and roles in any IPrincipal. It is also possible to construct a PrincipalPermission that only determines whether the IIdentity represents an authenticated or unauthenticated entity. In this case, name and role are ignored.
Unlike most other permissions, PrincipalPermission does not extend CodeAccessPermission. It does, however, implement the IPermission interface. This is because PrincipalPermission is not a code access permission; that is, it is not granted based on the identity of the executing assembly. Instead, it allows code to perform actions ( PrincipalPermission.Demand, PrincipalPermission.Union, PrincipalPermission.Intersect, and so on) against the current user identity in a manner consistent with the way those actions are performed for code access and code identity permissions.
String id1 = "Bob"; String role1 = "Manager"; PrincipalPermission PrincipalPerm1 = new PrincipalPermission(id1, role1); String id2 = "Louise"; String role2 = "Supervisor"; PrincipalPermission PrincipalPerm2 = new PrincipalPermission(id2, role2); (PrincipalPerm1.Union(PrincipalPerm2)).Demand();
ctor #1 | Overloaded:.ctor(PermissionState state) Initializes a new instance of the PrincipalPermission class with the specified PermissionState. |
ctor #2 | Overloaded:.ctor(string name, string role) Initializes a new instance of the PrincipalPermission class for the specified name and role. |
ctor #3 | Overloaded:.ctor(string name, string role, bool isAuthenticated) Initializes a new instance of the PrincipalPermission class for the specified name, role, and authentication status. |
Copy | Creates and returns an identical copy of the current permission. |
Demand | Determines at run time whether the current principal matches that specified by the current permission. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
FromXml | Reconstructs a permission with a specified state from an XML encoding. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
Intersect | Creates and returns a permission that is the intersection of the current permission and the specified permission. |
IsSubsetOf | Determines whether the current permission is a subset of the specified permission. |
IsUnrestricted | Returns a value indicating whether the current permission is unrestricted. |
ToString | Overridden: Creates and returns a string representing the current permission. |
ToXml | Creates an XML encoding of the permission and its current state. |
Union | Creates a permission that is the union of the current permission and the specified permission. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public PrincipalPermission( |
state
Exception Type | Condition |
---|---|
ArgumentException | The state parameter is not a valid PermissionState. |
name
role
name
role
isAuthenticated
public IPermission Copy(); |
public void Demand(); |
Exception Type | Condition |
---|---|
SecurityException | The current principal does not pass the security check for the principal specified by the current permission. -or- The current IPrincipal is null. |
This method acts against the principal attached to the calling thread.
~PrincipalPermission(); |
public void FromXml( |
elem
Exception Type | Condition |
---|---|
ArgumentNullException | The elem parameter is null. |
ArgumentException | The elem parameter is not a valid permission element. -or- The elem parameter's version number is not valid. |
public virtual int GetHashCode(); |
public Type GetType(); |
public IPermission Intersect( |
target
Exception Type | Condition |
---|---|
ArgumentException | The target parameter is not null and is not an instance of the same class as the current permission. |
PrincipalPermission ppBob = new PrincipalPermission("Bob", "Administrator"); PrincipalPermission ppLouise = new PrincipalPermission("Louise", "Administrator"); PrincipalPermission pp1 = ppBob.Intersect(ppLouise);
is equivalent to
PrincipalPermission pp1 = new PrincipalPermission("", "Administrator");
because no identity can simultaneously represent both Bob and Louise. In effect,
pp1.Demand()
only succeeds if an unauthenticated principal (with name equal to the empty string ("")) is allowed to act in the Administrator role.
public bool IsSubsetOf( |
target
Exception Type | Condition |
---|---|
ArgumentException | The target parameter is an object that is not of the same type as the current permission. |
pp1
represents Bob and Louise,
pp2
represents Bob, Louise, and Greg.//Define users and roles. PrincipalPermission ppBob = new PrincipalPermission("Bob", "Manager"); PrincipalPermission ppLouise = new PrincipalPermission("Louise", "Supervisor"); PrincipalPermission ppGreg = new PrincipalPermission("Greg", "Employee"); //Define groups of users. PrincipalPermission pp1 = (PrincipalPermission)ppBob.Union(ppLouise); PrincipalPermission pp2 = (PrincipalPermission)ppGreg.Union(pp1);
With the preceding declarations,
pp1.IsSubsetOf(pp2)
returns true, and
pp2.IsSubsetOf(pp1)
returns false.
public bool IsUnrestricted(); |
protected object MemberwiseClone(); |
public override string ToString(); |
public SecurityElement ToXml(); |
public IPermission Union( |
other
Exception Type | Condition |
---|---|
ArgumentException | The other parameter is an object that is not of the same type as the current permission. |
PrincipalPermission ppBob = new PrincipalPermission("Bob", "Administrator"); PrincipalPermission ppLouise = new PrincipalPermission("Louise", "Administrator");
(ppBob.Union(ppLouise)).Demand()
will succeed if the current principal represents Bob in the role of Administrator or Louise in the role of Administrator.