/** * Determines the action method and assures that the method exists. * * @return string The action method name * @throws \TYPO3\FLOW3\Mvc\Exception\NoSuchActionException if the action specified in the request object does not exist (and if there's no default action either). */ protected function resolveActionMethodName() { if ($this->request->getControllerActionName() === 'index') { $actionName = 'index'; switch ($this->request->getHttpRequest()->getMethod()) { case 'HEAD': case 'GET': $actionName = $this->request->hasArgument($this->resourceArgumentName) ? 'show' : 'list'; break; case 'POST': $actionName = 'create'; break; case 'PUT': if (!$this->request->hasArgument($this->resourceArgumentName)) { $this->throwStatus(400, NULL, 'No resource specified'); } $actionName = 'update'; break; case 'DELETE': if (!$this->request->hasArgument($this->resourceArgumentName)) { $this->throwStatus(400, NULL, 'No resource specified'); } $actionName = 'delete'; break; } $this->request->setControllerActionName($actionName); } return parent::resolveActionMethodName(); }
/** * @test */ public function getHttpRequestReturnsTheHttpRequestWhichIsTheRootOfAllActionRequests() { $httpRequest = HttpRequest::create(new Uri('http://robertlemke.com/blog')); $actionRequest = new ActionRequest($httpRequest); $anotherActionRequest = new ActionRequest($actionRequest); $yetAnotherActionRequest = new ActionRequest($anotherActionRequest); $this->assertSame($httpRequest, $actionRequest->getHttpRequest()); $this->assertSame($httpRequest, $yetAnotherActionRequest->getHttpRequest()); $this->assertSame($httpRequest, $anotherActionRequest->getHttpRequest()); }
/** * Updates the password credential from the POST vars, if the POST parameters * are available. Sets the authentication status to AUTHENTICATION_NEEDED, if credentials have been sent. * * Note: You need to send the password in this POST parameter: * __authentication[TYPO3][FLOW3][Security][Authentication][Token][PasswordToken][password] * * @param \TYPO3\FLOW3\Mvc\ActionRequest $actionRequest The current action request * @return void */ public function updateCredentials(\TYPO3\FLOW3\Mvc\ActionRequest $actionRequest) { if ($actionRequest->getHttpRequest()->getMethod() !== 'POST') { return; } $postArguments = $actionRequest->getInternalArguments(); $password = \TYPO3\FLOW3\Reflection\ObjectAccess::getPropertyPath($postArguments, '__authentication.TYPO3.FLOW3.Security.Authentication.Token.PasswordToken.password'); if (!empty($password)) { $this->credentials['password'] = $password; $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * Updates the username and password credentials from the HTTP authorization header. * Sets the authentication status to AUTHENTICATION_NEEDED, if the header has been * sent, to NO_CREDENTIALS_GIVEN if no authorization header was there. * * @param \TYPO3\FLOW3\Mvc\ActionRequest $actionRequest The current action request instance * @return void */ public function updateCredentials(\TYPO3\FLOW3\Mvc\ActionRequest $actionRequest) { $authorizationHeader = $actionRequest->getHttpRequest()->getHeaders()->get('Authorization'); if (substr($authorizationHeader, 0, 5) === 'Basic') { $credentials = base64_decode(substr($authorizationHeader, 6)); $this->credentials['username'] = substr($credentials, 0, strpos($credentials, ':')); $this->credentials['password'] = substr($credentials, strpos($credentials, ':') + 1); $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } else { $this->credentials = array('username' => NULL, 'password' => NULL); $this->authenticationStatus = self::NO_CREDENTIALS_GIVEN; } }
/** * Builds the URI * * @param array $arguments optional URI arguments. Will be merged with $this->arguments with precedence to $arguments * @return string The URI * @api */ public function build(array $arguments = array()) { $arguments = Arrays::arrayMergeRecursiveOverrule($this->arguments, $arguments); $this->mergeArgumentsWithRequestArguments($arguments); $uri = $this->router->resolve($arguments); $this->lastArguments = $arguments; if (!$this->environment->isRewriteEnabled()) { $uri = 'index.php/' . $uri; } if ($this->createAbsoluteUri === TRUE) { $uri = $this->request->getHttpRequest()->getBaseUri() . $uri; } if ($this->section !== '') { $uri .= '#' . $this->section; } return $uri; }