From d744699f6b26e7290bd0dfcc4c089f20fc654d68 Mon Sep 17 00:00:00 2001 From: sualko Date: Thu, 4 Jun 2020 09:52:49 +0200 Subject: [PATCH] fix: remove dependency on shares fix #20 --- lib/AppInfo/Application.php | 15 +++++++++ lib/Controller/JoinController.php | 29 ++++++----------- lib/Middleware/JoinMiddleware.php | 52 +++++++++++++++++++++++++++++++ lib/NotFoundException.php | 7 +++++ 4 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 lib/Middleware/JoinMiddleware.php create mode 100644 lib/NotFoundException.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5f262a1..9b7859a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -2,6 +2,21 @@ namespace OCA\BigBlueButton\AppInfo; +use \OCP\AppFramework\App; +use \OCA\BigBlueButton\Middleware\JoinMiddleware; + if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) { throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?'); } + +class Application extends App +{ + public function __construct(array $urlParams = []) + { + parent::__construct('bbb', $urlParams); + + $container = $this->getContainer(); + + $container->registerMiddleWare(JoinMiddleware::class); + } +} diff --git a/lib/Controller/JoinController.php b/lib/Controller/JoinController.php index e2b050d..d944b7a 100644 --- a/lib/Controller/JoinController.php +++ b/lib/Controller/JoinController.php @@ -3,18 +3,21 @@ namespace OCA\BigBlueButton\Controller; use OCA\BigBlueButton\BigBlueButton\API; use OCA\BigBlueButton\BigBlueButton\Presentation; +use OCA\BigBlueButton\NotFoundException; use OCP\AppFramework\Http\RedirectResponse; -use OCP\AppFramework\PublicShareController; use OCP\IRequest; use OCP\ISession; use OCP\IUserSession; use OCP\IConfig; -use OCP\Files\NotFoundException; use OCA\BigBlueButton\Service\RoomService; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; -class JoinController extends PublicShareController +class JoinController extends Controller { + /** @var string */ + protected $token; + /** @var RoomService */ private $service; @@ -44,37 +47,25 @@ class JoinController extends PublicShareController $this->api = $api; } - protected function getPasswordHash(): string + public function setToken(string $token) { - return ''; + $this->token = $token; } - /** - * Validate the token of this share. If the token is invalid this controller - * will return a 404. - */ public function isValidToken(): bool { - $room = $this->service->findByUid($this->getToken()); + $room = $this->service->findByUid($this->token); return $room !== null; } - /** - * Allows you to specify if this share is password protected - */ - protected function isPasswordProtected(): bool - { - return false; - } - /** * @PublicPage * @NoCSRFRequired */ public function index($displayname, $u = '', $filename = '') { - $room = $this->service->findByUid($this->getToken()); + $room = $this->service->findByUid($this->token); if ($room === null) { throw new NotFoundException(); diff --git a/lib/Middleware/JoinMiddleware.php b/lib/Middleware/JoinMiddleware.php new file mode 100644 index 0000000..bc70eb2 --- /dev/null +++ b/lib/Middleware/JoinMiddleware.php @@ -0,0 +1,52 @@ +request = $request; + } + + public function beforeController($controller, $methodName) + { + if (!($controller instanceof JoinController)) { + return; + } + + $token = $this->request->getParam('token'); + if ($token === null) { + throw new NotFoundException(); + } + + $controller->setToken($token); + + if ($controller->isValidToken()) { + return; + } + + throw new NotFoundException(); + } + + public function afterException($controller, $methodName, \Exception $exception) + { + if (!($controller instanceof JoinController)) { + throw $exception; + } + + if ($exception instanceof NotFoundException) { + return new NotFoundResponse(); + } + + throw $exception; + } +} diff --git a/lib/NotFoundException.php b/lib/NotFoundException.php new file mode 100644 index 0000000..6a40214 --- /dev/null +++ b/lib/NotFoundException.php @@ -0,0 +1,7 @@ +