diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1859c022f7a039c04e9765aba41402a0cb8ceda6..b1635540ceff074d7f59ffe30d3c1240dd6ec40d 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 { diff --git a/lib/Listeners/PasswordUpdatedListener.php b/lib/Listeners/PasswordUpdatedListener.php index c283ac91c35ed544a64e62c4432348f552162125..8d1dd8f85b361e0fee0b33008cee8983aa34db92 100644 --- a/lib/Listeners/PasswordUpdatedListener.php +++ b/lib/Listeners/PasswordUpdatedListener.php @@ -5,21 +5,28 @@ 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; use OCP\ILogger; +use OCP\ISession; +use OCP\IUserSession; use OCP\User\Events\PasswordUpdatedEvent; class PasswordUpdatedListener implements IEventListener { private SSOService $ssoService; - private $logger; + private ILogger $logger; + private ISession $session; + private IUserSession $userSession; - public function __construct(SSOService $ssoService, ILogger $logger) { + 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 { @@ -27,13 +34,17 @@ class PasswordUpdatedListener implements IEventListener { return; } + if (!$this->userSession->isLoggedIn() || !$this->session->exists('is_oidc')) { + return; + } + $user = $event->getUser(); $username = $user->getUID(); 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]); } } }