Table of Contents

Class SessionStorage

Namespace
DuetWebServer.Singletons
Assembly
DuetWebServer.dll

Storage singleton for internal HTTP sessions

public class SessionStorage : ISessionStorage
Inheritance
SessionStorage
Implements
Inherited Members

Constructors

SessionStorage(ILogger<SessionStorage>)

Storage singleton for internal HTTP sessions

public SessionStorage(ILogger<SessionStorage> logger)

Parameters

logger ILogger<SessionStorage>

Logger instance

Methods

CacheMessage(string)

Cache an incoming generic message

public void CacheMessage(string message)

Parameters

message string

Message to cache

CheckSessionKey(string, bool)

Check if the given session key provides the requested access to the given policy

public bool CheckSessionKey(string key, bool readWrite)

Parameters

key string

Session key

readWrite bool

If readWrite or readOnly policy is requested

Returns

bool

True if access is granted

GetCachedMessages(ClaimsPrincipal)

Retrieve the cached messages of a given user

public string GetCachedMessages(ClaimsPrincipal user)

Parameters

user ClaimsPrincipal

Returns

string

Cached messages

GetSessionId(string)

Get a session ID from the given key

public int GetSessionId(string key)

Parameters

key string

Key to query

Returns

int

Session ID or -1

GetTicketFromIpAddress(string)

Get a ticket from the given IP address

public AuthenticationTicket? GetTicketFromIpAddress(string ipAddress)

Parameters

ipAddress string

IP address to query

Returns

AuthenticationTicket

Authentication ticket or null

GetTicketFromKey(string)

Get a ticket from the given key

public AuthenticationTicket? GetTicketFromKey(string key)

Parameters

key string

Key to query

Returns

AuthenticationTicket

Authentication ticket or null

MaintainSessions(TimeSpan, string)

Remove sessions that are no longer active

public void MaintainSessions(TimeSpan sessionTimeout, string socketPath)

Parameters

sessionTimeout TimeSpan

Timeout for HTTP sessions

socketPath string

API socket path

MakeSessionKey(int, string, bool)

Make a new session key and register it if the session ID is valid

public string MakeSessionKey(int sessionId, string ipAddress, bool readWrite)

Parameters

sessionId int

DSF session ID

ipAddress string

Optional IP address if the request came from a RRF HTTP request

readWrite bool

Whether the client has read-write or read-only access

Returns

string

Authentication ticket

MakeSessionTicket(int, string, bool)

Make a new session ticket and register it if the session ID is valid

public AuthenticationTicket MakeSessionTicket(int sessionId, string ipAddress, bool readWrite)

Parameters

sessionId int

DSF session ID

ipAddress string

Optional IP address if the request came from a RRF HTTP request

readWrite bool

Whether the client has read-write or read-only access

Returns

AuthenticationTicket

Authentication ticket

RemoveTicket(ClaimsPrincipal)

Remove a session ticket returning the corresponding session ID

public int RemoveTicket(ClaimsPrincipal user)

Parameters

user ClaimsPrincipal

Returns

int

Session ID or 0 if none was found

SetLongRunningHttpRequest(ClaimsPrincipal, bool)

Set whether a potentially long-running HTTP request has started or finished

public void SetLongRunningHttpRequest(ClaimsPrincipal user, bool requestStarted)

Parameters

user ClaimsPrincipal

Principal user

requestStarted bool

Whether a WebSocket is connected

SetWebSocketState(string, bool)

Set whether a given socket is connected over WebSocket

public void SetWebSocketState(string key, bool webSocketConnected)

Parameters

key string

Session key

webSocketConnected bool

Whether a WebSocket is connected