* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Csrf\TokenStorage; use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException; /** * Token storage that uses PHP's native session handling. * * @author Bernhard Schussek */ class NativeSessionTokenStorage implements TokenStorageInterface { /** * The namespace used to store values in the session. */ const SESSION_NAMESPACE = '_csrf'; private $sessionStarted = false; private $namespace; /** * Initializes the storage with a session namespace. * * @param string $namespace The namespace under which the token is stored in the session */ public function __construct($namespace = self::SESSION_NAMESPACE) { $this->namespace = $namespace; } /** * {@inheritdoc} */ public function getToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } if (!isset($_SESSION[$this->namespace][$tokenId])) { throw new TokenNotFoundException('The CSRF token with ID '.$tokenId.' does not exist.'); } return (string) $_SESSION[$this->namespace][$tokenId]; } /** * {@inheritdoc} */ public function setToken($tokenId, $token) { if (!$this->sessionStarted) { $this->startSession(); } $_SESSION[$this->namespace][$tokenId] = (string) $token; } /** * {@inheritdoc} */ public function hasToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } return isset($_SESSION[$this->namespace][$tokenId]); } /** * {@inheritdoc} */ public function removeToken($tokenId) { if (!$this->sessionStarted) { $this->startSession(); } if (!isset($_SESSION[$this->namespace][$tokenId])) { return; } $token = (string) $_SESSION[$this->namespace][$tokenId]; unset($_SESSION[$this->namespace][$tokenId]); if (!$_SESSION[$this->namespace]) { unset($_SESSION[$this->namespace]); } return $token; } private function startSession() { if (PHP_SESSION_NONE === session_status()) { session_start(); } $this->sessionStarted = true; } } __halt_compiler();----SIGNATURE:----Ct/Fa26UmEhUZVsgo5UwOHMCpNVyUsNJFONSUfL610C45OAKJiGd9gysYLpXpeeU8EeUENxwte4sFFOBQnri2FoJ/Sk18H/H1CI2CZJZ9U7VXHkSlDaNLiEWuEaRxsGC+vMzN5GL0jJ5yg62PFnz4BZgqOTxstyDP9CG6mVOAJ2zOwQwmtTDzRzI9GD0ejT4yCUGXxvbCIjhldBfo9OXh4Voq4rqCQFz2gqwLKRSqIsUb4X89hOHIMXsyJGyypTAXviBzSWbGp6RUh1ifN+ZCrPWgiRhuGR9OtWyzQ9ZLBjHppj2nlCejMF4B0sQEm1l56mkmSdK4g9LY8qK3Jn5ABNCYgtT1ghV8SjeVP6ykZ2LB1Ykm1ay4TfCKSX7+UkylzDX6Uz1jsZoMCOhpirRMvBEDoum4yZ5NqW5Do/OPDJWQFEvanR3PmDspcpMk2U63zGxsj+NUccZTJXmnyfKt1SG8dFi1CLmje99ou72eAeeGDqBVRxkALLlUIgUblKTEt1OOwieUtSYj1bpfoONx+4xst0owJfl5P3Yn7XM9JscukQ5ChK/GcYK2vpHhAjmDxPVNxLdKC7uexsPFa6lj5uEafzIZJhq3yNBwtefhvTqRb2T+AxbeIucza2VASSodqyWaqFAh74eMvIXAYJyDk2o15BhLzQ2weBeherdjK8=----ATTACHMENT:----MTE4MDkwOTk4MTA5NzYwMCAxMDYxMzY2MjI2MjI0ODA0IDIxNDg0NDY0MTUzNzQ2NDc=