/** * {@inheritDoc} */ public function verify($controller) { $httpRequest = $controller->getRequest(); if (false == $httpRequest instanceof Request) { throw new InvalidArgumentException(sprintf('Invalid request given. Expected %s but it is %s', 'Zend\\Http\\Request', is_object($httpRequest) ? get_class($httpRequest) : gettype($httpRequest))); } $hash = $controller->params()->fromRoute('payum_token') ?: $httpRequest->getQuery('payum_token'); /** @var $httpRequest Request */ if (!$hash) { //TODO we should set 404 to response but I do not know how. symfony just throws not found exception. throw new InvalidArgumentException('Token parameter not set in request'); } if ($hash instanceof Token) { $token = $hash; } else { if (false == ($token = $this->tokenStorage->find($hash))) { //TODO here again should be 404 throw new InvalidArgumentException(sprintf('A token with hash `%s` could not be found.', $hash)); } if ($httpRequest->getUri()->getPath() != parse_url($token->getTargetUrl(), PHP_URL_PATH)) { //TODO here again should be 400 throw new InvalidArgumentException(sprintf('The current url %s not match target url %s set in the token.', $httpRequest->getUri()->getPath(), parse_url($token->getTargetUrl(), PHP_URL_PATH))); } } return $token; }
/** * {@inheritDoc} * * @param $request GetToken */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); if (false == ($token = $this->tokenStorage->find($request->getHash()))) { throw new LogicException(sprintf('The token %s could not be found', $request->getHash())); } $request->setToken($token); }
/** * {@inheritDoc} */ public function onPreExecute(Context $context) { $request = $context->getRequest(); if (false == $request instanceof ModelAggregateInterface) { return; } if ($request->getModel() instanceof IdentityInterface) { /** @var IdentityInterface $identity */ $identity = $request->getModel(); if (false == ($model = $this->storage->find($identity))) { return; } $request->setModel($model); } $this->scheduleForUpdateIfSupported($request->getModel()); }
/** * {@inheritDoc} */ public function verify($httpRequest) { if (false == $httpRequest instanceof Request) { throw new InvalidArgumentException(sprintf('Invalid request given. Expected %s but it is %s', 'Symfony\\Component\\HttpFoundation\\Request', is_object($httpRequest) ? get_class($httpRequest) : gettype($httpRequest))); } if (false === ($hash = $httpRequest->attributes->get('payum_token', $httpRequest->get('payum_token', false)))) { throw new NotFoundHttpException('Token parameter not set in request'); } if ($hash instanceof TokenInterface) { $token = $hash; } else { if (false == ($token = $this->tokenStorage->find($hash))) { throw new NotFoundHttpException(sprintf('A token with hash `%s` could not be found.', $hash)); } if (parse_url($httpRequest->getUri(), PHP_URL_PATH) != parse_url($token->getTargetUrl(), PHP_URL_PATH)) { throw new HttpException(400, sprintf('The current url %s not match target url %s set in the token.', $httpRequest->getUri(), $token->getTargetUrl())); } } return $token; }
/** * {@inheritDoc} */ public function verify($httpRequest) { if (false == is_array($httpRequest)) { throw new InvalidArgumentException('Invalid request given. In most cases you have to pass $_REQUEST array.'); } if (false == isset($httpRequest[$this->tokenParameter])) { throw new InvalidArgumentException(sprintf('Token parameter `%s` was not found in in the http request.', $this->tokenParameter)); } if ($httpRequest[$this->tokenParameter] instanceof TokenInterface) { return $httpRequest[$this->tokenParameter]; } if (false == ($token = $this->tokenStorage->find($httpRequest[$this->tokenParameter]))) { throw new InvalidArgumentException(sprintf('A token with hash `%s` could not be found.', $httpRequest[$this->tokenParameter])); } /** @var $token TokenInterface */ if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) != parse_url($token->getTargetUrl(), PHP_URL_PATH)) { throw new InvalidArgumentException(sprintf('The current url %s not match target url %s set in the token.', $_SERVER['REQUEST_URI'], $token->getTargetUrl())); } return $token; }