Try our conversational search powered by Generative AI!

Class VirtualRolePrincipal

A wrapper class that adds Virtual Role functionality to a principal object.

Inheritance
System.Object
VirtualRolePrincipal
Implements
System.Security.Principal.IPrincipal
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Security
Assembly: EPiServer.Framework.dll
Version: 8.11.0
Syntax
public class VirtualRolePrincipal : IPrincipal

Constructors

VirtualRolePrincipal(IPrincipal, VirtualRoleAuthorizationSession)

This constructor supports the EPiServer infrastructure and is not intended to be used directly from your code.

Declaration
public VirtualRolePrincipal(IPrincipal principal, VirtualRoleAuthorizationSession authorization)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal to be wrapped

VirtualRoleAuthorizationSession authorization

The virtual role authorization

VirtualRolePrincipal(IPrincipal, Object, VirtualRoleRepository<VirtualRoleProviderBase>, IDictionary<String, Boolean>)

This constructor supports the EPiServer infrastructure and is not intended to be used directly from your code.

Declaration
[Obsolete("Virtual role principal use the VirtualRoleAuthorizationSession class to check for role membership")]
public VirtualRolePrincipal(IPrincipal principal, object context, VirtualRoleRepository<VirtualRoleProviderBase> repository, IDictionary<string, bool> cache)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal to be wrapped

System.Object context

The context

VirtualRoleRepository<VirtualRoleProviderBase> repository

The virtual role repository

System.Collections.Generic.IDictionary<System.String, System.Boolean> cache

Used to cache role lookups

Properties

Context

Declaration
[Obsolete("Context can be passed via IsInRole instead of multi-layering wrapping")]
public object Context { get; }
Property Value
Type Description
System.Object

FailSafeIsInRole

Gets or sets a value indicating whether IsInRole on VirtualRolePrincipal may throw an exception.

Declaration
public static bool FailSafeIsInRole { get; set; }
Property Value
Type Description
System.Boolean

true if IsInRole is fail safe (cannot throw exception); otherwise, false.

Remarks

This setting can be useful to emulate the behavior of IsInRole as it worked in .NET Framework 1.0 / 1.1 In these versions any exceptions thrown by code executing beneath IsInRole were caught and ignored. The IsInRole for a WindowsPrincipal in .NET 2.0 may throw an exception if a domain controller is unavailable - this may be undesired behavior since it could prevent the logon process, thus preventing any user from logging on. By setting this property to True you will cause any exceptions thrown by IsInRole to be caught and ignored. The IsInRole call will be interpreted as returning False on throw.

Identity

Gets the identity of the current principal.

Declaration
public IIdentity Identity { get; }
Property Value
Type Description
System.Security.Principal.IIdentity

WrappedPrincipal

Declaration
public IPrincipal WrappedPrincipal { get; }
Property Value
Type Description
System.Security.Principal.IPrincipal

Methods

CreateWrapper(IPrincipal)

Creates the wrapper.

Declaration
public static IPrincipal CreateWrapper(IPrincipal principal)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal.

Returns
Type Description
System.Security.Principal.IPrincipal

An IPrincipal that supports virtual roles.

Remarks

This method will check that the principal object passed as input parameter does not already support virtual roles. I e calling CreateWrapper multiple times will not add additional wrappers to the principal object.

CreateWrapper(IPrincipal, Object)

Creates the wrapper.

Declaration
[Obsolete("Use CreateWrapper to create virtual role without context")]
public static IPrincipal CreateWrapper(IPrincipal principal, object context)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal.

System.Object context

External context for virtual role determination.

Returns
Type Description
System.Security.Principal.IPrincipal

An IPrincipal that supports virtual roles.

Remarks

This method will check that the principal object passed as input parameter does not already support virtual roles. I e calling CreateWrapper multiple times will not add additional wrappers to the principal object.

IsInRole(String)

Determines whether the current principal belongs to the specified role.

Declaration
public bool IsInRole(string role)
Parameters
Type Name Description
System.String role

The name of the role for which to check membership.

Returns
Type Description
System.Boolean

true if the current principal is a member of the specified role; otherwise, false.

IsInRole(String, SecurityEntityType)

Determines whether the current principal belongs to the specified role.

Declaration
public bool IsInRole(string role, SecurityEntityType type)
Parameters
Type Name Description
System.String role

The name of the role for which to check membership.

SecurityEntityType type

Only check virtual roles of this security type

Returns
Type Description
System.Boolean

true if the current principal is a member of the specified role; otherwise, false.

IsInRole(String, SecurityEntityType, Object)

Determines whether the current principal belongs to the specified role.

Declaration
public bool IsInRole(string role, SecurityEntityType type, object context)
Parameters
Type Name Description
System.String role

The name of the role for which to check membership.

SecurityEntityType type

Only check virtual roles of this security type

System.Object context

The context where the virtual role is queried (ie access control lists)

Returns
Type Description
System.Boolean

true if the current principal is a member of the specified role; otherwise, false.

IsInVirtualRole(String, SecurityEntityType)

Determines whether the current principal belongs to the specified virtual role.

Declaration
public bool IsInVirtualRole(string role, SecurityEntityType type)
Parameters
Type Name Description
System.String role

The name of the role for which to check membership.

SecurityEntityType type

The security type of the role you want to check

Returns
Type Description
System.Boolean

true if the current principal is a member of the specified role; otherwise, false.

IsInVirtualRole(String, SecurityEntityType, Object)

Determines whether the current principal belongs to the specified virtual role.

Declaration
public bool IsInVirtualRole(string role, SecurityEntityType type, object context)
Parameters
Type Name Description
System.String role

The name of the role for which to check membership.

SecurityEntityType type

The security type of the role you want to check

System.Object context

The context where the virtual role is queried (ie access control lists)

Returns
Type Description
System.Boolean

true if the current principal is a member of the specified role; otherwise, false.

Unwrap(IPrincipal)

Unwraps a wrapped principal

Declaration
public static IPrincipal Unwrap(IPrincipal principal)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal.

Returns
Type Description
System.Security.Principal.IPrincipal

Implements

System.Security.Principal.IPrincipal