diff options
Diffstat (limited to 'lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php')
-rw-r--r-- | lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php | 55 |
1 files changed, 16 insertions, 39 deletions
diff --git a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php index 7acb579938b..83e799e3d3b 100644 --- a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php +++ b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php @@ -1,31 +1,16 @@ <?php + /** - * @copyright Copyright (c) 2016 Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\AppFramework\Middleware\PublicShare; use OC\AppFramework\Middleware\PublicShare\Exceptions\NeedAuthenticationException; +use OCA\Files_Sharing\AppInfo\Application; use OCP\AppFramework\AuthPublicShareController; -use OCP\AppFramework\Http\NotFoundResponse; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Middleware; use OCP\AppFramework\PublicShareController; use OCP\Files\NotFoundException; @@ -35,23 +20,13 @@ use OCP\ISession; use OCP\Security\Bruteforce\IThrottler; class PublicShareMiddleware extends Middleware { - /** @var IRequest */ - private $request; - - /** @var ISession */ - private $session; - - /** @var IConfig */ - private $config; - - /** @var IThrottler */ - private $throttler; - public function __construct(IRequest $request, ISession $session, IConfig $config, IThrottler $throttler) { - $this->request = $request; - $this->session = $session; - $this->config = $config; - $this->throttler = $throttler; + public function __construct( + private IRequest $request, + private ISession $session, + private IConfig $config, + private IThrottler $throttler, + ) { } public function beforeController($controller, $methodName) { @@ -110,7 +85,9 @@ class PublicShareMiddleware extends Middleware { } if ($exception instanceof NotFoundException) { - return new NotFoundResponse(); + return new TemplateResponse(Application::APP_ID, 'sharenotfound', [ + 'message' => $exception->getMessage(), + ], 'guest', Http::STATUS_NOT_FOUND); } if ($controller instanceof AuthPublicShareController && $exception instanceof NeedAuthenticationException) { @@ -144,7 +121,7 @@ class PublicShareMiddleware extends Middleware { private function throttle($bruteforceProtectionAction, $token): void { $ip = $this->request->getRemoteAddress(); - $this->throttler->sleepDelay($ip, $bruteforceProtectionAction); + $this->throttler->sleepDelayOrThrowOnMax($ip, $bruteforceProtectionAction); $this->throttler->registerAttempt($bruteforceProtectionAction, $ip, ['token' => $token]); } } |