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