SecurityMiddleware
Security middleware: evaluates action security requirements and forwards unauthenticated/unauthorized requests to login/secure system actions.
Synopsis
Section titled “Synopsis”class SecurityMiddleware implements MiddlewareInterface
| Implements | MiddlewareInterface |
| Uses | RequestDiagnostics |
| Source | Middleware/SecurityMiddleware.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(Controller $controller, ?SecurityService $securityService = null, RandomnessInterface $randomness = new SystemRandomness(…)): mixed
| Parameter | Type | Description |
|---|---|---|
$controller | Controller | |
$securityService | ?SecurityService | |
$randomness | RandomnessInterface |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | Evaluates the routed action’s security requirements and forwards when they are not met. |
process()
Section titled “process()”public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Evaluates the routed action’s security requirements and forwards when they are not met.
Requires an ActionDescriptor attribute; without one the request passes straight through unexamined. Ensures a quiote.rid correlation attribute exists, then builds and initializes the action instance so its isSecure()/getCredentials() can be consulted, caching it on the request as quiote.preinstantiated_action for DispatchMiddleware to reuse.
With core.use_security off, everything is allowed. If the action could not be instantiated the decision fails closed rather than falling back to “authenticated is good enough”: an anonymous caller is sent to the login forward, an authenticated one to the secure forward. The decision is recorded on the request’s ExecutionState either way.
A non-allow decision swaps in a system login/secure ActionDescriptor, preserves the original as quiote.original_action, clears the preinstantiated action so the forwarded action gets a fresh instance, and resets the execution state’s view/attribute/validation fields. More than five forwards on one request yields a 508. If the forward descriptor itself cannot be built, a 403 is returned rather than letting the original action run.
| Parameter | Type | Description |
|---|---|---|
$request | ServerRequestInterface | |
$handler | RequestHandlerInterface |
Returns ResponseInterface