1
0

Capabilities.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
  5. * @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @author J0WI <J0WI@users.noreply.github.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OC\Security\Bruteforce;
  29. use OCP\Capabilities\IInitialStateExcludedCapability;
  30. use OCP\Capabilities\IPublicCapability;
  31. use OCP\IRequest;
  32. use OCP\Security\Bruteforce\IThrottler;
  33. class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
  34. public function __construct(
  35. private IRequest $request,
  36. private IThrottler $throttler,
  37. ) {
  38. }
  39. /**
  40. * @return array{bruteforce: array{delay: int, allow-listed: bool}}
  41. */
  42. public function getCapabilities(): array {
  43. return [
  44. 'bruteforce' => [
  45. 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()),
  46. 'allow-listed' => $this->throttler->isBypassListed($this->request->getRemoteAddress()),
  47. ],
  48. ];
  49. }
  50. }