feat: extended oauth2 user info and refactored authenticator

This commit is contained in:
Björn Fromme
2025-12-12 19:57:34 +01:00
parent 6315fbd0f7
commit 42f17db542
7 changed files with 75 additions and 40 deletions
+4 -26
View File
@@ -4,7 +4,6 @@ namespace App\Security;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\CrmAttributes;
use App\BusProNet\Model\PersonalData;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
@@ -79,7 +78,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
throw new CustomUserMessageAuthenticationException($e->getMessage());
}
$roles = $this->collectRoles($crmAttributes);
$roles = $crmAttributes->roles;
$hotelCodes = $crmAttributes->hotelCodes;
$encryptedPassword = $this->crypt->encrypt($password);
$userRepository = $this->entityManager->getRepository(User::class);
@@ -94,6 +95,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
->setPersonId($personId)
->setAddressId($addressId)
->setRoles($roles)
->setHotelCodes($hotelCodes)
->setLastLoginAt(new \DateTimeImmutable())
;
@@ -114,28 +116,4 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
return new RedirectResponse($this->urlGenerator->generate('app_account'));
}
private function collectRoles(CrmAttributes $crmAttributes): array
{
// All users inherit the default role 'customer'
$roles = [
'ROLE_CUSTOMER',
];
// Get user's base role from CRM attributes
if ($crmAttributes->admin) {
$roles[] = 'ROLE_ADMIN';
} elseif ($crmAttributes->manager) {
$roles[] = 'ROLE_MANAGER';
} elseif ($crmAttributes->houseManager) {
$roles[] = 'ROLE_HOUSE_MANAGER';
}
// All users can have role 'teamer' additionally
if ($crmAttributes->teamer) {
$roles[] = 'ROLE_TEAMER';
}
return $roles;
}
}