[WIP] migrates SessionLockRequestComponent to new MiddlewareInterface
This commit is contained in:
parent
d7dbff9fc2
commit
28c6c8ef59
4 changed files with 18 additions and 18 deletions
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace DigiComp\FlowSessionLock\Aspects;
|
||||
|
||||
use DigiComp\FlowSessionLock\Http\SessionLockRequestComponent;
|
||||
use DigiComp\FlowSessionLock\Http\SessionLockRequestMiddleware;
|
||||
use Neos\Flow\Annotations as Flow;
|
||||
use Neos\Flow\Aop\JoinPointInterface;
|
||||
use Neos\Flow\Core\Bootstrap;
|
||||
|
@ -52,9 +52,8 @@ class ReadOnlyAspect
|
|||
$this->readOnly = true;
|
||||
|
||||
/** @var Lock|null $lock */
|
||||
$lock = $activeRequestHandler->getComponentContext()->getParameter(
|
||||
SessionLockRequestComponent::class,
|
||||
SessionLockRequestComponent::PARAMETER_NAME
|
||||
$lock = $activeRequestHandler->getHttpRequest()->getAttribute(
|
||||
SessionLockRequestMiddleware::class . '.' . SessionLockRequestMiddleware::PARAMETER_NAME
|
||||
);
|
||||
if ($lock !== null) {
|
||||
$this->logger->debug('SessionLock: Release, as this is marked read only.');
|
||||
|
|
|
@ -5,14 +5,16 @@ declare(strict_types=1);
|
|||
namespace DigiComp\FlowSessionLock\Http;
|
||||
|
||||
use Neos\Flow\Annotations as Flow;
|
||||
use Neos\Flow\Http\Component\ComponentContext;
|
||||
use Neos\Flow\Http\Component\ComponentInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Lock\Exception\LockAcquiringException;
|
||||
use Symfony\Component\Lock\Key;
|
||||
use Symfony\Component\Lock\LockFactory;
|
||||
|
||||
class SessionLockRequestComponent implements ComponentInterface
|
||||
class SessionLockRequestMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public const PARAMETER_NAME = 'sessionLock';
|
||||
|
||||
|
@ -55,13 +57,13 @@ class SessionLockRequestComponent implements ComponentInterface
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function handle(ComponentContext $componentContext): void
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$sessionCookieName = $this->sessionSettings['name'];
|
||||
|
||||
$cookies = $componentContext->getHttpRequest()->getCookieParams();
|
||||
$cookies = $request->getCookieParams();
|
||||
if (!isset($cookies[$sessionCookieName])) {
|
||||
return;
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
// TODO: sessionIdentifier might be wrong, probably it should probably be storage identifier
|
||||
|
@ -69,7 +71,7 @@ class SessionLockRequestComponent implements ComponentInterface
|
|||
|
||||
$lock = $this->lockFactory->createLockFromKey($key, $this->timeToLive, $this->autoRelease);
|
||||
|
||||
$componentContext->setParameter(SessionLockRequestComponent::class, static::PARAMETER_NAME, $lock);
|
||||
$request = $request->withAttribute(static::class . '.' . static::PARAMETER_NAME, $lock);
|
||||
|
||||
$this->logger->debug('SessionLock: Try to get "' . $key . '"');
|
||||
$timedOut = \time() + $this->secondsToWait;
|
||||
|
@ -83,5 +85,6 @@ class SessionLockRequestComponent implements ComponentInterface
|
|||
\usleep(100000);
|
||||
}
|
||||
$this->logger->debug('SessionLock: Acquired "' . $key . '"');
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
|
@ -9,9 +9,7 @@ DigiComp:
|
|||
Neos:
|
||||
Flow:
|
||||
http:
|
||||
chain:
|
||||
preprocess:
|
||||
chain:
|
||||
lockSession:
|
||||
position: "before getSessionCookieFromRequest"
|
||||
component: "DigiComp\\FlowSessionLock\\Http\\SessionLockRequestComponent"
|
||||
middlewares:
|
||||
lockSession:
|
||||
position: "before session"
|
||||
middleware: "DigiComp\\FlowSessionLock\\Http\\SessionLockRequestMiddleware"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"description": "Session locking for Neos Flow - it secures the session becoming corrupted by concurrent access to the same session by different requests",
|
||||
"type": "neos-package",
|
||||
"require": {
|
||||
"neos/flow": "^6.3.0",
|
||||
"neos/flow": "^7.3.0",
|
||||
"php": ">=7.4",
|
||||
"symfony/lock": "^5.2.0"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue