Table of Contents

Class SessionContext

Namespace
Core.CliniCore.Domain.Authentication.Representation
Assembly
Core.CliniCore.dll

Maintains context about the current authenticated session

public class SessionContext
Inheritance
SessionContext
Inherited Members

Properties

AuthenticatedUser

The currently authenticated user profile

public IUserProfile AuthenticatedUser { get; }

Property Value

IUserProfile

IdleTime

How long since last activity

public TimeSpan IdleTime { get; }

Property Value

TimeSpan

LastActivityTime

Last time any activity occurred in this session

public DateTime LastActivityTime { get; }

Property Value

DateTime

LoginTime

When the user logged in

public DateTime LoginTime { get; }

Property Value

DateTime

SessionDuration

How long the session has been active

public TimeSpan SessionDuration { get; }

Property Value

TimeSpan

SessionId

Unique identifier for this session

public Guid SessionId { get; }

Property Value

Guid

UserId

Convenience property to get the user's ID

public Guid UserId { get; }

Property Value

Guid

UserRole

Convenience property to get the user's role

public UserRole UserRole { get; }

Property Value

UserRole

Username

Convenience property to get the username

public string Username { get; }

Property Value

string

Methods

CreateSession(IUserProfile)

Factory method to create a new session for an authenticated user

public static SessionContext CreateSession(IUserProfile authenticatedUser)

Parameters

authenticatedUser IUserProfile

Returns

SessionContext

HasPermission(Permission)

Checks if the authenticated user has a specific permission

public bool HasPermission(Permission permission)

Parameters

permission Permission

Returns

bool

IsExpired(TimeSpan?)

Whether the session has been idle too long (default 30 minutes)

public bool IsExpired(TimeSpan? maxIdleTime = null)

Parameters

maxIdleTime TimeSpan?

Returns

bool

ToString()

Gets a display string for the current session

public override string ToString()

Returns

string

UpdateActivity()

Updates the last activity time to now

public void UpdateActivity()