Functional Core - Pure session business logic - Minimal working version
Functional Core - Pure session business logic - Minimal working version
(account-refusal user)Why user (nil when gone) may not authenticate, or nil.
Why `user` (nil when gone) may not authenticate, or nil.
(analyze-session-duration session now)Calculate session duration in hours from creation to last access.
Calculate session duration in hours from creation to last access.
(calculate-session-risk-score session previous-sessions)Calculate a 0.0-1.0 risk score based on IP changes and concurrent sessions.
Calculate a 0.0-1.0 risk score based on IP changes and concurrent sessions.
(calculate-user-session-stats sessions user-id)Compute active/inactive session counts for a given user-id.
Compute active/inactive session counts for a given user-id.
How long a session lasts from sign-in, however it is used (BOU-1007).
How long a session lasts from sign-in, however it is used (BOU-1007).
(detect-suspicious-activity? session previous-sessions)Detect suspicious patterns (IP change, concurrent sessions) between current and previous sessions.
Detect suspicious patterns (IP change, concurrent sessions) between current and previous sessions.
(ends-at session max-days)When session ends however it is used: max-days after sign-in. Nil for
one that does not say when it began.
When `session` ends however it is used: `max-days` after sign-in. Nil for one that does not say when it began.
Where the page says the user is still there (BOU-1007).
Where the page says the user is still there (BOU-1007).
(extract-device-info user-agent ip-address)Parse user-agent and ip-address into a device-info map with :device-type.
Parse user-agent and ip-address into a device-info map with :device-type.
(filter-sessions-for-cleanup sessions current-time)Return sessions that have been expired past the cleanup grace period.
Return sessions that have been expired past the cleanup grace period.
(generate-session-token timestamp-ms nonce)Build a deterministic session token from a timestamp and nonce.
Build a deterministic session token from a timestamp and nonce.
(group-sessions-by-device-type sessions)Group sessions into :mobile, :desktop, or :other based on user-agent.
Group sessions into :mobile, :desktop, or :other based on user-agent.
(is-same-device? device1 device2)Check if two device-info maps represent the same device (same IP and similar user-agent).
Check if two device-info maps represent the same device (same IP and similar user-agent).
(is-session-valid? session current-time max-days)Check if session is valid: not nil, not revoked, not expired, and within
max-days of sign-in (BOU-1007).
Check if session is valid: not nil, not revoked, not expired, and within `max-days` of sign-in (BOU-1007).
(mark-session-for-cleanup session current-time)Mark session as revoked by setting :revoked-at to current time.
Mark session as revoked by setting :revoked-at to current time.
(max-days auth-config)The days auth-config lets a session last, however it is used.
The days `auth-config` lets a session last, however it is used.
(prepare-session-for-invalidation session current-time)Pure function: Prepare session for invalidation.
Args: session: Current session entity current-time: Current timestamp
Returns: Session entity marked as revoked
Pure - data transformation only.
Pure function: Prepare session for invalidation. Args: session: Current session entity current-time: Current timestamp Returns: Session entity marked as revoked Pure - data transformation only.
(prune-cutoff now retention-days)The instant before which an expired session may be deleted.
Retention is counted from expiry, not from creation: a session that expires
today is removed retention-days from today, whatever its age. A retention
of 0 deletes a session the moment it expires.
The instant before which an expired session may be deleted. Retention is counted from expiry, not from creation: a session that expires today is removed `retention-days` from today, whatever its age. A retention of 0 deletes a session the moment it expires.
Where the page signs the user in again before the session ends (BOU-1007).
Where the page signs the user in again before the session ends (BOU-1007).
(same-ip? a b)Equal and known: two unresolved client addresses are not the same one.
Equal and known: two unresolved client addresses are not the same one.
(session-access-write session current-time max-days)The session to write for an access at current-time, or nil when nothing
needs writing: at most once a minute (BOU-666), so the expiry slides a
minute late at most (BOU-1007).
The session to write for an access at `current-time`, or nil when nothing needs writing: at most once a minute (BOU-666), so the expiry slides a minute late at most (BOU-1007).
(should-cleanup-session? session current-time cleanup-policy)Return true if session has been expired longer than the grace period.
Return true if session has been expired longer than the grace period.
(should-require-additional-verification? session previous-sessions)Return true if session risk score exceeds the verification threshold (0.5).
Return true if session risk score exceeds the verification threshold (0.5).
(update-session-access session current-time max-days)session used at current-time: it slides by its own :duration-hours, the
hours its sign-in got, never past ends-at (BOU-1007). One from before
then has none and slides 24 hours, as it did.
`session` used at `current-time`: it slides by its own :duration-hours, the hours its sign-in got, never past `ends-at` (BOU-1007). One from before then has none and slides 24 hours, as it did.
(validate-session-creation-request session-data)Validate that session-data has the required :user-id key.
Validate that session-data has the required :user-id key.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |