|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2023 SURFnet bv |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication; |
|
22
|
|
|
|
|
23
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
|
25
|
|
|
|
|
26
|
|
|
readonly class AuthenticatedIdentity implements UserInterface |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
public function __construct(private Identity $originalIdentity) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getIdentity(): Identity |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
return $this->originalIdentity; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getUsername(): string |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
return $this->originalIdentity->id ?: ''; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
|
|
|
|
|
43
|
|
|
* @inheritDoc |
|
44
|
|
|
*/ |
|
|
|
|
|
|
45
|
|
|
public function getRoles(): array |
|
46
|
|
|
{ |
|
47
|
|
|
// You can customize this method based on your application's logic. |
|
48
|
|
|
return ['ROLE_USER']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
|
|
|
|
|
52
|
|
|
* @inheritDoc |
|
53
|
|
|
*/ |
|
|
|
|
|
|
54
|
|
|
public function getPassword(): ?string |
|
55
|
|
|
{ |
|
56
|
|
|
// You may not store the password in this DTO, return null. |
|
57
|
|
|
return null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
|
|
|
|
|
61
|
|
|
* @inheritDoc |
|
62
|
|
|
*/ |
|
|
|
|
|
|
63
|
|
|
public function getSalt(): ?string |
|
64
|
|
|
{ |
|
65
|
|
|
// You may not store a salt in this DTO, return null. |
|
66
|
|
|
return null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
|
|
|
|
|
70
|
|
|
* @inheritDoc |
|
71
|
|
|
*/ |
|
|
|
|
|
|
72
|
|
|
public function eraseCredentials(): array |
|
73
|
|
|
{ |
|
74
|
|
|
return []; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Allow access to the original Identity instance if needed. |
|
79
|
|
|
*/ |
|
|
|
|
|
|
80
|
|
|
public function getOriginalIdentity(): Identity |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->originalIdentity; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getUserIdentifier(): string |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
$parts = explode(':', $this->originalIdentity->nameId); |
|
88
|
|
|
return end($parts); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|