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\CasBundle\Security\Core\User; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
15
|
|
|
|
16
|
|
|
final class CasUser implements CasUserInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The user storage. |
20
|
|
|
* |
21
|
|
|
* @var array<mixed> |
22
|
|
|
*/ |
23
|
|
|
private array $storage; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* CasUser constructor. |
27
|
|
|
* |
28
|
|
|
* @param array<mixed> $data |
29
|
|
|
*/ |
30
|
8 |
|
public function __construct(array $data) |
31
|
|
|
{ |
32
|
8 |
|
$this->storage = $data; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function eraseCredentials(): void |
36
|
|
|
{ |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
public function get(string $key, $default = null) |
40
|
|
|
{ |
41
|
3 |
|
return $this->getStorage()[$key] ?? $default; |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
public function getAttribute(string $key, $default = null) |
45
|
|
|
{ |
46
|
1 |
|
return $this->getStorage()['attributes'][$key] ?? $default; |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function getAttributes(): array |
50
|
|
|
{ |
51
|
1 |
|
return $this->get('attributes', []); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getPassword(): ?string |
55
|
|
|
{ |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getPgt(): ?string |
60
|
|
|
{ |
61
|
1 |
|
return $this->get('proxyGrantingTicket'); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function getRoles(): array |
65
|
|
|
{ |
66
|
1 |
|
return ['ROLE_CAS_AUTHENTICATED']; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getSalt(): ?string |
70
|
|
|
{ |
71
|
|
|
return null; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getUserIdentifier(): string |
75
|
|
|
{ |
76
|
|
|
return $this->get('user'); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function getUsername(): string |
80
|
|
|
{ |
81
|
1 |
|
return $this->get('user'); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function isEqualTo(UserInterface $user): bool |
85
|
|
|
{ |
86
|
|
|
return $user->getUserIdentifier() === $this->getUserIdentifier(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the storage. |
91
|
|
|
* |
92
|
|
|
* @return array<mixed> |
93
|
|
|
*/ |
94
|
4 |
|
private function getStorage(): array |
95
|
|
|
{ |
96
|
4 |
|
return $this->storage; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|