Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Snif.ClassServer

Feature notes: Snif remoting framework (concepts)

Classes, interfaces and records

recordTsnifUserListItem

fName: string; fAuthData: tBytes; fRoles: TArray<string>; fInfo: IInterface; fFailures: Int64; fTotalFailures: Int64; fLastFailure: TDateTime; fOtpHash: tBytes;
hash of a pending one-time password (empty = none)
fOtpExpiry: TDateTime;
expiry of the pending OTP
fLock: IReadWriteSync;

classTsnifUserRoleCollectionItem

inherits from TCollectionItem

(no public members)

classTsnifClassServer

inherits from TstBaseComponent

Inherit the standard required-unit suggestion hook and IDE component editor.

constructor Create(AOwner: TComponent); override;
Creates the server component. An application creates one TsnifClassServer per server process (usually owned by nil and freed manually), then registers its remotable classes and hands it to a transport server (e.g. assign it to TsnipSSHServer.ClassServer) so incoming connections are routed to it. » member page
destructor Destroy; override;
Frees the internal application (contexts/sessions/users) and role list. Called by the app when tearing the server down. » member page
class procedure RegisterServerClass(aClass: TClass);
Registers a class whose published methods become callable by remote clients. Class-wide (shared by every server instance in the process): call it once at startup, typically from a unit's initialization section, for each server class you want exposed. Full description »
class function FindServerClass(const aName: string): TsnifClassDescriptor;
Looks up the descriptor for a registered class by its qualified name. Mainly internal dispatch wiring (TsnifApplication.FindClassByName calls it when resolving an incoming request's ClsName); apps rarely call it directly. » member page
class function CurrentApplication: TsnifApplication;
Returns the internal TsnifApplication of the server that is currently processing a request on THIS thread (valid only inside Process). Used by server-side remotable code / auth handlers that need to reach the shared user, session and context registry; returns nil off a processing thread. » member page
class function CurrentContext: TsnifContext;
Returns the TsnifContext (connection) being serviced on THIS thread while a request is processed. Server-side remotable methods and auth code use it to identify the calling connection and its logged-in user (e.g. its Connection for channel binding); nil outside Process. » member page
class function FindCurrentUserListItem(const aUsername: string): TsnifUserListItem;
Reads (a copy of) the current server's user-list entry for aUsername -- auth data, roles and failure counters. Called from server-side authentication classes (e.g. SRP/AKE login) to load a user's stored credentials during a handshake. Returns an empty record if there is no current server. » member page
class procedure UpdateCurrentUserListItem(const aUsername: string; const aItem: TsnifUserListItem);
Writes an updated user-list entry back into the current server (and fires OnUserUpdated so a storage layer can persist it). Used by server-side auth classes when they mutate a user, e.g. AkeChangeAuth committing new auth data or a failed-attempt counter update. » member page
class procedure CurrentUserAuthenticated(const aUsername: string; aResetThrottle: Boolean = True);
Marks the current connection's user as successfully authenticated: binds the user to the current context and resets the consecutive-failure counter. Called by server-side auth handlers on a successful login. » member page
class procedure CurrentUserUnauthenticated(const aUsername: string);
Records a failed authentication attempt for aUsername (bumps the consecutive and total failure counters and the last-failure timestamp), for throttling / lockout policy. Called by server-side auth handlers on a rejected login. » member page
class procedure CurrentRequestOTP(const aUser, aOTP: string);
Fires the current server's OnRequestOTP so the application can deliver a freshly generated one-time password aOTP to aUser over a secondary channel (email/SMS). Called by a server-side login handler (AkeLogin.RequestOTP) during a request. » member page
class function CurrentConversionKind: TsnifConversionKind;
The ConversionKind of the server currently processing on this thread; the wire (de)serialization format. Used internally by server-side code that must match the active server's marshalling format. » member page
function GetUserList: TsnifUserList;
Returns the current user list (credentials + roles + counters). A persistence layer reads this to save the users back to storage (see TsnifCustomUserStorage). » member page
procedure UpdateUserList(const aUserList: TsnifUserList);
Bulk-loads the whole user list into the server: assigns a fresh lock per item and resets each user's roles from the stored role list. An app calls this at startup to populate the server from persistent storage (TsnifCustomUserStorage. LoadInto). This bulk load does NOT fire OnUserUpdated, so it does not loop back into the storage layer. » member page
function NewConnection(aConn: TsnipAbstractConnection): TsnifContext;
Server-side accept: given a freshly accepted transport connection, creates a new TsnifContext (naming the connection) or re-attaches to the existing context of a reconnecting client (matched by the connection Name). The transport server loop calls this once per accepted connection before entering its request loop; raises if a named connection has expired or is still active. » member page
function NewRequest: TsnifRequest;
Constructs an empty request object using this server's ConversionKind. Internal wiring: ProcessRequest uses it to build the request it reads off the wire. » member page
procedure CloseConnection(const aConn: IsnipConnection);
Detaches and removes the context bound to aConn. The transport server loop calls this when a connection's request loop ends (socket closed) to release the context; only removes it if aConn is still the context's current connection. » member page
function Process(aConnection: TsnifContext; aRequest: TsnifRequest): TsnifResponse;
Processes one already-parsed request against a context and returns the response: resolves/creates the session, enforces user/role authorization, then dispatches Call/Read/Free. Sets the per-thread Current* state for the duration. Server-side only; usually reached via ProcessRequest rather than called directly. The caller owns and must free the returned TsnifResponse. » member page
procedure ProcessRequest(aConnection: TsnifContext);
The server's per-request pump: reads one request off the connection, calls Process, and sends the response back. The transport server loop calls this repeatedly (once per available request) for the life of a connection. Reads outside the context monitor deliberately so concurrent server->client callback replies can be demultiplexed without deadlock. » member page
procedure ExpireSessions(aLastAccess: TDateTime);
Expires (drops) sessions whose last access is older than aLastAccess. An app's housekeeping timer calls this periodically to reclaim idle logged-in sessions. » member page
procedure ExpireConnections(aLastAccess: TDateTime);
Expires (drops) connections/contexts idle since before aLastAccess. An app's housekeeping timer calls this to reclaim stale contexts of disconnected clients. » member page
property Roles: TStrings read GetRoles;
The consolidated set of role names known to this server (gathered from all registered classes via RefreshRoles). Read-only; an app or admin UI reads it to enumerate the roles available for assignment. » member page
property ConversionKind: TsnifConversionKind read fConversionKind write SetConversionKind;
The wire (de)serialization format used for requests, responses and callbacks on this server. An app sets it once at setup so client and server agree on the marshalling format. » member page
property OnAddRole: TsnifGetRoleEvent read fOnAddRole write SetOnAddRole;
Fired for every role discovered while (re)building the role set from registered classes. An app hooks it to observe / customize each role as it is added (e.g. to attach role-info metadata). » member page
property OnUserUpdated: TsnifUserUpdatedEvent read fOnUserUpdated write fOnUserUpdated;
Fired when a single user entry is updated in place (via UpdateUserListItem, e.g. an auth-data or password change), so a storage layer can write that one user through to persistence. NOT fired by the bulk UpdateUserList. See TsnifCustomUserStorage.Attach. » member page
property OnRequestOTP: TsnifRequestOTPEvent read fOnRequestOTP write fOnRequestOTP;
Fired when a login handler has generated a one-time password for a user (see AkeLogin.RequestOTP). The application delivers the plaintext aOTP to aUser over a secondary channel (email / SMS); the server stores only its hash. Assigned in code (public, not published); on TsnipServer it is inherited and assignable. » member page

Types (enumerations, sets, aliases)

typeTsnifRole

  TsnifRole = StreamSec.Snif.Role.TsnifRole;

procTsnifGetRoleEvent

  TsnifGetRoleEvent = procedure (Sender: TObject; aRole: TsnifRole) of object;

arrayTsnifUserList

  TsnifUserList = array of TsnifUserListItem;

procTsnifUserUpdatedEvent

Fired when a single user item is updated in place (UpdateUserListItem, e.g. via AkeChangeAuth/ChangePassword), so a storage layer can write through. NOT fired by the bulk UpdateUserList (that is the storage LOADING the list).

  TsnifUserUpdatedEvent = procedure (Sender: TObject; const aUserName: string;
                                     const aItem: TsnifUserListItem) of object;

procTsnifRequestOTPEvent

Fired by a login handler (AkeLogin.RequestOTP) when a one-time password has been generated for aUser. The application delivers aOTP to the user over a SECONDARY channel (email / SMS). aOTP is the plaintext code; it is never sent over the login channel and only its hash is stored server-side. The handler MUST be non-blocking (enqueue the message and return): a synchronous send makes RequestOTP's response latency depend on account existence, i.e. a username-enumeration oracle.

  TsnifRequestOTPEvent = procedure (Sender: TObject; const aUser, aOTP: string) of object;