summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/middleware/sharingcheckmiddleware.php')
-rw-r--r--apps/files_sharing/lib/middleware/sharingcheckmiddleware.php49
1 files changed, 48 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
index 61dfd914d0b..942efc0483e 100644
--- a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
+++ b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
@@ -29,6 +29,9 @@ use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Files\NotFoundException;
use OCP\IConfig;
+use OCP\AppFramework\Utility\IControllerMethodReflector;
+use OCA\Files_Sharing\Exceptions\S2SException;
+use OCP\AppFramework\Http\JSONResponse;
/**
* Checks whether the "sharing check" is enabled
@@ -43,6 +46,8 @@ class SharingCheckMiddleware extends Middleware {
protected $config;
/** @var IAppManager */
protected $appManager;
+ /** @var IControllerMethodReflector */
+ protected $reflector;
/***
* @param string $appName
@@ -51,10 +56,13 @@ class SharingCheckMiddleware extends Middleware {
*/
public function __construct($appName,
IConfig $config,
- IAppManager $appManager) {
+ IAppManager $appManager,
+ IControllerMethodReflector $reflector
+ ) {
$this->appName = $appName;
$this->config = $config;
$this->appManager = $appManager;
+ $this->reflector = $reflector;
}
/**
@@ -68,6 +76,14 @@ class SharingCheckMiddleware extends Middleware {
if(!$this->isSharingEnabled()) {
throw new NotFoundException('Sharing is disabled.');
}
+
+ if ($controller instanceof \OCA\Files_Sharing\Controllers\ExternalSharesController &&
+ !$this->externalSharesChecks()) {
+ throw new S2SException('Federated sharing not allowed');
+ } else if ($controller instanceof \OCA\Files_Sharing\Controllers\ShareController &&
+ !$this->isLinkSharingEnabled()) {
+ throw new NotFoundException('Link sharing is disabled');
+ }
}
/**
@@ -84,10 +100,33 @@ class SharingCheckMiddleware extends Middleware {
return new NotFoundResponse();
}
+ if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) {
+ return new JSONResponse($exception->getMessage(), 405);
+ }
+
throw $exception;
}
/**
+ * Checks for externalshares controller
+ * @return bool
+ */
+ private function externalSharesChecks() {
+
+ if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') &&
+ $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') {
+ return false;
+ }
+
+ if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') &&
+ $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
* Check whether sharing is enabled
* @return bool
*/
@@ -98,6 +137,14 @@ class SharingCheckMiddleware extends Middleware {
return false;
}
+ return true;
+ }
+
+ /**
+ * Check if link sharing is allowed
+ * @return bool
+ */
+ private function isLinkSharingEnabled() {
// Check if the shareAPI is enabled
if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
return false;