public function buildHttpRequest() { try { $method = $this->getRequestMethod(); $request = new HttpRequest($this->getRequestUri(), $method, $this->getProtocol()); $request->setRawUri($this->getRawRequestUri()); $request->setPathBase(trim($this->getBaseUri()->getPath(false), '/')); $request->setCookies($this->getCookies()); foreach ($this->getHeaders() as $name => $value) { $request->setHeader($name, $value); if ($name == 'content-type') { $mediaType = $request->getMediaType(); if ($mediaType->is(Http::FORM_ENCODED)) { if ($method != Http::METHOD_POST) { $fields = Uri::parseQuery(file_get_contents($this->getInputUrl())); $request->setEntity(new FormEntity($fields)); } else { $request->setEntity(new FormEntity($this->getPostParams())); } } elseif ($mediaType->is(Http::FORM_MULTIPART_ENCODED)) { if ($method != Http::METHOD_POST) { throw new \RuntimeException('Multipart requests must be POST'); } $request->setEntity(new MultipartFormEntity($this->getPostParams(), $this->getFiles())); } } } if (!$request->hasEntity()) { $request->setEntity(new StreamEntity(ResourceInputStream::fromUrl($this->getInputUrl()))); } } catch (BadRequestException $e) { throw $e; } catch (\Exception $e) { throw new BadRequestException($e); } return $request; }
/** * {@inheritdoc} */ public function updateCredentials(HttpRequest $request) { $this->setStatus(self::AUTHENTICATION_NEEDED); $path = trim($request->getUri()->getPath(false), '/'); $logoutPath = trim((new Uri($this->auth->getLogoutUri()))->getPath(false), '/'); if ($path === $logoutPath) { return; } $session = $this->securityContext->getSession(); if ($session->isInitialized()) { $data = (array) $session->get($this->auth->getKey(), NULL); $identity = NULL; if (isset($data[FormAuthenticationProvider::SESSION_IDENTITY])) { $identity = (string) $data[FormAuthenticationProvider::SESSION_IDENTITY]; } if ($identity !== NULL) { $principal = $this->auth->getPrincipalProvider()->findPrincipal($identity); if ($principal !== NULL) { $this->setPrincipal($principal); return $this->setStatus(self::AUTHENTICATION_SUCCESSFUL); } } } if ($request->isPost(false) && $request->getMediaType()->is(Http::FORM_ENCODED)) { $fields = $request->getEntity()->getFields(); $data = isset($fields['auth']) ? (array) $fields['auth'] : []; $data = isset($data[$this->auth->getKey()]) ? (array) $data[$this->auth->getKey()] : []; if (array_key_exists(FormAuthenticationProvider::FIELD_USERNAME, $data)) { $this->username = (string) $data[FormAuthenticationProvider::FIELD_USERNAME]; } if (array_key_exists(FormAuthenticationProvider::FIELD_PASSWORD, $data)) { $this->password = (string) $data[FormAuthenticationProvider::FIELD_PASSWORD]; } if (array_key_exists(FormAuthenticationProvider::FIELD_GUARD, $data)) { $guard = (string) $data[FormAuthenticationProvider::FIELD_GUARD]; $data = (array) $session->get($this->auth->getKey(), NULL); if (array_key_exists(FormAuthenticationProvider::SESSION_GUARD, $data)) { if ((string) $data[FormAuthenticationProvider::SESSION_GUARD] == $guard) { $this->guarded = true; } } } return $this->setStatus(self::AUTHENTICATION_NEEDED); } }