From cc9700a5581b9f66679be5c03713383e136757d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 3 Oct 2023 16:39:35 +0200 Subject: [PATCH] Fix: Expect at least one role returned from API client for user --- src/Security/BpnAuthenticator.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Security/BpnAuthenticator.php b/src/Security/BpnAuthenticator.php index c1c99fc..7731228 100644 --- a/src/Security/BpnAuthenticator.php +++ b/src/Security/BpnAuthenticator.php @@ -59,10 +59,17 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent return null; } + // Finale checks and local user loading/creation + $user = $this->getOrCreateLocalUser($response, $email, $password); + + if (null === $user) { + return null; + } + // Store BPN password in session for later use $request->getSession()->set('bpn_password', $password); - return $this->getOrCreateLocalUser($response, $email, $password); + return $user; }), [new CsrfTokenBadge('authenticate', $csrfToken)] ); @@ -91,7 +98,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent private function getOrCreateLocalUser(ProfileResponse $profileResponse, string $email, string $password): ?User { - // Fetch CRM attributes, early return in case of an API arror + // Fetch CRM attributes, early return in case of an API error try { /** @var CrmAttributesResponse $crmAttributes */ $crmAttributes = $this->apiClient->getCrmAttributes($email, $password); @@ -105,6 +112,11 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent ->collectRoles($crmAttributes) ; + // User is expected to have at least one role + if (0 === count($roles)) { + return null; + } + // Determine teamer status from CRM attributes $isTeamer = $crmAttributes->isTeamer();