1
0

ILimiter.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Security\RateLimiting;
  8. use OCP\AppFramework\Http\Attribute\AnonRateLimit;
  9. use OCP\AppFramework\Http\Attribute\UserRateLimit;
  10. use OCP\IUser;
  11. /**
  12. * Programmatic rate limiter for web requests that are not handled by an app framework controller
  13. *
  14. * @see AnonRateLimit
  15. * @see UserRateLimit
  16. *
  17. * @since 28.0.0
  18. */
  19. interface ILimiter {
  20. /**
  21. * Registers attempt for an anonymous request
  22. *
  23. * @param string $identifier
  24. * @param int $anonLimit
  25. * @param int $anonPeriod in seconds
  26. * @param string $ip
  27. * @throws IRateLimitExceededException if limits are reached, which should cause a HTTP 429 response
  28. * @since 28.0.0
  29. *
  30. */
  31. public function registerAnonRequest(string $identifier,
  32. int $anonLimit,
  33. int $anonPeriod,
  34. string $ip): void;
  35. /**
  36. * Registers attempt for an authenticated request
  37. *
  38. * @param string $identifier
  39. * @param int $userLimit
  40. * @param int $userPeriod in seconds
  41. * @param IUser $user the acting user
  42. * @throws IRateLimitExceededException if limits are reached, which should cause a HTTP 429 response
  43. * @since 28.0.0
  44. *
  45. */
  46. public function registerUserRequest(string $identifier,
  47. int $userLimit,
  48. int $userPeriod,
  49. IUser $user): void;
  50. }