|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the UserWrapped class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\Security; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\User\User as APIUser; |
|
12
|
|
|
use Symfony\Component\Security\Core\User\EquatableInterface; |
|
13
|
|
|
use Symfony\Component\Security\Core\User\UserInterface as CoreUserInterface; |
|
14
|
|
|
use InvalidArgumentException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This class represents a UserWrapped object. |
|
18
|
|
|
* |
|
19
|
|
|
* It's used when working with multiple user providers |
|
20
|
|
|
* |
|
21
|
|
|
* It has two properties: |
|
22
|
|
|
* - wrappedUser: containing the originally matched user. |
|
23
|
|
|
* - apiUser: containing the API User (the one from the eZ Repository ) |
|
24
|
|
|
*/ |
|
25
|
|
|
class UserWrapped implements UserInterface, EquatableInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var \Symfony\Component\Security\Core\User\UserInterface */ |
|
28
|
|
|
private $wrappedUser; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \eZ\Publish\API\Repository\Values\User\User */ |
|
31
|
|
|
private $apiUser; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(CoreUserInterface $wrappedUser, APIUser $apiUser) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->setWrappedUser($wrappedUser); |
|
36
|
|
|
$this->apiUser = $apiUser; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function __toString() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->wrappedUser->getUsername(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $apiUser |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setAPIUser(APIUser $apiUser) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->apiUser = $apiUser; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getAPIUser() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->apiUser; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @throws InvalidArgumentException If $wrappedUser is instance of self or User to avoid duplicated APIUser in session. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \Symfony\Component\Security\Core\User\UserInterface $wrappedUser |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setWrappedUser(CoreUserInterface $wrappedUser) |
|
66
|
|
|
{ |
|
67
|
|
|
if ($wrappedUser instanceof self) { |
|
68
|
|
|
throw new InvalidArgumentException('Injecting UserWrapped to itself is not allowed to avoid recursion'); |
|
69
|
|
|
} elseif ($wrappedUser instanceof User) { |
|
70
|
|
|
throw new InvalidArgumentException('Injecting User into UserWrapped causes duplication of APIUser, not wanted for session serialization'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->wrappedUser = $wrappedUser; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return \Symfony\Component\Security\Core\User\UserInterface |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getWrappedUser() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->wrappedUser; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getRoles() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->wrappedUser->getRoles(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getPassword() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->wrappedUser->getPassword(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getSalt() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->wrappedUser->getSalt(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getUsername() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->wrappedUser->getUsername(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function eraseCredentials() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->wrappedUser->eraseCredentials(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function isEqualTo(CoreUserInterface $user) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->wrappedUser instanceof EquatableInterface ? $this->wrappedUser->isEqualTo($user) : true; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|