November Happy Hour will be moved to Thursday December 5th.

Class PrincipalInfo

A class that encapsulates some of the details dealing with the IPrincipal interface and corresponding issues with permissions and role/membership management.

Inheritance
System.Object
PrincipalInfo
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.Cms.AspNet.dll
Version: 11.20.7
Syntax
public class PrincipalInfo

Constructors

PrincipalInfo(IPrincipal)

Initializes a new instance of the PrincipalInfo class.

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

The principal object that you want to work with.

Properties

AnonymousPrincipal

Gets a principal object representing the an anonoymous principal.

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

The anonymous principal.

Current

Gets a PrincipalInfo object initialized with the current principal.

Declaration
public static PrincipalInfo Current { get; }
Property Value
Type Description
PrincipalInfo

The PrincipalInfo object.

CurrentPrincipal

Gets or sets the current principal.

Declaration
public static IPrincipal CurrentPrincipal { get; set; }
Property Value
Type Description
System.Security.Principal.IPrincipal

The current principal.

Remarks

This method will use the user from the http context an HttpContext exists, otherwise it will fall back to the the Thread.CurrentPrincipal setting.

When you get the current principal you are assured to always get a valid IPrincipal.

HasAdminAccess

Checks for user access to the /admin pages.

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

HasEditAccess

Checks for user access to the /edit pages.

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

HasEditorAccess

Checks for user access to the /editor pages.

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

Name

Gets the name of the principal.

Declaration
public string Name { get; }
Property Value
Type Description
System.String

The name.

Remarks

This is a convenience method to directly access the Name property of the contained Indentity.

Principal

Gets the principal used by this instance.

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

The principal.

RoleList

Gets the list of roles that the principal belongs to.

Declaration
public ICollection<string> RoleList { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<System.String>

The role list.

Remarks

Uses System.Security.Claims.ClaimsPrincipal to get a list of all role claims

Methods

CreatePrincipal(String)

Creates a principal object for a user.

Declaration
[Obsolete("Use IUserImpersonation")]
public static IPrincipal CreatePrincipal(string username)
Parameters
Type Name Description
System.String username

The name of the user.

Returns
Type Description
System.Security.Principal.IPrincipal

An IPrincipal with the associated roles initialized.

Remarks

The Roles system must be enabled in order for this method to work. Note that there is no check that the passed username exists in the current Membership provider, a non-existing username will return a principal object with the given name and an empty role list. If role system is disabled then a principal without roles is returned.

HasPathAccess(String)

Determines whether the contained principal has access to the specified path.

Declaration
public virtual bool HasPathAccess(string path)
Parameters
Type Name Description
System.String path

The path to check.

Returns
Type Description
System.Boolean

true if the contained principal has access to the specified path; otherwise, false.

IsPermitted(PermissionType)

Determines whether the specified permission is granted to the current principal.

Declaration
public bool IsPermitted(PermissionType permissionType)
Parameters
Type Name Description
PermissionType permissionType

The permission type.

Returns
Type Description
System.Boolean

true if the specified permission is granted; otherwise, false.

RecreatePrincipalForThreading()

Recreates the principal for threading. This function should be used before the worker thread is created to avoiding get System.ObjectDisposedException or run under AnonymousPrincipal ... ... RecreatePrincipalForThreading(); ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadStart), State);

Declaration
public static void RecreatePrincipalForThreading()

WindowsIdentityRoles(WindowsIdentity)

Gets the identity roles for a WindowsIdentity.

Declaration
public ICollection<string> WindowsIdentityRoles(WindowsIdentity wi)
Parameters
Type Name Description
System.Security.Principal.WindowsIdentity wi

The WindowsIdentity object.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

A collection of role names.

Remarks

In most cases you should use the RoleList method.

Extension Methods