1 | <?php |
||
2 | declare(strict_types = 1); |
||
3 | /** |
||
4 | * /src/Security/ApiKeyUser.php |
||
5 | * |
||
6 | * @author TLe, Tarmo Leppänen <[email protected]> |
||
7 | */ |
||
8 | |||
9 | namespace App\Security; |
||
10 | |||
11 | use App\Entity\ApiKey; |
||
12 | use App\Enum\Role; |
||
13 | use App\Security\Interfaces\ApiKeyUserInterface; |
||
14 | use Symfony\Component\Security\Core\User\UserInterface; |
||
15 | use function array_unique; |
||
16 | |||
17 | /** |
||
18 | * Class ApiKeyUser |
||
19 | * |
||
20 | * @package App\Security |
||
21 | * @author TLe, Tarmo Leppänen <[email protected]> |
||
22 | */ |
||
23 | class ApiKeyUser implements ApiKeyUserInterface, UserInterface |
||
24 | { |
||
25 | private readonly string $identifier; |
||
26 | private readonly string $apiKeyIdentifier; |
||
27 | |||
28 | /** |
||
29 | * @var array<int, string> |
||
30 | */ |
||
31 | private readonly array $roles; |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 20 | public function __construct(ApiKey $apiKey, array $roles) |
|
37 | { |
||
38 | 20 | $this->identifier = $apiKey->getToken(); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
39 | 20 | $this->apiKeyIdentifier = $apiKey->getId(); |
|
0 ignored issues
–
show
|
|||
40 | 20 | $this->roles = array_unique([...$roles, Role::API->value]); |
|
0 ignored issues
–
show
|
|||
41 | } |
||
42 | |||
43 | 2 | public function getUserIdentifier(): string |
|
44 | { |
||
45 | 2 | return $this->identifier; |
|
46 | } |
||
47 | |||
48 | 7 | public function getApiKeyIdentifier(): string |
|
49 | { |
||
50 | 7 | return $this->apiKeyIdentifier; |
|
51 | } |
||
52 | |||
53 | 15 | public function getRoles(): array |
|
54 | { |
||
55 | 15 | return $this->roles; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * @codeCoverageIgnore |
||
60 | */ |
||
61 | public function getPassword(): ?string |
||
62 | { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @codeCoverageIgnore |
||
68 | */ |
||
69 | public function getSalt(): ?string |
||
70 | { |
||
71 | return null; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @codeCoverageIgnore |
||
76 | */ |
||
77 | public function eraseCredentials(): void |
||
78 | { |
||
79 | } |
||
80 | } |
||
81 |