morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::session::SigningAuthorizer Class Reference

IAuthorizer that authenticates via a signed Context::token. More...

#include <session_auth.hpp>

Inheritance diagram for morph::session::SigningAuthorizer:
morph::session::IAuthorizer

Public Types

using Policy
 Optional per-request policy over verified claims.

Public Member Functions

 SigningAuthorizer (std::string secret, MacFunction mac=hmacSha256, Clock clock=systemClockMs, Policy policy={})
 Constructs the authorizer.
bool authorize (const Context &ctx, std::string_view modelType, std::string_view actionType) const override
 Allows the call iff ctx carries a valid token the policy admits.
std::optional< std::string > authenticate (const Context &ctx) const override
 Returns the verified principal so the server can make it authoritative.
Admission admit (const Context &ctx, std::string_view modelType, std::string_view actionType) const override
 Verifies ctx's token once, then asks authenticate and authorize as the default admit does.
Public Member Functions inherited from morph::session::IAuthorizer
virtual bool authorizeInstance (const Context &ctx, std::string_view modelType, std::string_view actionType, std::uint64_t modelId, std::string_view ownerPrincipal) const
 Optional per-**instance** authorization hook — the multi-tenant gate.
virtual bool authorizeRegister (const Context &ctx, std::string_view modelType) const
 Optional gate on model creation — bounds who may create an instance.

Detailed Description

IAuthorizer that authenticates via a signed Context::token.

authorize returns true only for a token with a valid signature and unexpired claims (and, if a policy is supplied, one the policy admits). authenticate returns the verified principal so RemoteServer makes it authoritative. Install it on the server:

auto authz = std::make_shared<morph::session::SigningAuthorizer>(sharedSecret);
auto server = std::make_shared<morph::backend::RemoteServer>(pool, authz);

Definition at line 523 of file session_auth.hpp.

Member Typedef Documentation

◆ Policy

Initial value:
std::function<bool(const SessionToken& claims, std::string_view modelType, std::string_view actionType)>
Verified claims carried by a session token.

Optional per-request policy over verified claims.

Receives the verified token plus the target ids; return false to deny. The action id is empty for the instances, schemas and deregister envelopes, and the model type id is empty for deregister – see IAuthorizer::authorize's own doc comment for why, and handle those cases explicitly rather than letting them reach a default arm. The default (empty) admits any validly-signed, unexpired token.

Definition at line 533 of file session_auth.hpp.

Constructor & Destructor Documentation

◆ SigningAuthorizer()

morph::session::SigningAuthorizer::SigningAuthorizer ( std::string secret,
MacFunction mac = hmacSha256,
Clock clock = systemClockMs,
Policy policy = {} )
inlineexplicit

Constructs the authorizer.

Parameters
secretShared secret used to verify tokens.
macMAC primitive; defaults to hmacSha256. Forwarded into this authorizer's TokenVerifier and invoked for its whole lifetime, so anything the callable refers to must outlive it.
clockTime source (ms since epoch) for expiry; defaults to system time. Stored and invoked for this authorizer's whole lifetime, so anything the callable refers to must outlive it.
policyOptional per-request policy over verified claims. Stored and invoked on the same terms as clock.

Definition at line 567 of file session_auth.hpp.

Member Function Documentation

◆ authorize()

bool morph::session::SigningAuthorizer::authorize ( const Context & ctx,
std::string_view modelType,
std::string_view actionType ) const
inlinenodiscardoverridevirtual

Allows the call iff ctx carries a valid token the policy admits.

Parameters
ctxPer-call session (its token is verified).
modelTypeTarget model type id (passed to the policy).
actionTypeTarget action type id (passed to the policy).
Returns
true to allow dispatch, false to reject.

Implements morph::session::IAuthorizer.

Definition at line 577 of file session_auth.hpp.

◆ authenticate()

std::optional< std::string > morph::session::SigningAuthorizer::authenticate ( const Context & ctx) const
inlinenodiscardoverridevirtual

Returns the verified principal so the server can make it authoritative.

Parameters
ctxPer-call session (its token is verified).
Returns
The token's principal if valid, else nullopt.

Reimplemented from morph::session::IAuthorizer.

Definition at line 590 of file session_auth.hpp.

◆ admit()

Admission morph::session::SigningAuthorizer::admit ( const Context & ctx,
std::string_view modelType,
std::string_view actionType ) const
inlinenodiscardoverridevirtual

Verifies ctx's token once, then asks authenticate and authorize as the default admit does.

Both are still called through the vtable, so a subclass that overrides either keeps its own decision: a carve-out that admits a call without a token, or a rule that refuses more than the token does. While this call runs, SigningAuthorizer's own authenticate and authorize answer from the one verification instead of verifying again, so a token is judged against one clock reading. Nothing outlives the call.

Parameters
ctxPer-call session (its token is verified).
modelTypeTarget model type id (passed to authorize).
actionTypeTarget action type id (passed to authorize).
Returns
authorize's answer and authenticate's, from one verification.

Reimplemented from morph::session::IAuthorizer.

Definition at line 612 of file session_auth.hpp.


The documentation for this class was generated from the following file: