protected function getDestinationPath(Uri $baseUri, HttpRequest $request) { if (!$request->hasHeader('Destination')) { throw new BadRequestException(); } $dest = $request->getHeader('Destination'); if (preg_match("'^(?:https?:)?//'i", $dest)) { try { $uri = new Uri($dest); } catch (\Exception $e) { throw new BadRequestException($e); } if (0 !== strpos((string) $uri, rtrim($baseUri, '/') . '/')) { throw new WebDavException(WebDav::CODE_BAD_GATEWAY); } return Uri::decode(substr($uri->getPath(), strlen(rtrim($baseUri->getPath(), '/') . '/'))); } if (preg_match("'^/.*'", $dest)) { $path = '/' . trim($dest, '/'); $base = rtrim('/' . $baseUri->getPath(), '/') . '/'; if (0 !== strpos($path, $base)) { throw new WebDavException(WebDav::CODE_BAD_GATEWAY); } return Uri::decode(substr($path, strlen($base))); } throw new BadRequestException(); }
/** * Get the path info of this request (that is the path starting at the base bath of the front * controller). * * @return string */ public function getPathInfo() { $path = trim($this->uri->getPath(false), '/'); if ($this->pathBase == '') { return $path; } if ($path == $this->pathBase) { return ''; } return preg_replace("'^" . preg_quote($this->pathBase, "'") . "/'i", '', $path); }
public function getResourcePath(Uri $baseUri, Uri $requestUri) { if ($this->path === '') { return ltrim(substr($requestUri->getPath(false), strlen($baseUri->getPath(false))), '/'); } if (preg_match("'^/+'", $this->path)) { return ltrim($this->path, '/'); } if (preg_match("'^https?://'", $this->path)) { if (0 !== strpos($this->path, $baseUri)) { throw new \InvalidArgumentException(sprintf('URI does not refer to this WebDAV share: "%s"', $this->path)); } return Uri::decode(trim(substr($this->path, strlen($baseUri)), '/')); } throw new \InvalidArgumentException(sprintf('Unprocessable tag in list: "%s"', $this->path)); }
/** * {@inheritdoc} */ public function startAuthentication(TokenInterface $token, HttpRequest $request, HttpResponse $response) { if (!$token instanceof FormAuthToken) { throw new SecurityException(sprintf('Invalid token %s passed to %s', get_class($token), get_class($this))); } $loginUri = new Uri($this->auth->getLoginUri()); $path = trim($request->getUri()->getPath(false), '/'); $loginPath = trim($loginUri->getPath(false), '/'); $session = $this->securityContext->getSession(); $data = (array) $session->get($this->auth->getKey(), NULL); // Save the current URI when it is not the login URI. if ($path !== $loginPath && !array_key_exists(FormAuthenticationProvider::SESSION_URI, $data)) { $data[FormAuthenticationProvider::SESSION_URI] = (string) $request->getUri(); } $session->set($this->auth->getKey(), $data); $response->setStatus(Http::REDIRECT_TEMPORARY); $response->setReason(Http::getReason(Http::REDIRECT_TEMPORARY)); $response->setHeader('Location', $loginUri); }