From 4740181f01277cfd3426a5b388cfd3f87531b086 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 20 Jun 2024 12:00:53 +0600 Subject: [PATCH 1/5] fix: wrong logException format at passwordUpdateListener class --- lib/Listeners/PasswordUpdatedListener.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Listeners/PasswordUpdatedListener.php b/lib/Listeners/PasswordUpdatedListener.php index c283ac91..f3106922 100644 --- a/lib/Listeners/PasswordUpdatedListener.php +++ b/lib/Listeners/PasswordUpdatedListener.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Listeners; use Exception; +use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Service\SSOService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -33,7 +34,7 @@ class PasswordUpdatedListener implements IEventListener { try { $this->ssoService->logout($username); } catch (Exception $e) { - $this->logger->logException('Failed to logout from ssoService for user: ' . $username, ['exception' => $e]); + $this->logger->logException($e, ['app' => Application::APP_ID]); } } } -- GitLab From 2781b33cf0059b7f14232e829a956237c462cc88 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 20 Jun 2024 12:06:41 +0600 Subject: [PATCH 2/5] chore: enable passwordUpadteListener --- appinfo/info.xml | 2 +- lib/AppInfo/Application.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index e6f7fd12..957567d6 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 6.0.4 + 6.0.5/version> agpl Murena SAS EcloudAccounts diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1859c022..b1635540 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -55,7 +55,7 @@ class Application extends App implements IBootstrap { $context->registerEventListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); $context->registerEventListener(StateChanged::class, TwoFactorStateChangedListener::class); - // $context->registerEventListener(PasswordUpdatedEvent::class, PasswordUpdatedListener::class); + $context->registerEventListener(PasswordUpdatedEvent::class, PasswordUpdatedListener::class); } public function boot(IBootContext $context): void { -- GitLab From 3deb90b3b4f69edcae5030e047622eb0ec97c1ae Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Thu, 20 Jun 2024 07:30:42 +0000 Subject: [PATCH 3/5] Apply 1 suggestion(s) to 1 file(s) --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 957567d6..fa2d7ab5 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 6.0.5/version> + 6.0.5 agpl Murena SAS EcloudAccounts -- GitLab From 0201405c9e9f6b4e58a70d984293bb2d523771a3 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 21 Jun 2024 12:05:24 +0600 Subject: [PATCH 4/5] fix: add is_oidc session check before logout to sso --- lib/Listeners/PasswordUpdatedListener.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/PasswordUpdatedListener.php b/lib/Listeners/PasswordUpdatedListener.php index f3106922..0f3666c0 100644 --- a/lib/Listeners/PasswordUpdatedListener.php +++ b/lib/Listeners/PasswordUpdatedListener.php @@ -10,17 +10,20 @@ use OCA\EcloudAccounts\Service\SSOService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\ILogger; +use OCP\ISession; use OCP\User\Events\PasswordUpdatedEvent; class PasswordUpdatedListener implements IEventListener { private SSOService $ssoService; - private $logger; + private ILogger $logger; + private ISession $session; - public function __construct(SSOService $ssoService, ILogger $logger) { + public function __construct(SSOService $ssoService, ILogger $logger, ISession $session) { $this->ssoService = $ssoService; $this->logger = $logger; + $this->session = $session; } public function handle(Event $event): void { @@ -32,6 +35,10 @@ class PasswordUpdatedListener implements IEventListener { $username = $user->getUID(); try { + if (!$this->session->exists('is_oidc')) { + return; + } + $this->ssoService->logout($username); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); -- GitLab From 55c0fabcd37bf34b24fe3e3d5d91c687b2ef0e88 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Fri, 21 Jun 2024 19:13:06 +0600 Subject: [PATCH 5/5] feat: check userLoggedIn or not at passwordUpdateListener --- lib/Listeners/PasswordUpdatedListener.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Listeners/PasswordUpdatedListener.php b/lib/Listeners/PasswordUpdatedListener.php index 0f3666c0..8d1dd8f8 100644 --- a/lib/Listeners/PasswordUpdatedListener.php +++ b/lib/Listeners/PasswordUpdatedListener.php @@ -11,6 +11,7 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\ILogger; use OCP\ISession; +use OCP\IUserSession; use OCP\User\Events\PasswordUpdatedEvent; class PasswordUpdatedListener implements IEventListener { @@ -19,11 +20,13 @@ class PasswordUpdatedListener implements IEventListener { private ILogger $logger; private ISession $session; + private IUserSession $userSession; - public function __construct(SSOService $ssoService, ILogger $logger, ISession $session) { + public function __construct(SSOService $ssoService, ILogger $logger, ISession $session, IUserSession $userSession) { $this->ssoService = $ssoService; $this->logger = $logger; $this->session = $session; + $this->userSession = $userSession; } public function handle(Event $event): void { @@ -31,14 +34,14 @@ class PasswordUpdatedListener implements IEventListener { return; } + if (!$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { + return; + } + $user = $event->getUser(); $username = $user->getUID(); try { - if (!$this->session->exists('is_oidc')) { - return; - } - $this->ssoService->logout($username); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); -- GitLab