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
IdleTime
How long since last activity
public TimeSpan IdleTime { get; }
Property Value
LastActivityTime
Last time any activity occurred in this session
public DateTime LastActivityTime { get; }
Property Value
LoginTime
When the user logged in
public DateTime LoginTime { get; }
Property Value
SessionDuration
How long the session has been active
public TimeSpan SessionDuration { get; }
Property Value
SessionId
Unique identifier for this session
public Guid SessionId { get; }
Property Value
UserId
Convenience property to get the user's ID
public Guid UserId { get; }
Property Value
UserRole
Convenience property to get the user's role
public UserRole UserRole { get; }
Property Value
Username
Convenience property to get the username
public string Username { get; }
Property Value
Methods
CreateSession(IUserProfile)
Factory method to create a new session for an authenticated user
public static SessionContext CreateSession(IUserProfile authenticatedUser)
Parameters
authenticatedUserIUserProfile
Returns
HasPermission(Permission)
Checks if the authenticated user has a specific permission
public bool HasPermission(Permission permission)
Parameters
permissionPermission
Returns
IsExpired(TimeSpan?)
Whether the session has been idle too long (default 30 minutes)
public bool IsExpired(TimeSpan? maxIdleTime = null)
Parameters
maxIdleTimeTimeSpan?
Returns
ToString()
Gets a display string for the current session
public override string ToString()
Returns
UpdateActivity()
Updates the last activity time to now
public void UpdateActivity()