/** * Authenticates the user based on the current request. * * If authentication is successful, true must be returned. * If authentication fails, an exception must be thrown. * * @param DAV\Server $server * @param string $realm * @throws DAV\Exception\NotAuthenticated * @return bool */ public function authenticate(DAV\Server $server, $realm) { $auth = new BasicAuthNoPass(); $auth->setHTTPRequest($server->httpRequest); $auth->setHTTPResponse($server->httpResponse); $auth->setRealm($realm); $userpass = $auth->getUserPass(); if (!$userpass) { $auth->requireLogin(); throw new DAV\Exception\NotAuthenticated('No basic authentication headers were found'); } // Authenticates the user $token = $userpass[0]; $shareStore = new \ShareStore(\ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER")); $shareData = $shareStore->loadShare($token); if (is_array($shareData)) { $this->shareData = $shareData; } else { $auth->requireLogin(); throw new DAV\Exception\NotAuthenticated('Username or password does not match'); } if (!$this->validateUserPass($userpass[0], $userpass[1])) { $auth->requireLogin(); throw new DAV\Exception\NotAuthenticated('Username or password does not match'); } $repositoryId = $this->shareData["REPOSITORY"]; $repository = \ConfService::getRepositoryById($repositoryId); if ($repository == null) { $repository = \ConfService::getRepositoryByAlias($repositoryId); } if ($repository == null) { throw new DAV\Exception\NotAuthenticated('Username cannot access any repository'); } else { $this->rootCollection->updateRepository($repository); } $this->currentUser = $userpass[0]; return true; }