|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Security\User; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Security\Core\User\EquatableInterface; |
|
6
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
7
|
|
|
|
|
8
|
|
|
class AlmaUser implements UserInterface, EquatableInterface |
|
9
|
|
|
{ |
|
10
|
|
|
private $username; |
|
11
|
|
|
private $roles; |
|
12
|
|
|
private $fullName; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct($username, array $roles, $fullName) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->username = $username; |
|
17
|
|
|
$this->roles = $roles; |
|
18
|
|
|
$this->fullName = $fullName; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the roles granted to the user. |
|
23
|
|
|
* |
|
24
|
|
|
* <code> |
|
25
|
|
|
* public function getRoles() |
|
26
|
|
|
* { |
|
27
|
|
|
* return array('ROLE_USER'); |
|
28
|
|
|
* } |
|
29
|
|
|
* </code> |
|
30
|
|
|
* |
|
31
|
|
|
* Alternatively, the roles might be stored on a ``roles`` property, |
|
32
|
|
|
* and populated in any number of different ways when the user object |
|
33
|
|
|
* is created. |
|
34
|
|
|
* |
|
35
|
|
|
* @return array (Role|string)[] The user roles |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getRoles() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->roles; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the password used to authenticate the user. |
|
44
|
|
|
* |
|
45
|
|
|
* This should be the encoded password. On authentication, a plain-text |
|
46
|
|
|
* password will be salted, encoded, and then compared to this value. |
|
47
|
|
|
* |
|
48
|
|
|
* @return string The password |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getPassword() |
|
51
|
|
|
{ |
|
52
|
|
|
return null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns the salt that was originally used to encode the password. |
|
57
|
|
|
* |
|
58
|
|
|
* This can return null if the password was not encoded using a salt. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string|null The salt |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getSalt() |
|
63
|
|
|
{ |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Returns the username used to authenticate the user. |
|
69
|
|
|
* |
|
70
|
|
|
* @return string The username |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getUsername() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->username; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Removes sensitive data from the user. |
|
79
|
|
|
* |
|
80
|
|
|
* This is important if, at any given point, sensitive information like |
|
81
|
|
|
* the plain-text password is stored on this object. |
|
82
|
|
|
*/ |
|
83
|
|
|
public function eraseCredentials() |
|
84
|
|
|
{ |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* The equality comparison should neither be done by referential equality |
|
89
|
|
|
* nor by comparing identities (i.e. getId() === getId()). |
|
90
|
|
|
* |
|
91
|
|
|
* However, you do not need to compare every attribute, but only those that |
|
92
|
|
|
* are relevant for assessing whether re-authentication is required. |
|
93
|
|
|
* |
|
94
|
|
|
* Also implementation should consider that $user instance may implement |
|
95
|
|
|
* the extended user interface `AdvancedUserInterface`. |
|
96
|
|
|
* |
|
97
|
|
|
* @param UserInterface $user |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
public function isEqualTo(UserInterface $user) |
|
101
|
|
|
{ |
|
102
|
|
|
if (!$user instanceof AlmaUser) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
if ($this->username !== $user->getUsername()) { |
|
106
|
|
|
return false; |
|
107
|
|
|
} |
|
108
|
|
|
return true; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getFullName() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->fullName; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|