|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the user HashGenerator 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\User; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\HashGenerator as HashGeneratorInterface; |
|
12
|
|
|
use eZ\Publish\SPI\User\Identity as IdentityInterface; |
|
13
|
|
|
use eZ\Publish\SPI\User\IdentityAware; |
|
14
|
|
|
use FOS\HttpCache\UserContext\ContextProviderInterface; |
|
15
|
|
|
use FOS\HttpCache\UserContext\UserContext; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* User hash generator. |
|
19
|
|
|
* |
|
20
|
|
|
* @deprecated since 5.4. Will be removed in 6.0. Use FOSHttpCacheBundle user context feature instead. |
|
21
|
|
|
*/ |
|
22
|
|
|
class HashGenerator implements HashGeneratorInterface, IdentityAware, ContextProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var IdentityInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $userIdentity; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var IdentityAware[] |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $identityDefiners = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param IdentityAware $identityDefiner |
|
36
|
|
|
*/ |
|
37
|
|
|
public function setIdentityDefiner(IdentityAware $identityDefiner) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->identityDefiners[] = $identityDefiner; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return IdentityAware[] |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getIdentityDefiners() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->identityDefiners; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param IdentityInterface $identity |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setIdentity(IdentityInterface $identity) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->userIdentity = $identity; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return IdentityInterface |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getIdentity() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->userIdentity; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Generates the user hash. |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function generate() |
|
72
|
|
|
{ |
|
73
|
|
|
foreach ($this->getIdentityDefiners() as $identityDefiner) { |
|
74
|
|
|
$identityDefiner->setIdentity($this->userIdentity); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->userIdentity->getHash(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function updateUserContext(UserContext $context) |
|
81
|
|
|
{ |
|
82
|
|
|
$context->addParameter('ezpublish_identity', $this->generate()); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|