Capabilities.php 875 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Security\Bruteforce;
  8. use OCP\Capabilities\IInitialStateExcludedCapability;
  9. use OCP\Capabilities\IPublicCapability;
  10. use OCP\IRequest;
  11. use OCP\Security\Bruteforce\IThrottler;
  12. class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
  13. public function __construct(
  14. private IRequest $request,
  15. private IThrottler $throttler,
  16. ) {
  17. }
  18. /**
  19. * @return array{bruteforce: array{delay: int, allow-listed: bool}}
  20. */
  21. public function getCapabilities(): array {
  22. return [
  23. 'bruteforce' => [
  24. 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()),
  25. 'allow-listed' => $this->throttler->isBypassListed($this->request->getRemoteAddress()),
  26. ],
  27. ];
  28. }
  29. }