* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Csrf; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\Exception\InvalidArgumentException; use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator; use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface; use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage; use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface; /** * Default implementation of {@link CsrfTokenManagerInterface}. * * @author Bernhard Schussek * @author Kévin Dunglas */ class CsrfTokenManager implements CsrfTokenManagerInterface { private $generator; private $storage; private $namespace; /** * @param null|string|RequestStack|callable $namespace * * null: generates a namespace using $_SERVER['HTTPS'] * * string: uses the given string * * RequestStack: generates a namespace using the current master request * * callable: uses the result of this callable (must return a string) */ public function __construct(TokenGeneratorInterface $generator = null, TokenStorageInterface $storage = null, $namespace = null) { $this->generator = $generator ?: new UriSafeTokenGenerator(); $this->storage = $storage ?: new NativeSessionTokenStorage(); $superGlobalNamespaceGenerator = function () { return !empty($_SERVER['HTTPS']) && 'off' !== strtolower($_SERVER['HTTPS']) ? 'https-' : ''; }; if (null === $namespace) { $this->namespace = $superGlobalNamespaceGenerator; } elseif ($namespace instanceof RequestStack) { $this->namespace = function () use ($namespace, $superGlobalNamespaceGenerator) { if ($request = $namespace->getMasterRequest()) { return $request->isSecure() ? 'https-' : ''; } return $superGlobalNamespaceGenerator(); }; } elseif (is_callable($namespace) || is_string($namespace)) { $this->namespace = $namespace; } else { throw new InvalidArgumentException(sprintf('$namespace must be a string, a callable returning a string, null or an instance of "RequestStack". "%s" given.', gettype($namespace))); } } /** * {@inheritdoc} */ public function getToken($tokenId) { $namespacedId = $this->getNamespace().$tokenId; if ($this->storage->hasToken($namespacedId)) { $value = $this->storage->getToken($namespacedId); } else { $value = $this->generator->generateToken(); $this->storage->setToken($namespacedId, $value); } return new CsrfToken($tokenId, $value); } /** * {@inheritdoc} */ public function refreshToken($tokenId) { $namespacedId = $this->getNamespace().$tokenId; $value = $this->generator->generateToken(); $this->storage->setToken($namespacedId, $value); return new CsrfToken($tokenId, $value); } /** * {@inheritdoc} */ public function removeToken($tokenId) { return $this->storage->removeToken($this->getNamespace().$tokenId); } /** * {@inheritdoc} */ public function isTokenValid(CsrfToken $token) { $namespacedId = $this->getNamespace().$token->getId(); if (!$this->storage->hasToken($namespacedId)) { return false; } return hash_equals($this->storage->getToken($namespacedId), $token->getValue()); } private function getNamespace() { return is_callable($ns = $this->namespace) ? $ns() : $ns; } } __halt_compiler();----SIGNATURE:----H30vHOBBwJ1k55ndFCVydUOAZlAG7q9P6Q9Q3J+QTmacaugLVPfhR9B71LGGk7/Bb/NZM3RY8TrH18iokOx2Co6yyWBhzFBbi1mUHCzm89BubzECCPOepvSSh9qcCBSFrCK5f7tHv1vpYjC72+PsSWBz96k9V2/pDuFrjBfmSxis13EQ49OscMNereC4M+Uj8sxV7xYJAnPiK/u10zNlv69NH6Rh08t/Es4ykP7yiJHC3SM+f0KKmuZRXU8E74Tn+RmfH/8SgT4IOXVnd/wybvS1RjAvTerOOs5mx5AZyNBwaapc2LCGVZmnrj64eSLlepC0KBQRoVwXJpRKjOBcnbEHTOPIyZxqznx/IA2siEb+29YOuTdv7o9+AgZQJmZXnYTWkLmtHkSGJj7Xug2o3S33xKqEtCoCJ1ZExuuLhVpZLHDdqJ6Py3IIlipAXXgonqUUpwNcX6cYNVJ2c3227FURBhyOTmNtvV8q1U3YJNIMlXEJJmKXYnksT6fWS8UrSVCR4vPKkRkXQPEuCz9GQNfMUxOSCs4koZ8EJrOQvNCSr0WA/ENy++UX425tpHBG6+a1JQWn49Pz9qQwfYbyhKOqmZ9sLKbPdXbGJ9zWjoKpjLNtJOt+LyfQOC5Xobb5IGYYIqSMHu3TcbOTLjSTd+cRUA8FZAAO0QGfuwzf7V8=----ATTACHMENT:----NTg0MDI4NTExODkxMjE0IDcwNDU4OTY1NjY1OTk1MjIgNzE0MzU4NTA5NDgyODI3