diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2021-09-06 16:31:01 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2021-09-06 16:31:01 +0200 |
commit | d4f97affc1a0ecfaacfbdc26aab820cad1650a06 (patch) | |
tree | aa77abd5adf02edd735159cc3c0c07cf7fd4c847 /lib/private/Server.php | |
parent | 33a0b75c83a1c56fa84b98d3a07a26b5c4932b65 (diff) | |
download | nextcloud-server-d4f97affc1a0ecfaacfbdc26aab820cad1650a06.tar.gz nextcloud-server-d4f97affc1a0ecfaacfbdc26aab820cad1650a06.zip |
Add database ratelimiting backend
In case no distributed memory cache is specified this adds
a database backend for ratelimit purposes.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/Server.php')
-rw-r--r-- | lib/private/Server.php | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php index 0320eda2b91..83a3c905f94 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -785,10 +785,20 @@ class Server extends ServerContainer implements IServerContainer { $this->registerDeprecatedAlias('Search', ISearch::class); $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { - return new \OC\Security\RateLimiting\Backend\MemoryCache( - $this->get(ICacheFactory::class), - new \OC\AppFramework\Utility\TimeFactory() - ); + $cacheFactory = $c->get(ICacheFactory::class); + if ($cacheFactory->isAvailable()) { + $backend = new \OC\Security\RateLimiting\Backend\MemoryCache( + $this->get(ICacheFactory::class), + new \OC\AppFramework\Utility\TimeFactory() + ); + } else { + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( + $c->get(IDBConnection::class), + new \OC\AppFramework\Utility\TimeFactory() + ); + } + + return $backend; }); $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |