From 74cd6ed5fcc8d5e4c8e9fc84ab8e521b46c15143 Mon Sep 17 00:00:00 2001
From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr>
Date: Tue, 9 Nov 2021 16:55:55 +0100
Subject: [PATCH] =?UTF-8?q?[FIX]=20Tentative=20de=20r=C3=A9agir=20en=20cas?=
 =?UTF-8?q?=20d'erreur=20'PHP=20Fatal=20error:=20=20Uncaught=20Zend\Sessio?=
 =?UTF-8?q?n\Exception\RuntimeException:=20Session=20validation=20failed?=
 =?UTF-8?q?=20in=20...=20SessionManager.php:160'?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Authentication/Storage/AuthFactory.php       | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/UnicaenAuth/Authentication/Storage/AuthFactory.php b/src/UnicaenAuth/Authentication/Storage/AuthFactory.php
index 7dc7f0e..8fa4fed 100644
--- a/src/UnicaenAuth/Authentication/Storage/AuthFactory.php
+++ b/src/UnicaenAuth/Authentication/Storage/AuthFactory.php
@@ -4,6 +4,7 @@ namespace UnicaenAuth\Authentication\Storage;
 
 use Interop\Container\ContainerInterface;
 use Zend\Authentication\Storage\Session;
+use Zend\Session\Exception\RuntimeException;
 use Zend\Session\SessionManager;
 
 class AuthFactory
@@ -19,8 +20,19 @@ class AuthFactory
         $sessionManager = $container->get(SessionManager::class);
 
         $storage = new Auth();
-        $storage->setStorage(new Session(Usurpation::class, null, $sessionManager));
+
+        try {
+            $storage->setStorage(new Session(Usurpation::class, null, $sessionManager));
+        } catch (RuntimeException $e) {
+            /**
+             * Tentative de réagir en cas d'erreur suivante :
+             * "PHP Fatal error:  Uncaught Zend\Session\Exception\RuntimeException: Session validation failed in
+             * /var/www/sygal/vendor/zendframework/zend-session/src/SessionManager.php:160"
+             */
+            $sessionManager->regenerateId(true);
+            $storage->setStorage(new Session(Usurpation::class, null, $sessionManager));
+        }
 
         return $storage;
     }
-}
\ No newline at end of file
+}
-- 
GitLab