2017-07-12 15:46:25 -04:00
|
|
|
<?php
|
2021-04-19 09:50:30 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-07-12 15:46:25 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-07-12 15:46:25 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Security\Bruteforce;
|
|
|
|
|
|
2022-04-05 12:32:46 -04:00
|
|
|
use OCP\Capabilities\IInitialStateExcludedCapability;
|
2017-07-12 15:46:25 -04:00
|
|
|
use OCP\Capabilities\IPublicCapability;
|
|
|
|
|
use OCP\IRequest;
|
2023-08-16 11:40:38 -04:00
|
|
|
use OCP\Security\Bruteforce\IThrottler;
|
2017-07-12 15:46:25 -04:00
|
|
|
|
2022-04-05 12:32:46 -04:00
|
|
|
class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
|
2023-08-15 02:04:32 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IRequest $request,
|
2023-08-16 11:40:38 -04:00
|
|
|
private IThrottler $throttler,
|
2023-08-15 02:04:32 -04:00
|
|
|
) {
|
|
|
|
|
}
|
2017-07-12 15:46:25 -04:00
|
|
|
|
|
|
|
|
/**
|
2023-08-15 02:04:32 -04:00
|
|
|
* @return array{bruteforce: array{delay: int, allow-listed: bool}}
|
2017-07-12 15:46:25 -04:00
|
|
|
*/
|
2021-04-19 09:50:30 -04:00
|
|
|
public function getCapabilities(): array {
|
2017-07-12 15:46:25 -04:00
|
|
|
return [
|
|
|
|
|
'bruteforce' => [
|
2023-08-15 02:04:32 -04:00
|
|
|
'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()),
|
2023-08-16 11:40:38 -04:00
|
|
|
'allow-listed' => $this->throttler->isBypassListed($this->request->getRemoteAddress()),
|
2023-08-15 02:04:32 -04:00
|
|
|
],
|
2017-07-12 15:46:25 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|