diff --git a/Classes/Aspects/ReadOnlyAspect.php b/Classes/Aspects/ReadOnlyAspect.php index 3ece8df..3728566 100644 --- a/Classes/Aspects/ReadOnlyAspect.php +++ b/Classes/Aspects/ReadOnlyAspect.php @@ -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.'); diff --git a/Classes/Http/SessionLockRequestComponent.php b/Classes/Http/SessionLockRequestMiddleware.php similarity index 78% rename from Classes/Http/SessionLockRequestComponent.php rename to Classes/Http/SessionLockRequestMiddleware.php index 43109ad..a8630da 100644 --- a/Classes/Http/SessionLockRequestComponent.php +++ b/Classes/Http/SessionLockRequestMiddleware.php @@ -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); } } diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index f283d84..08c69fc 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -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" diff --git a/composer.json b/composer.json index d775e36..1858857 100644 --- a/composer.json +++ b/composer.json @@ -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" },