Table of Contents

Class AppPrincipal

Namespace
Arc4u.Security.Principal
Assembly
Arc4u.dll

AppPrincipal is the principal which knows all the information on a person (authorization, authentication and profile information). We use a principal because it is copied from thrad to thead (new in .Net 2.0).

public class AppPrincipal : ClaimsPrincipal, IPrincipal, IAuthorization
Inheritance
AppPrincipal
Implements
Inherited Members

Constructors

AppPrincipal(Authorization, IIdentity, string)

Initializes a new instance of the AppPrincipal class.

public AppPrincipal(Authorization authorizationData, IIdentity identity, string sid)

Parameters

authorizationData Authorization

The authorization data.

identity IIdentity

The identity.

sid string

The sid.

Properties

Profile

Gets or sets the profile.

public UserProfile Profile { get; set; }

Property Value

UserProfile

The profile.

Sid

Gets the security identifier of the principal. It is updated with the Sid when the Profile is set.

public string Sid { get; }

Property Value

string

Methods

IsAuthorized(string)

Determines whether the specified operation is authorized in the default (empty) scope.

public bool IsAuthorized(string operation)

Parameters

operation string

The operation name.

Returns

bool

true if the specified operation is authorized; otherwise, false.

Remarks

This overload exists so that IsAuthorized("Name") compiles: without it, a single string argument matches both IsAuthorized(string, params int[]) and IsAuthorized(string, params string[]) with an empty operations array, which is ambiguous.

IsAuthorized<TAccess>(params TAccess[])

Determines whether all the specified operations, expressed with an enumeration, are authorized in the empty scope. The numeric value of each enumeration member is the operation identifier.

public bool IsAuthorized<TAccess>(params TAccess[] operations) where TAccess : struct, Enum

Parameters

operations TAccess[]

The operations.

Returns

bool

true if all the operations are authorized; otherwise false.

Type Parameters

TAccess

The enumeration type whose members identify the operations.

Examples

public enum Access { Read = 1, Write = 2 }

if (principal.IsAuthorized(Access.Read, Access.Write))
{
    // The user can read and write.
}