crossbar.router.cookiestore

Classes

CookieStore

Cookie store common base.

CookieStoreDatabaseBacked

A persistent, database-backed cookie store. This implementation uses a zLMDB

CookieStoreFileBacked

A persistent, file-backed cookie store.

CookieStoreMemoryBacked

Memory-backed cookie store.

Module Contents

class CookieStore(config: Dict[str, Any])[source]

Bases: object

Cookie store common base.

_config[source]
_connections: Dict[str, Set[autobahn.wamp.interfaces.ISession]][source]
addProto(cbtid: str, proto: autobahn.wamp.interfaces.ISession) int[source]

Add given WebSocket connection to the set of connections associated with the cookie having the given ID. Return the new count of connections associated with the cookie.

dropProto(cbtid: str, proto: autobahn.wamp.interfaces.ISession)[source]

Remove given WebSocket connection from the set of connections associated with the cookie having the given ID. Return the new count of connections associated with the cookie.

exists(cbtid: str) bool[source]
getProtos(cbtid: str) List[autobahn.wamp.interfaces.ISession][source]

Get all WebSocket connections currently associated with the cookie.

log[source]
parse(headers)[source]

Parse HTTP request header for cookie. If cookie is found, return cookie ID, else return None.

class CookieStoreDatabaseBacked(dbpath: str, config: Dict[str, Any])[source]

Bases: CookieStore

A persistent, database-backed cookie store. This implementation uses a zLMDB based embedded database with Flatbuffers data serialization.

_db[source]
_schema[source]
create() Tuple[str, str][source]

Create and store a new cookie (unauthenticated) in the database.

Returns:

A pair with Cookie value (ID, cbtid) and complete Cookie HTTP header value.

delAuth(cbtid: str) bool[source]

Delete an existing cookie (if any), including any authentication info and the cookie itself.

Parameters:

cbtid – Cookie value (ID) of cookie to delete.

Returns:

Flag indicating an existing cookie was deleted.

exists(cbtid: str) bool[source]

Check if a cookie with given value currently exists in the cookie store.

Parameters:

cbtid – Cookie value (ID) to check.

Returns:

Flag indicating whether a cookie (authenticated or not) is stored in the database.

getAuth(cbtid: str) Tuple[str | None, str | None, str | None, str | None, Dict[str, Any] | None][source]

Get the authentication info (if any) for a cookie stored in the database.

Parameters:

cbtid – Cookie value (ID) to get authentication for.

Returns:

A tuple (authid, authrole, authmethod, authrealm, authextra) if the cookie exists, or a tuple (None, None, None, None, None) if no cookie with given cbtid is currently stored.

setAuth(cbtid: str, authid: str | None, authrole: str | None, authmethod: str | None, authextra: Dict[str, Any] | None, authrealm: str | None) bool[source]

Update the authentication information associated and stored for an existing cookie (if any).

Parameters:
  • cbtid – Cookie value (ID) to update authentication for.

  • authid – The WAMP authid a cookie-authenticating session is to be assigned.

  • authrole – The WAMP authrole a cookie-authenticating session is to join under.

  • authmethod – The WAMP authentication method to be returned to the client performing this cookie-based authentication.

  • authextra – The WAMP authentication extra data to be returned to the client performing this cookie-based authentication.

  • authrealm – The WAMP realm a cookie-authenticating session is to join.

Returns:

Flag indicating an existing cookie was modified.

class CookieStoreFileBacked(cookie_file_name, config)[source]

Bases: CookieStoreMemoryBacked

A persistent, file-backed cookie store.

This cookie store is backed by a file, which is written to in append-only mode. Hence, the file is “growing forever”. Whenever information attached to a cookie is changed (such as a previously anonymous cookie is authenticated), a new cookie record is appended. When the store is booting, the file is sequentially scanned. The last record for a given cookie ID is remembered in memory.

_init_store()[source]
_iter_persisted()[source]
_persist(cbtid, c, status)[source]
create()[source]

Create a new cookie, returning the cookie ID and cookie header value.

delAuth(cbtid: str) bool[source]

Delete an existing cookie (if any), including any authentication info and the cookie itself.

Parameters:

cbtid – Cookie value (ID) of cookie to delete.

Returns:

Flag indicating an existing cookie was deleted.

setAuth(cbtid, authid, authrole, authmethod, authextra, authrealm)[source]

Set (authid, authrole, authmethod, authextra) for given cookie ID.

class CookieStoreMemoryBacked(config: Dict[str, Any])[source]

Bases: CookieStore

Memory-backed cookie store.

_cookies: Dict[str, Dict[str, Any]][source]
create()[source]

Create a new cookie, returning the cookie ID and cookie header value.

delAuth(cbtid: str) bool[source]

Delete an existing cookie (if any), including any authentication info and the cookie itself.

Parameters:

cbtid – Cookie value (ID) of cookie to delete.

Returns:

Flag indicating an existing cookie was deleted.

exists(cbtid)[source]

Check if cookie with given ID exists.

getAuth(cbtid)[source]

Return (authid, authrole, authmethod, authrealm, authextra) tuple given cookie ID.

setAuth(cbtid, authid, authrole, authmethod, authextra, authrealm)[source]

Set (authid, authrole, authmethod, authextra) for given cookie ID.