aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/middleware
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2015-10-02 09:57:33 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2015-10-02 12:03:53 +0200
commit3d2acb5003a4953d3f422b34f670d87c4afb11c9 (patch)
tree89ec8d0821639581110f0b73db75a89defbdbb8a /apps/files_sharing/lib/middleware
parentdc38e674a5d547e7fd53d66fb0ac0dbb5490ea77 (diff)
downloadnextcloud-server-3d2acb5003a4953d3f422b34f670d87c4afb11c9.tar.gz
nextcloud-server-3d2acb5003a4953d3f422b34f670d87c4afb11c9.zip
sharingcheckmiddleware now handles externalshares as well
Added new annotations for the externalsharescontroller class * @NoOutgoingFederatedSharingRequired * @NoIncomingFederatedSharingRequired By default both are required for all functions in the externalSharesController. A proper exception is thrown and then a 405 is returned instead of the default error page. Since it is only an API endpoint this makes more sense. Unit tests added and updated
Diffstat (limited to 'apps/files_sharing/lib/middleware')
-rw-r--r--apps/files_sharing/lib/middleware/sharingcheckmiddleware.php38
1 files changed, 35 insertions, 3 deletions
diff --git a/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php b/apps/files_sharing/lib/middleware/sharingcheckmiddleware.php
index f51399b76a8..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;
}
/**
@@ -69,8 +77,9 @@ class SharingCheckMiddleware extends Middleware {
throw new NotFoundException('Sharing is disabled.');
}
- if ($controller instanceof \OCA\Files_Sharing\Controllers\ExternalSharesController) {
- //TODO: Proper checks
+ 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');
@@ -91,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
*/