aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Security/Bruteforce/Capabilities.php
blob: 581b4480a2707ded130ebf17da0bacd977e2d251 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OC\Security\Bruteforce;

use OCP\Capabilities\IInitialStateExcludedCapability;
use OCP\Capabilities\IPublicCapability;
use OCP\IRequest;
use OCP\Security\Bruteforce\IThrottler;

class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
	public function __construct(
		private IRequest $request,
		private IThrottler $throttler,
	) {
	}

	/**
	 * @return array{bruteforce: array{delay: int, allow-listed: bool}}
	 */
	public function getCapabilities(): array {
		return [
			'bruteforce' => [
				'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()),
				'allow-listed' => $this->throttler->isBypassListed($this->request->getRemoteAddress()),
			],
		];
	}
}