diff --git a/apps/dav/lib/Connector/LegacyPublicAuth.php b/apps/dav/lib/Connector/LegacyPublicAuth.php index 37695229f0f63..0aa77993a7785 100644 --- a/apps/dav/lib/Connector/LegacyPublicAuth.php +++ b/apps/dav/lib/Connector/LegacyPublicAuth.php @@ -67,7 +67,7 @@ protected function validateUserPass($username, $password) { \OC_User::setIncognitoMode(true); // check if the share is password protected - if ($share->getPassword() !== null) { + if ($share->isPasswordProtected()) { if ($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL || $share->getShareType() === IShare::TYPE_CIRCLE) { diff --git a/apps/dav/lib/Connector/Sabre/PublicAuth.php b/apps/dav/lib/Connector/Sabre/PublicAuth.php index 4f41b95c220af..9548050374f5d 100644 --- a/apps/dav/lib/Connector/Sabre/PublicAuth.php +++ b/apps/dav/lib/Connector/Sabre/PublicAuth.php @@ -63,7 +63,7 @@ public function check(RequestInterface $request, ResponseInterface $response): a try { $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), self::BRUTEFORCE_ACTION); - if (count($_COOKIE) > 0 && !$this->request->passesStrictCookieCheck() && $this->getShare()->getPassword() !== null) { + if (count($_COOKIE) > 0 && !$this->request->passesStrictCookieCheck() && $this->getShare()->isPasswordProtected()) { throw new PreconditionFailed('Strict cookie check failed'); } @@ -142,7 +142,7 @@ private function checkToken(): array { } // If the share is protected but user is not authenticated - if ($share->getPassword() !== null) { + if ($share->isPasswordProtected()) { $this->throttler->registerAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress()); throw new NotAuthenticated(); } @@ -176,7 +176,7 @@ protected function validateUserPass($username, $password) { \OC_User::setIncognitoMode(true); // check if the share is password protected - if ($share->getPassword() !== null) { + if ($share->isPasswordProtected()) { if ($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL || $share->getShareType() === IShare::TYPE_CIRCLE) { diff --git a/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php b/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php index ceac2388f7b24..ac5b5f4ec055f 100644 --- a/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php +++ b/apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php @@ -98,8 +98,7 @@ public function createFederatedShare($shareWith, $token, $password = '') { $authenticated = in_array($share->getId(), $allowedShareIds) || $this->shareManager->checkPassword($share, $password); - $storedPassword = $share->getPassword(); - if (!empty($storedPassword) && !$authenticated) { + if ($share->isPasswordProtected() && !$authenticated) { $response = new JSONResponse( ['message' => 'No permission to access the share'], Http::STATUS_BAD_REQUEST diff --git a/apps/files_sharing/lib/Controller/PublicPreviewController.php b/apps/files_sharing/lib/Controller/PublicPreviewController.php index 24a537e110d1d..f4015a02f4a43 100644 --- a/apps/files_sharing/lib/Controller/PublicPreviewController.php +++ b/apps/files_sharing/lib/Controller/PublicPreviewController.php @@ -1,7 +1,7 @@ share->getPassword() !== null; + return $this->share->isPasswordProtected(); } /** @@ -181,7 +181,7 @@ public function directLink(string $token) { } // Password protected shares have no direct link! - if ($share->getPassword() !== null) { + if ($share->isPasswordProtected()) { return new DataResponse([], Http::STATUS_FORBIDDEN); } diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index fe4b132392fdd..9fd7a0b6a5a20 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -1,7 +1,7 @@ share->getPassword() !== null; + return $this->share->isPasswordProtected(); } #[\Override] diff --git a/apps/files_sharing/lib/Controller/ShareInfoController.php b/apps/files_sharing/lib/Controller/ShareInfoController.php index e7e42e8b6c771..3a5fa771984c2 100644 --- a/apps/files_sharing/lib/Controller/ShareInfoController.php +++ b/apps/files_sharing/lib/Controller/ShareInfoController.php @@ -1,7 +1,7 @@ getPassword() && !$this->shareManager->checkPassword($share, $password)) { + if ($share->isPasswordProtected() && !$this->shareManager->checkPassword($share, $password)) { $response = new JSONResponse([], Http::STATUS_FORBIDDEN); $response->throttle(['token' => $t]); return $response; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index cbff1f1a4750c..cc59c15ee7300 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1,7 +1,7 @@ getPassword() === null) { + // if the share is not password protected, there is nothing to check + if (!$share->isPasswordProtected()) { return false; } diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index a89cbc458a343..3f8d3d97b21ef 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -1,7 +1,7 @@ password; } + /** + * @inheritdoc + */ + #[\Override] + public function isPasswordProtected(): bool { + return $this->password !== '' && $this->password !== null; + } + /** * @inheritdoc */ diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 16fcd3f9f0010..1323299bc5137 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -1,7 +1,7 @@ createMock(IShare::class); $share->method('getShareType')->willReturn(IShare::TYPE_LINK); $share->method('getPassword')->willReturn('passwordHash'); + $share->method('isPasswordProtected')->willReturn(true); $this->hasher->method('verify')->with('password', 'passwordHash', '')->willReturn(true);