aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-08-28 15:50:45 +0200
committerJoas Schilling <coding@schilljs.com>2023-08-28 15:50:45 +0200
commit25309bcb45232bf30fe719bac1776f0136f7cd7a (patch)
tree7cfa6dacd42f22a854b895c2ae5853ff1725d96b
parentac3d7e3a7e9848c5e134b79f481d73416cc810f4 (diff)
downloadnextcloud-server-25309bcb45232bf30fe719bac1776f0136f7cd7a.tar.gz
nextcloud-server-25309bcb45232bf30fe719bac1776f0136f7cd7a.zip
techdebt(DI): Use public IThrottler interface which exists since Nextcloud 25
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--apps/dav/lib/Connector/PublicAuth.php6
-rw-r--r--apps/dav/lib/Connector/Sabre/Auth.php6
-rw-r--r--apps/dav/lib/Direct/DirectHome.php8
-rw-r--r--apps/dav/lib/Direct/ServerFactory.php5
-rw-r--r--apps/dav/tests/unit/Connector/PublicAuthTest.php6
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/AuthTest.php6
-rw-r--r--apps/dav/tests/unit/Direct/DirectHomeTest.php6
-rw-r--r--apps/oauth2/lib/Controller/OauthApiController.php4
-rw-r--r--apps/oauth2/tests/Controller/OauthApiControllerTest.php6
-rw-r--r--core/Controller/LoginController.php4
-rw-r--r--lib/base.php5
-rw-r--r--lib/private/AppFramework/DependencyInjection/DIContainer.php7
-rw-r--r--lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php6
-rw-r--r--lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php4
-rw-r--r--lib/private/AppFramework/Middleware/Security/CORSMiddleware.php12
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/private/User/Session.php8
-rw-r--r--tests/Core/Controller/LoginControllerTest.php6
-rw-r--r--tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php6
-rw-r--r--tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php6
-rw-r--r--tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php9
-rw-r--r--tests/lib/User/SessionTest.php6
22 files changed, 67 insertions, 67 deletions
diff --git a/apps/dav/lib/Connector/PublicAuth.php b/apps/dav/lib/Connector/PublicAuth.php
index cc51a249e75..6f58e89f1c0 100644
--- a/apps/dav/lib/Connector/PublicAuth.php
+++ b/apps/dav/lib/Connector/PublicAuth.php
@@ -29,9 +29,9 @@
*/
namespace OCA\DAV\Connector;
-use OC\Security\Bruteforce\Throttler;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
@@ -48,12 +48,12 @@ class PublicAuth extends AbstractBasic {
private IManager $shareManager;
private ISession $session;
private IRequest $request;
- private Throttler $throttler;
+ private IThrottler $throttler;
public function __construct(IRequest $request,
IManager $shareManager,
ISession $session,
- Throttler $throttler) {
+ IThrottler $throttler) {
$this->request = $request;
$this->shareManager = $shareManager;
$this->session = $session;
diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php
index 75e3f61fded..29e39349704 100644
--- a/apps/dav/lib/Connector/Sabre/Auth.php
+++ b/apps/dav/lib/Connector/Sabre/Auth.php
@@ -36,12 +36,12 @@ namespace OCA\DAV\Connector\Sabre;
use Exception;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\Bruteforce\MaxDelayReached;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Auth\Backend\AbstractBasic;
@@ -58,13 +58,13 @@ class Auth extends AbstractBasic {
private IRequest $request;
private ?string $currentUser = null;
private Manager $twoFactorManager;
- private Throttler $throttler;
+ private IThrottler $throttler;
public function __construct(ISession $session,
Session $userSession,
IRequest $request,
Manager $twoFactorManager,
- Throttler $throttler,
+ IThrottler $throttler,
string $principalPrefix = 'principals/users/') {
$this->session = $session;
$this->userSession = $userSession;
diff --git a/apps/dav/lib/Direct/DirectHome.php b/apps/dav/lib/Direct/DirectHome.php
index 5453a61ed46..8fc8b555db5 100644
--- a/apps/dav/lib/Direct/DirectHome.php
+++ b/apps/dav/lib/Direct/DirectHome.php
@@ -26,13 +26,13 @@ declare(strict_types=1);
*/
namespace OCA\DAV\Direct;
-use OC\Security\Bruteforce\Throttler;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
@@ -49,18 +49,20 @@ class DirectHome implements ICollection {
/** @var ITimeFactory */
private $timeFactory;
- /** @var Throttler */
+ /** @var IThrottler */
private $throttler;
/** @var IRequest */
private $request;
+
+ /** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(
IRootFolder $rootFolder,
DirectMapper $mapper,
ITimeFactory $timeFactory,
- Throttler $throttler,
+ IThrottler $throttler,
IRequest $request,
IEventDispatcher $eventDispatcher
) {
diff --git a/apps/dav/lib/Direct/ServerFactory.php b/apps/dav/lib/Direct/ServerFactory.php
index 05587ab4c2c..ce689b1e88e 100644
--- a/apps/dav/lib/Direct/ServerFactory.php
+++ b/apps/dav/lib/Direct/ServerFactory.php
@@ -27,7 +27,6 @@ declare(strict_types=1);
*/
namespace OCA\DAV\Direct;
-use OC\Security\Bruteforce\Throttler;
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -37,12 +36,14 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\L10N\IFactory;
+use OCP\Security\Bruteforce\IThrottler;
class ServerFactory {
/** @var IConfig */
private $config;
/** @var IL10N */
private $l10n;
+ /** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) {
@@ -56,7 +57,7 @@ class ServerFactory {
IRootFolder $rootFolder,
DirectMapper $mapper,
ITimeFactory $timeFactory,
- Throttler $throttler,
+ IThrottler $throttler,
IRequest $request): Server {
$home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher);
$server = new Server($home);
diff --git a/apps/dav/tests/unit/Connector/PublicAuthTest.php b/apps/dav/tests/unit/Connector/PublicAuthTest.php
index bbb391c8f28..25cad495ce9 100644
--- a/apps/dav/tests/unit/Connector/PublicAuthTest.php
+++ b/apps/dav/tests/unit/Connector/PublicAuthTest.php
@@ -26,9 +26,9 @@
*/
namespace OCA\DAV\Tests\unit\Connector;
-use OC\Security\Bruteforce\Throttler;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
@@ -50,7 +50,7 @@ class PublicAuthTest extends \Test\TestCase {
private $shareManager;
/** @var \OCA\DAV\Connector\PublicAuth */
private $auth;
- /** @var Throttler|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;
/** @var string */
@@ -68,7 +68,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->shareManager = $this->getMockBuilder(IManager::class)
->disableOriginalConstructor()
->getMock();
- $this->throttler = $this->getMockBuilder(Throttler::class)
+ $this->throttler = $this->getMockBuilder(IThrottler::class)
->disableOriginalConstructor()
->getMock();
diff --git a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
index b3b3341240a..06559261f3c 100644
--- a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
@@ -30,11 +30,11 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OC\Authentication\TwoFactorAuth\Manager;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
+use OCP\Security\Bruteforce\IThrottler;
use Sabre\DAV\Server;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
@@ -57,7 +57,7 @@ class AuthTest extends TestCase {
private $request;
/** @var Manager */
private $twoFactorManager;
- /** @var Throttler */
+ /** @var IThrottler */
private $throttler;
protected function setUp(): void {
@@ -71,7 +71,7 @@ class AuthTest extends TestCase {
$this->twoFactorManager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
- $this->throttler = $this->getMockBuilder(Throttler::class)
+ $this->throttler = $this->getMockBuilder(IThrottler::class)
->disableOriginalConstructor()
->getMock();
$this->auth = new \OCA\DAV\Connector\Sabre\Auth(
diff --git a/apps/dav/tests/unit/Direct/DirectHomeTest.php b/apps/dav/tests/unit/Direct/DirectHomeTest.php
index 01214b3c48b..0d0203509ff 100644
--- a/apps/dav/tests/unit/Direct/DirectHomeTest.php
+++ b/apps/dav/tests/unit/Direct/DirectHomeTest.php
@@ -27,7 +27,6 @@ declare(strict_types=1);
*/
namespace OCA\DAV\Tests\Unit\Direct;
-use OC\Security\Bruteforce\Throttler;
use OCA\DAV\Db\Direct;
use OCA\DAV\Db\DirectMapper;
use OCA\DAV\Direct\DirectFile;
@@ -37,6 +36,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
@@ -53,7 +53,7 @@ class DirectHomeTest extends TestCase {
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;
- /** @var Throttler|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;
/** @var IRequest */
@@ -71,7 +71,7 @@ class DirectHomeTest extends TestCase {
$this->directMapper = $this->createMock(DirectMapper::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->request = $this->createMock(IRequest::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
diff --git a/apps/oauth2/lib/Controller/OauthApiController.php b/apps/oauth2/lib/Controller/OauthApiController.php
index 8cdd8132441..af1205be0d7 100644
--- a/apps/oauth2/lib/Controller/OauthApiController.php
+++ b/apps/oauth2/lib/Controller/OauthApiController.php
@@ -31,7 +31,6 @@ namespace OCA\OAuth2\Controller;
use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider as TokenProvider;
-use OC\Security\Bruteforce\Throttler;
use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\ClientMapper;
use OCA\OAuth2\Exceptions\AccessTokenNotFoundException;
@@ -41,6 +40,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
@@ -57,7 +57,7 @@ class OauthApiController extends Controller {
private ISecureRandom $secureRandom,
private ITimeFactory $time,
private LoggerInterface $logger,
- private Throttler $throttler
+ private IThrottler $throttler
) {
parent::__construct($appName, $request);
}
diff --git a/apps/oauth2/tests/Controller/OauthApiControllerTest.php b/apps/oauth2/tests/Controller/OauthApiControllerTest.php
index c65302532a9..a7dc35943f0 100644
--- a/apps/oauth2/tests/Controller/OauthApiControllerTest.php
+++ b/apps/oauth2/tests/Controller/OauthApiControllerTest.php
@@ -29,7 +29,6 @@ use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\IProvider as TokenProvider;
use OC\Authentication\Token\PublicKeyToken;
-use OC\Security\Bruteforce\Throttler;
use OCA\OAuth2\Controller\OauthApiController;
use OCA\OAuth2\Db\AccessToken;
use OCA\OAuth2\Db\AccessTokenMapper;
@@ -41,6 +40,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
@@ -66,7 +66,7 @@ class OauthApiControllerTest extends TestCase {
private $secureRandom;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $time;
- /** @var Throttler|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
@@ -83,7 +83,7 @@ class OauthApiControllerTest extends TestCase {
$this->tokenProvider = $this->createMock(TokenProvider::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->time = $this->createMock(ITimeFactory::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->oauthApiController = new OauthApiController(
diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php
index 5f94c8f8a32..af43f2d4c4a 100644
--- a/core/Controller/LoginController.php
+++ b/core/Controller/LoginController.php
@@ -38,7 +38,6 @@ namespace OC\Core\Controller;
use OC\Authentication\Login\Chain;
use OC\Authentication\Login\LoginData;
use OC\Authentication\WebAuthn\Manager as WebAuthnManager;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OC_App;
use OCP\AppFramework\Controller;
@@ -58,6 +57,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Util;
#[IgnoreOpenAPI]
@@ -74,7 +74,7 @@ class LoginController extends Controller {
private Session $userSession,
private IURLGenerator $urlGenerator,
private Defaults $defaults,
- private Throttler $throttler,
+ private IThrottler $throttler,
private IInitialStateService $initialStateService,
private WebAuthnManager $webAuthnManager,
private IManager $manager,
diff --git a/lib/base.php b/lib/base.php
index b328165fdfa..7153e481eda 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -74,6 +74,7 @@ use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share;
use OCP\User\Events\UserChangedEvent;
@@ -871,7 +872,7 @@ class OC {
// reset brute force delay for this IP address and username
$uid = $userSession->getUser()->getUID();
$request = Server::get(IRequest::class);
- $throttler = Server::get(\OC\Security\Bruteforce\Throttler::class);
+ $throttler = Server::get(IThrottler::class);
$throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]);
}
@@ -1149,7 +1150,7 @@ class OC {
&& $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) {
return true;
}
- if ($userSession->tryBasicAuthLogin($request, Server::get(\OC\Security\Bruteforce\Throttler::class))) {
+ if ($userSession->tryBasicAuthLogin($request, Server::get(IThrottler::class))) {
return true;
}
return false;
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 9a9740b7bcc..a012d1e8ea6 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -72,6 +72,7 @@ use OCP\IServerContainer;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
+use OCP\Security\Bruteforce\IThrottler;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@@ -233,7 +234,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$c->get(IRequest::class),
$c->get(IControllerMethodReflector::class),
$c->get(IUserSession::class),
- $c->get(OC\Security\Bruteforce\Throttler::class)
+ $c->get(IThrottler::class)
)
);
$dispatcher->registerMiddleware(
@@ -291,7 +292,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$dispatcher->registerMiddleware(
new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
$c->get(IControllerMethodReflector::class),
- $c->get(OC\Security\Bruteforce\Throttler::class),
+ $c->get(IThrottler::class),
$c->get(IRequest::class),
$c->get(LoggerInterface::class)
)
@@ -309,7 +310,7 @@ class DIContainer extends SimpleContainer implements IAppContainer {
$c->get(IRequest::class),
$c->get(ISession::class),
$c->get(\OCP\IConfig::class),
- $c->get(OC\Security\Bruteforce\Throttler::class)
+ $c->get(IThrottler::class)
)
);
$dispatcher->registerMiddleware(
diff --git a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php
index f20bd333452..7acb579938b 100644
--- a/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php
+++ b/lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php
@@ -24,7 +24,6 @@
namespace OC\AppFramework\Middleware\PublicShare;
use OC\AppFramework\Middleware\PublicShare\Exceptions\NeedAuthenticationException;
-use OC\Security\Bruteforce\Throttler;
use OCP\AppFramework\AuthPublicShareController;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Middleware;
@@ -33,6 +32,7 @@ use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
+use OCP\Security\Bruteforce\IThrottler;
class PublicShareMiddleware extends Middleware {
/** @var IRequest */
@@ -44,10 +44,10 @@ class PublicShareMiddleware extends Middleware {
/** @var IConfig */
private $config;
- /** @var Throttler */
+ /** @var IThrottler */
private $throttler;
- public function __construct(IRequest $request, ISession $session, IConfig $config, Throttler $throttler) {
+ public function __construct(IRequest $request, ISession $session, IConfig $config, IThrottler $throttler) {
$this->request = $request;
$this->session = $session;
$this->config = $config;
diff --git a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php
index a0b915588ad..574e86a9ca2 100644
--- a/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php
@@ -29,7 +29,6 @@ declare(strict_types=1);
namespace OC\AppFramework\Middleware\Security;
use OC\AppFramework\Utility\ControllerMethodReflector;
-use OC\Security\Bruteforce\Throttler;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
@@ -39,6 +38,7 @@ use OCP\AppFramework\Middleware;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\Bruteforce\MaxDelayReached;
use Psr\Log\LoggerInterface;
use ReflectionMethod;
@@ -55,7 +55,7 @@ class BruteForceMiddleware extends Middleware {
public function __construct(
protected ControllerMethodReflector $reflector,
- protected Throttler $throttler,
+ protected IThrottler $throttler,
protected IRequest $request,
protected LoggerInterface $logger,
) {
diff --git a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
index e177a612d96..8bdacf550b6 100644
--- a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
@@ -29,7 +29,6 @@ namespace OC\AppFramework\Middleware\Security;
use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;
use OC\AppFramework\Utility\ControllerMethodReflector;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
@@ -39,6 +38,7 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use ReflectionMethod;
/**
@@ -54,19 +54,13 @@ class CORSMiddleware extends Middleware {
private $reflector;
/** @var Session */
private $session;
- /** @var Throttler */
+ /** @var IThrottler */
private $throttler;
- /**
- * @param IRequest $request
- * @param ControllerMethodReflector $reflector
- * @param Session $session
- * @param Throttler $throttler
- */
public function __construct(IRequest $request,
ControllerMethodReflector $reflector,
Session $session,
- Throttler $throttler) {
+ IThrottler $throttler) {
$this->request = $request;
$this->reflector = $reflector;
$this->session = $session;
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 7a2987759a4..e8ade23d8fe 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -2106,7 +2106,7 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return Throttler
+ * @return IThrottler
* @deprecated 20.0.0
*/
public function getBruteForceThrottler() {
diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php
index e7075bce47a..82887f8d029 100644
--- a/lib/private/User/Session.php
+++ b/lib/private/User/Session.php
@@ -419,7 +419,7 @@ class Session implements IUserSession, Emitter {
* @param string $user
* @param string $password
* @param IRequest $request
- * @param OC\Security\Bruteforce\Throttler $throttler
+ * @param IThrottler $throttler
* @throws LoginException
* @throws PasswordLoginForbiddenException
* @return boolean
@@ -427,7 +427,7 @@ class Session implements IUserSession, Emitter {
public function logClientIn($user,
$password,
IRequest $request,
- OC\Security\Bruteforce\Throttler $throttler) {
+ IThrottler $throttler) {
$remoteAddress = $request->getRemoteAddress();
$currentDelay = $throttler->sleepDelayOrThrowOnMax($remoteAddress, 'login');
@@ -572,11 +572,11 @@ class Session implements IUserSession, Emitter {
*
* @todo do not allow basic auth if the user is 2FA enforced
* @param IRequest $request
- * @param OC\Security\Bruteforce\Throttler $throttler
+ * @param IThrottler $throttler
* @return boolean if the login was successful
*/
public function tryBasicAuthLogin(IRequest $request,
- OC\Security\Bruteforce\Throttler $throttler) {
+ IThrottler $throttler) {
if (!empty($request->server['PHP_AUTH_USER']) && !empty($request->server['PHP_AUTH_PW'])) {
try {
if ($this->logClientIn($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW'], $request, $throttler)) {
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php
index 6044440bdaf..333baf0aa86 100644
--- a/tests/Core/Controller/LoginControllerTest.php
+++ b/tests/Core/Controller/LoginControllerTest.php
@@ -29,7 +29,6 @@ use OC\Authentication\Login\LoginData;
use OC\Authentication\Login\LoginResult;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Core\Controller\LoginController;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
@@ -43,6 +42,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager;
+use OCP\Security\Bruteforce\IThrottler;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -74,7 +74,7 @@ class LoginControllerTest extends TestCase {
/** @var Defaults|MockObject */
private $defaults;
- /** @var Throttler|MockObject */
+ /** @var IThrottler|MockObject */
private $throttler;
/** @var IInitialStateService|MockObject */
@@ -99,7 +99,7 @@ class LoginControllerTest extends TestCase {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->twoFactorManager = $this->createMock(Manager::class);
$this->defaults = $this->createMock(Defaults::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->initialStateService = $this->createMock(IInitialStateService::class);
$this->webAuthnManager = $this->createMock(\OC\Authentication\WebAuthn\Manager::class);
$this->notificationManager = $this->createMock(IManager::class);
diff --git a/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php b/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
index 3e48078cbad..a025f39419a 100644
--- a/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/PublicShare/PublicShareMiddlewareTest.php
@@ -25,7 +25,6 @@ namespace Test\AppFramework\Middleware\PublicShare;
use OC\AppFramework\Middleware\PublicShare\Exceptions\NeedAuthenticationException;
use OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware;
-use OC\Security\Bruteforce\Throttler;
use OCP\AppFramework\AuthPublicShareController;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\NotFoundResponse;
@@ -36,6 +35,7 @@ use OCP\IConfig;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
+use OCP\Security\Bruteforce\IThrottler;
class PublicShareMiddlewareTest extends \Test\TestCase {
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
@@ -44,7 +44,7 @@ class PublicShareMiddlewareTest extends \Test\TestCase {
private $session;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;
/** @var PublicShareMiddleware */
@@ -57,7 +57,7 @@ class PublicShareMiddlewareTest extends \Test\TestCase {
$this->request = $this->createMock(IRequest::class);
$this->session = $this->createMock(ISession::class);
$this->config = $this->createMock(IConfig::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->middleware = new PublicShareMiddleware(
$this->request,
diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
index faf2d24d172..0492d5f7fcf 100644
--- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
@@ -24,11 +24,11 @@ namespace Test\AppFramework\Middleware\Security;
use OC\AppFramework\Middleware\Security\BruteForceMiddleware;
use OC\AppFramework\Utility\ControllerMethodReflector;
-use OC\Security\Bruteforce\Throttler;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;
+use OCP\Security\Bruteforce\IThrottler;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -55,7 +55,7 @@ class TestController extends Controller {
class BruteForceMiddlewareTest extends TestCase {
/** @var ControllerMethodReflector */
private $reflector;
- /** @var Throttler|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
private $throttler;
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
private $request;
@@ -67,7 +67,7 @@ class BruteForceMiddlewareTest extends TestCase {
parent::setUp();
$this->reflector = new ControllerMethodReflector();
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->request = $this->createMock(IRequest::class);
$this->logger = $this->createMock(LoggerInterface::class);
diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
index 7c48f7e2712..80c2ed84451 100644
--- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php
@@ -15,21 +15,22 @@ use OC\AppFramework\Http\Request;
use OC\AppFramework\Middleware\Security\CORSMiddleware;
use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;
use OC\AppFramework\Utility\ControllerMethodReflector;
-use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IRequestId;
+use OCP\Security\Bruteforce\IThrottler;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\AppFramework\Middleware\Security\Mock\CORSMiddlewareController;
class CORSMiddlewareTest extends \Test\TestCase {
/** @var ControllerMethodReflector */
private $reflector;
- /** @var Session|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Session|MockObject */
private $session;
- /** @var Throttler */
+ /** @var IThrottler|MockObject */
private $throttler;
/** @var CORSMiddlewareController */
private $controller;
@@ -38,7 +39,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
parent::setUp();
$this->reflector = new ControllerMethodReflector();
$this->session = $this->createMock(Session::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->controller = new CORSMiddlewareController(
'test',
$this->createMock(IRequest::class)
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 598a8b6e061..b6ac7a69fed 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -14,7 +14,6 @@ use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
-use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory;
use OC\User\LoginException;
use OC\User\Manager;
@@ -30,6 +29,7 @@ use OCP\IRequestId;
use OCP\ISession;
use OCP\IUser;
use OCP\Lockdown\ILockdownManager;
+use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ISecureRandom;
use OCP\User\Events\PostLoginEvent;
use PHPUnit\Framework\MockObject\MockObject;
@@ -47,7 +47,7 @@ class SessionTest extends \Test\TestCase {
private $tokenProvider;
/** @var IConfig|MockObject */
private $config;
- /** @var Throttler|MockObject */
+ /** @var IThrottler|MockObject */
private $throttler;
/** @var ISecureRandom|MockObject */
private $random;
@@ -73,7 +73,7 @@ class SessionTest extends \Test\TestCase {
->willReturn(10000);
$this->tokenProvider = $this->createMock(IProvider::class);
$this->config = $this->createMock(IConfig::class);
- $this->throttler = $this->createMock(Throttler::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->manager = $this->createMock(Manager::class);
$this->session = $this->createMock(ISession::class);