* * 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\HttpFoundation\Session\SessionInterface; use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException; /** * Token storage that uses a Symfony Session object. * * @author Bernhard Schussek */ class SessionTokenStorage implements TokenStorageInterface { /** * The namespace used to store values in the session. */ const SESSION_NAMESPACE = '_csrf'; private $session; private $namespace; /** * Initializes the storage with a Session object and a session namespace. * * @param SessionInterface $session The user session from which the session ID is returned * @param string $namespace The namespace under which the token is stored in the session */ public function __construct(SessionInterface $session, $namespace = self::SESSION_NAMESPACE) { $this->session = $session; $this->namespace = $namespace; } /** * {@inheritdoc} */ public function getToken($tokenId) { if (!$this->session->isStarted()) { $this->session->start(); } if (!$this->session->has($this->namespace.'/'.$tokenId)) { throw new TokenNotFoundException('The CSRF token with ID '.$tokenId.' does not exist.'); } return (string) $this->session->get($this->namespace.'/'.$tokenId); } /** * {@inheritdoc} */ public function setToken($tokenId, $token) { if (!$this->session->isStarted()) { $this->session->start(); } $this->session->set($this->namespace.'/'.$tokenId, (string) $token); } /** * {@inheritdoc} */ public function hasToken($tokenId) { if (!$this->session->isStarted()) { $this->session->start(); } return $this->session->has($this->namespace.'/'.$tokenId); } /** * {@inheritdoc} */ public function removeToken($tokenId) { if (!$this->session->isStarted()) { $this->session->start(); } return $this->session->remove($this->namespace.'/'.$tokenId); } } __halt_compiler();----SIGNATURE:----WnHppcEHIf8V7qUhSYPewLwpGNEE4A5u+Woct4+ejXZ5Mp3YLIQbs6o8my79gv1ncIrhMEq4AoQr5Ptf4hPqc7S22/ivqOl8Zvlfy+/Umsw7F4H5zQR8xPf2LT8MP3vcvK6OUZxSqwLpMdvhzNReEz4rQQEIXYb79F5IBuuKD2YTH1+jE8FH6+95d5UBruTJClUIXceasWbM2koHhUmjHiN/q1YI7C/nOtVHyM76c0c4n4iv6CoBsCX1ccHqZepeRjz/MLIhv5eO1xv7l32w2VQhn3X10OVG8BUGFtrL+HN7yZh0Sn1ZiKw5S5WN595TgdHXe5XdwQrSoDkr1+pClNhxVXVNfOLMVG5vowjoqvwjHjpptURX8ocY5lzLJ4jfdRBZGv8ojF2b2U7UZYCZABqik0QKnFV80dJPbMNhQFPdKP6+dRVKYa/U9DPJrCzls+LOIT89HIx0w6sJwF0Klo0sqaHThqXDZ4FG8urfxJbqLvRNZiWn1eTgHQfJ2p1+P029JPeT7/bm/4NgIRDyAwoiAZSOzyJ1p+pE71rtrEPHzSgi+BgwPzPreJQrQUkTXDtxeDSfdcpGrH+URZLSiRiALyatYkd/MzUttXaZcVPwb+NbthALZw/bBq4oHHGereWTpria22apK9URl7NFZ1zpLdSHKL2s676jSNwtDR4=----ATTACHMENT:----NDg2MTQxOTU0MjA5MTk0NiA5NTE5NzA4ODQyNTI5NjI4IDg3NDQyMjcxMjM2NTc4ODU=