summaryrefslogtreecommitdiffstats
path: root/lib/private/Server.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2021-09-06 16:31:01 +0200
committerLukas Reschke <lukas@statuscode.ch>2021-09-13 16:45:54 +0200
commitf416cacc64f26b88181ae6542e92ed1e5621ccd7 (patch)
treef4e9151e15c15279a6465e8e18f17d307ce3081f /lib/private/Server.php
parent7025c055e5110d46eaa00d06be378b721412744b (diff)
downloadnextcloud-server-f416cacc64f26b88181ae6542e92ed1e5621ccd7.tar.gz
nextcloud-server-f416cacc64f26b88181ae6542e92ed1e5621ccd7.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.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6a1550f83e0..d947fa6f3e9 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -782,10 +782,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\MemoryCacheBackend(
+ $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);