diff --git a/lib/Controller/MasterController.php b/lib/Controller/MasterController.php index bee6821..8a94492 100644 --- a/lib/Controller/MasterController.php +++ b/lib/Controller/MasterController.php @@ -1,11 +1,14 @@ * * @license GNU AGPL version 3 or any later version * + * @author Maxence Lange + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the @@ -21,18 +24,17 @@ * */ - namespace OCA\GlobalSiteSelector\Controller; use OCA\GlobalSiteSelector\AppInfo\Application; +use OCA\GlobalSiteSelector\Events\GlobalScaleMasterLogoutEvent; use OCA\GlobalSiteSelector\GlobalSiteSelector; -use OCA\GlobalSiteSelector\Master; use OCA\GlobalSiteSelector\Vendor\Firebase\JWT\JWT; use OCA\GlobalSiteSelector\Vendor\Firebase\JWT\Key; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\OCSController; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IRequest; -use OCP\ISession; use OCP\IURLGenerator; use Psr\Log\LoggerInterface; @@ -44,28 +46,16 @@ * @package OCA\GlobalSiteSelector\Controller */ class MasterController extends OCSController { - private IURLGenerator $urlGenerator; - private ISession $session; - private GlobalSiteSelector $gss; - private Master $master; - private LoggerInterface $logger; public function __construct( - $appName, + string $appName, IRequest $request, - IURLGenerator $urlGenerator, - ISession $session, - GlobalSiteSelector $globalSiteSelector, - Master $master, - LoggerInterface $logger + private IURLGenerator $urlGenerator, + private IEventDispatcher $eventDispatcher, + private GlobalSiteSelector $gss, + private LoggerInterface $logger ) { parent::__construct($appName, $request); - - $this->urlGenerator = $urlGenerator; - $this->session = $session; - $this->gss = $globalSiteSelector; - $this->master = $master; - $this->logger = $logger; } /** @@ -82,20 +72,23 @@ public function autoLogout(?string $jwt) { if ($jwt !== null) { $key = $this->gss->getJwtKey(); $decoded = (array)JWT::decode($jwt, new Key($key, Application::JWT_ALGORITHM)); - $idp = $decoded['saml.idp'] ?? null; - - $logoutUrl = $this->urlGenerator->linkToRoute('user_saml.SAML.singleLogoutService'); - if (!empty($logoutUrl)) { - $token = [ - 'logout' => 'logout', - 'idp' => $idp, - 'exp' => time() + 300, // expires after 5 minutes - ]; - $jwt = JWT::encode($token, $this->gss->getJwtKey(), Application::JWT_ALGORITHM); + $event = new GlobalScaleMasterLogoutEvent(); + $event->setIdp($decoded['saml.idp'] ?? ''); + $this->eventDispatcher->dispatchTyped($event); - return new RedirectResponse($logoutUrl . '?jwt=' . $jwt); - } +// $logoutUrl = $this->urlGenerator->linkToRoute('user_saml.SAML.singleLogoutService'); +// if (!empty($logoutUrl)) { +// $token = [ +// 'logout' => 'logout', +// 'idp' => $idp, +// 'exp' => time() + 300, // expires after 5 minutes +// ]; +// +// $jwt = JWT::encode($token, $this->gss->getJwtKey(), Application::JWT_ALGORITHM); +// +// return new RedirectResponse($logoutUrl . '?jwt=' . $jwt); +// } } } catch (\Exception $e) { $this->logger->warning('remote logout request failed', ['exception' => $e]); diff --git a/lib/Events/GlobalScaleMasterLogoutEvent.php b/lib/Events/GlobalScaleMasterLogoutEvent.php new file mode 100644 index 0000000..fa6ec80 --- /dev/null +++ b/lib/Events/GlobalScaleMasterLogoutEvent.php @@ -0,0 +1,43 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\GlobalSiteSelector\Events; + +use OCP\EventDispatcher\Event; + +class GlobalScaleMasterLogoutEvent extends Event { + private string $idp = ''; + + public function __construct() { + parent::__construct(); + } + + public function setIdp(string $idp): void { + $this->idp = $idp; + } + + public function getIdp(): string { + return $this->idp; + } +}