From a26e8cf5020cfcb36adda0c82537de38387e8b81 Mon Sep 17 00:00:00 2001 From: wtermellil Date: Fri, 28 Oct 2022 10:01:52 +0200 Subject: [PATCH] fix(websso) remove exception when REMOTE_USER does not exist --- .../Infrastructure/Provider/WebSSO.php | 1 + src/EventSubscriber/WebSSOEventSubscriber.php | 16 ++++++++++------ .../WebSSOEventSubscriberTest.php | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Core/Security/Authentication/Infrastructure/Provider/WebSSO.php b/src/Core/Security/Authentication/Infrastructure/Provider/WebSSO.php index e07081ab7d7..54cad8ec1ec 100644 --- a/src/Core/Security/Authentication/Infrastructure/Provider/WebSSO.php +++ b/src/Core/Security/Authentication/Infrastructure/Provider/WebSSO.php @@ -221,6 +221,7 @@ public function validateLoginAttributeOrFail(): void $this->error('login header attribute not found in server environment', [ 'login_header_attribute' => $customConfiguration->getLoginHeaderAttribute() ]); + throw new InvalidArgumentException('Missing Login Attribute'); } } diff --git a/src/EventSubscriber/WebSSOEventSubscriber.php b/src/EventSubscriber/WebSSOEventSubscriber.php index dfe41c2b904..5f1f129389e 100644 --- a/src/EventSubscriber/WebSSOEventSubscriber.php +++ b/src/EventSubscriber/WebSSOEventSubscriber.php @@ -121,13 +121,17 @@ public function loginWebSSOUser(RequestEvent $event): void } $this->info('Starting authentication with WebSSO'); - $provider->authenticateOrFail( - LoginRequest::createForSSO($request->getClientIp()) - ); + try { + $provider->authenticateOrFail( + LoginRequest::createForSSO($request->getClientIp()) + ); - $user = $provider->findUserOrFail(); - $this->createSession($request, $provider); - $this->info('Authenticated successfully', ['user' => $user->getAlias()]); + $user = $provider->findUserOrFail(); + $this->createSession($request, $provider); + $this->info('Authenticated successfully', ['user' => $user->getAlias()]); + } catch (\InvalidArgumentException $exception) { + $this->info($exception->getMessage()); + } } /** diff --git a/tests/php/EventSubscriber/WebSSOEventSubscriberTest.php b/tests/php/EventSubscriber/WebSSOEventSubscriberTest.php index f30335908b3..95678449bb9 100644 --- a/tests/php/EventSubscriber/WebSSOEventSubscriberTest.php +++ b/tests/php/EventSubscriber/WebSSOEventSubscriberTest.php @@ -340,7 +340,7 @@ ->method('start'); $this->subscriber->loginWebSSOUser($this->event); -})->throws(\InvalidArgumentException::class, 'Missing Login Attribute'); +}); it('should throw an exception when login matching regexp returns an invalid result', function () { $this->request->cookies = new InputBag();