Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
9 / 9 |
|
85.71% |
6 / 7 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| UserProvider | |
100.00% |
11 / 11 |
|
100.00% |
9 / 9 |
|
85.71% |
6 / 7 |
|
100.00% |
4 / 4 |
6.10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| loadUserByIdentifier | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
|
75.00% |
3 / 4 |
|
100.00% |
1 / 1 |
3.14 | |||
| refreshUser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supportsClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Auth\Infrastructure\Security; |
| 4 | |
| 5 | use App\Auth\Domain\Port\Driven\IdentityRepository; |
| 6 | use App\Auth\Infrastructure\Security\User\AuthenticatedUser; |
| 7 | use App\Shared\Domain\Exception\InvalidEntityIdException; |
| 8 | use App\Shared\Domain\Model\EntityId; |
| 9 | use Override; |
| 10 | use Psr\Log\LoggerInterface; |
| 11 | use Symfony\Component\Security\Core\Exception\UserNotFoundException; |
| 12 | use Symfony\Component\Security\Core\User\UserInterface; |
| 13 | use Symfony\Component\Security\Core\User\UserProviderInterface; |
| 14 | |
| 15 | /** |
| 16 | * @author Wilhelm Zwertvaegher |
| 17 | * @implements UserProviderInterface<UserInterface> |
| 18 | */ |
| 19 | readonly class UserProvider implements UserProviderInterface |
| 20 | { |
| 21 | public function __construct(private IdentityRepository $repository, private readonly LoggerInterface $logger) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | #[Override] |
| 26 | public function loadUserByIdentifier(string $identifier): UserInterface |
| 27 | { |
| 28 | try { |
| 29 | $identity = $this->repository->findById(EntityId::fromString($identifier)); |
| 30 | } catch (InvalidEntityIdException $e) { |
| 31 | $identity = $this->repository->findByIdentifier($identifier); |
| 32 | } |
| 33 | |
| 34 | if (!$identity) { |
| 35 | $this->logger->info("Identity '$identifier' not found."); |
| 36 | throw new UserNotFoundException("Identity '$identifier' not found."); |
| 37 | } |
| 38 | $this->logger->info("Identity for '$identifier' found."); |
| 39 | return new AuthenticatedUser($identity); |
| 40 | } |
| 41 | |
| 42 | #[Override] |
| 43 | public function refreshUser(UserInterface $user): UserInterface |
| 44 | { |
| 45 | return $user; // JWT → stateless |
| 46 | } |
| 47 | |
| 48 | #[Override] |
| 49 | public function supportsClass(string $class): bool |
| 50 | { |
| 51 | return $class === AuthenticatedUser::class; |
| 52 | } |
| 53 | } |