1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @see https://github.com/ecphp |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace EcPhp\EuLoginBundle\Security\Core\User; |
13
|
|
|
|
14
|
|
|
use EcPhp\CasBundle\Security\Core\User\CasUserInterface; |
15
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
16
|
|
|
|
17
|
|
|
use function array_key_exists; |
18
|
|
|
|
19
|
|
|
final class EuLoginUser implements EuLoginUserInterface |
20
|
|
|
{ |
21
|
|
|
private CasUserInterface $user; |
22
|
|
|
|
23
|
5 |
|
public function __construct(CasUserInterface $user) |
24
|
|
|
{ |
25
|
5 |
|
$this->user = $user; |
26
|
5 |
|
} |
27
|
|
|
|
28
|
1 |
|
public function eraseCredentials(): void |
29
|
|
|
{ |
30
|
|
|
// null |
31
|
1 |
|
} |
32
|
|
|
|
33
|
1 |
|
public function get(string $key, $default = null) |
34
|
|
|
{ |
35
|
1 |
|
return $this->user->get($key, $default); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
public function getAssuranceLevel(): ?string |
39
|
|
|
{ |
40
|
1 |
|
return $this->user->getAttribute('assuranceLevel'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getAttribute(string $key, $default = null) |
44
|
|
|
{ |
45
|
|
|
return $this->user->getAttribute($key, $default); |
46
|
|
|
} |
47
|
|
|
|
48
|
4 |
|
public function getAttributes(): array |
49
|
|
|
{ |
50
|
4 |
|
$attributes = $this->user->getAttributes(); |
51
|
|
|
|
52
|
|
|
/** @Todo Ugly. Refactor this when JSON format will be available. */ |
53
|
|
|
$propertyToMangle = [ |
54
|
4 |
|
['extendedAttributes', 'extendedAttribute'], |
55
|
|
|
['groups', 'group'], |
56
|
|
|
['strengths', 'strength'], |
57
|
|
|
['authenticationFactors', 'authenticationFactor'], |
58
|
|
|
]; |
59
|
|
|
|
60
|
4 |
|
foreach ($propertyToMangle as [$parent, $child]) { |
61
|
4 |
|
if (!array_key_exists($parent, $attributes)) { |
62
|
1 |
|
continue; |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
if (!array_key_exists($child, $attributes[$parent])) { |
|
|
|
|
66
|
4 |
|
continue; |
67
|
|
|
} |
68
|
|
|
|
69
|
4 |
|
$attributes[$parent][$child] = (array) $attributes[$parent][$child]; |
70
|
|
|
|
71
|
4 |
|
if (array_key_exists(0, $attributes[$parent][$child])) { |
72
|
3 |
|
continue; |
73
|
|
|
} |
74
|
|
|
|
75
|
4 |
|
$attributes[$parent][$child] = [$attributes[$parent][$child]]; |
76
|
|
|
} |
77
|
|
|
|
78
|
4 |
|
return $attributes; |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function getAuthenticationFactors(): array |
82
|
|
|
{ |
83
|
1 |
|
return $this->user->getAttribute('authenticationFactors', []); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public function getDepartmentNumber(): ?string |
87
|
|
|
{ |
88
|
1 |
|
return $this->user->getAttribute('departmentNumber'); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function getDomain(): ?string |
92
|
|
|
{ |
93
|
1 |
|
return $this->user->getAttribute('domain'); |
94
|
|
|
} |
95
|
|
|
|
96
|
1 |
|
public function getDomainUsername(): ?string |
97
|
|
|
{ |
98
|
1 |
|
return $this->user->getAttribute('domainUsername'); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function getEmail(): ?string |
102
|
|
|
{ |
103
|
1 |
|
return $this->user->getAttribute('email'); |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getEmployeeNumber(): ?string |
107
|
|
|
{ |
108
|
1 |
|
return $this->user->getAttribute('employeeNumber'); |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
public function getEmployeeType(): ?string |
112
|
|
|
{ |
113
|
1 |
|
return $this->user->getAttribute('employeeType'); |
114
|
|
|
} |
115
|
|
|
|
116
|
1 |
|
public function getExtendedAttributes(): array |
117
|
|
|
{ |
118
|
1 |
|
$attributes = $this->getAttributes(); |
119
|
|
|
|
120
|
1 |
|
if (!array_key_exists('extendedAttributes', $attributes)) { |
121
|
|
|
return []; |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
$extendedAttributes = $attributes['extendedAttributes']; |
125
|
|
|
|
126
|
1 |
|
if (!array_key_exists('extendedAttribute', $extendedAttributes)) { |
|
|
|
|
127
|
|
|
return []; |
128
|
|
|
} |
129
|
|
|
|
130
|
1 |
|
$extendedAttributes = $attributes['extendedAttributes']['extendedAttribute']; |
131
|
|
|
|
132
|
1 |
|
return array_reduce( |
133
|
1 |
|
$extendedAttributes, |
134
|
1 |
|
static function (array $carry, array $item): array { |
135
|
1 |
|
$carry[$item['@attributes']['name']] = $item['attributeValue']; |
136
|
|
|
|
137
|
1 |
|
return $carry; |
138
|
1 |
|
}, |
139
|
1 |
|
[] |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
1 |
|
public function getFirstName(): ?string |
144
|
|
|
{ |
145
|
1 |
|
return $this->user->getAttribute('firstName'); |
146
|
|
|
} |
147
|
|
|
|
148
|
3 |
|
public function getGroups(): array |
149
|
|
|
{ |
150
|
3 |
|
$attributes = $this->getAttributes(); |
151
|
|
|
|
152
|
3 |
|
if (!array_key_exists('groups', $attributes)) { |
153
|
|
|
return []; |
154
|
|
|
} |
155
|
|
|
|
156
|
3 |
|
$groups = $attributes['groups']; |
157
|
|
|
|
158
|
3 |
|
if (!array_key_exists('group', $groups)) { |
|
|
|
|
159
|
1 |
|
return []; |
160
|
|
|
} |
161
|
|
|
|
162
|
2 |
|
return $groups['group']; |
163
|
|
|
} |
164
|
|
|
|
165
|
1 |
|
public function getLastName(): ?string |
166
|
|
|
{ |
167
|
1 |
|
return $this->user->getAttribute('lastName'); |
168
|
|
|
} |
169
|
|
|
|
170
|
1 |
|
public function getLocale(): ?string |
171
|
|
|
{ |
172
|
1 |
|
return $this->user->getAttribute('locale'); |
173
|
|
|
} |
174
|
|
|
|
175
|
1 |
|
public function getLoginDate(): ?string |
176
|
|
|
{ |
177
|
1 |
|
return $this->user->getAttribute('loginDate'); |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
public function getOrgId(): ?string |
181
|
|
|
{ |
182
|
1 |
|
return $this->user->getAttribute('orgId'); |
183
|
|
|
} |
184
|
|
|
|
185
|
1 |
|
public function getPassword() |
186
|
|
|
{ |
187
|
1 |
|
return null; |
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
public function getPgt(): ?string |
191
|
|
|
{ |
192
|
1 |
|
return $this->user->getPgt(); |
193
|
|
|
} |
194
|
|
|
|
195
|
1 |
|
public function getProxyGrantingProtocol(): ?string |
196
|
|
|
{ |
197
|
1 |
|
return $this->user->getAttribute('proxyGrantingProtocol'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function getRoles() |
201
|
|
|
{ |
202
|
|
|
$default = ['ROLE_CAS_AUTHENTICATED']; |
203
|
|
|
|
204
|
|
|
return array_merge($this->getGroups(), $default); |
205
|
|
|
} |
206
|
|
|
|
207
|
1 |
|
public function getSalt() |
208
|
|
|
{ |
209
|
1 |
|
return null; |
210
|
|
|
} |
211
|
|
|
|
212
|
1 |
|
public function getSso(): ?string |
213
|
|
|
{ |
214
|
1 |
|
return $this->user->getAttribute('sso'); |
215
|
|
|
} |
216
|
|
|
|
217
|
2 |
|
public function getStrengths(): array |
218
|
|
|
{ |
219
|
2 |
|
$attributes = $this->getAttributes(); |
220
|
|
|
|
221
|
2 |
|
if (!array_key_exists('strengths', $attributes)) { |
222
|
|
|
return []; |
223
|
|
|
} |
224
|
|
|
|
225
|
2 |
|
$strengths = $attributes['strengths']; |
226
|
|
|
|
227
|
2 |
|
if (!array_key_exists('strength', $strengths)) { |
|
|
|
|
228
|
|
|
return []; |
229
|
|
|
} |
230
|
|
|
|
231
|
2 |
|
return (array) $strengths['strength']; |
232
|
|
|
} |
233
|
|
|
|
234
|
1 |
|
public function getTelephoneNumber(): ?string |
235
|
|
|
{ |
236
|
1 |
|
return $this->user->getAttribute('telephoneNumber'); |
237
|
|
|
} |
238
|
|
|
|
239
|
1 |
|
public function getTeleworkingPriority(): ?string |
240
|
|
|
{ |
241
|
1 |
|
return $this->user->getAttribute('teleworkingPriority'); |
242
|
|
|
} |
243
|
|
|
|
244
|
1 |
|
public function getTicketType(): ?string |
245
|
|
|
{ |
246
|
1 |
|
return $this->user->getAttribute('ticketType'); |
247
|
|
|
} |
248
|
|
|
|
249
|
1 |
|
public function getTimeZone(): ?string |
250
|
|
|
{ |
251
|
1 |
|
return $this->user->getAttribute('timeZone'); |
252
|
|
|
} |
253
|
|
|
|
254
|
1 |
|
public function getUid(): ?string |
255
|
|
|
{ |
256
|
1 |
|
return $this->user->getAttribute('uid'); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @deprecated use getUserIdentifier() instead |
261
|
|
|
*/ |
262
|
1 |
|
public function getUser(): string |
263
|
|
|
{ |
264
|
1 |
|
trigger_deprecation( |
265
|
1 |
|
'ecphp/eu-login-bundle', |
266
|
1 |
|
'2.2.3', |
267
|
1 |
|
'The method "%s::getUser()" is deprecated, use %s::getUserIdentifier() instead.', |
268
|
1 |
|
EuLoginUser::class |
269
|
|
|
); |
270
|
|
|
|
271
|
1 |
|
return $this->user->getUsername(); |
|
|
|
|
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
public function getUserIdentifier() |
275
|
|
|
{ |
276
|
|
|
return $this->user->getUserIdentifier(); |
|
|
|
|
277
|
|
|
} |
278
|
|
|
|
279
|
1 |
|
public function getUserManager(): ?string |
280
|
|
|
{ |
281
|
1 |
|
return $this->user->getAttribute('userManager'); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @deprecated since Symfony 5.3, use getUserIdentifier() instead |
286
|
|
|
*/ |
287
|
|
|
public function getUsername() |
288
|
|
|
{ |
289
|
|
|
trigger_deprecation( |
290
|
|
|
'ecphp/eu-login-bundle', |
291
|
|
|
'2.3.8', |
292
|
|
|
'The method "%s::getUsername()" is deprecated, use %s::getUserIdentifier() instead.', |
293
|
|
|
EuLoginUser::class |
294
|
|
|
); |
295
|
|
|
|
296
|
|
|
return $this->user->getUsername(); |
|
|
|
|
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function isEqualTo(UserInterface $user) |
300
|
|
|
{ |
301
|
|
|
return $this->user->isEqualTo($user); |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|