1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yokai\SecurityTokenBundle\Factory; |
4
|
|
|
|
5
|
|
|
use Yokai\SecurityTokenBundle\Configuration\TokenConfigurationRegistry; |
6
|
|
|
use Yokai\SecurityTokenBundle\Entity\Token; |
7
|
|
|
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface; |
8
|
|
|
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Yann Eugoné <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class TokenFactory implements TokenFactoryInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var TokenConfigurationRegistry |
17
|
|
|
*/ |
18
|
|
|
private $registry; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var InformationGuesserInterface |
22
|
|
|
*/ |
23
|
|
|
private $informationGuesser; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var UserManagerInterface |
27
|
|
|
*/ |
28
|
|
|
private $userManager; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param TokenConfigurationRegistry $registry |
32
|
|
|
* @param InformationGuesserInterface $informationGuesser |
33
|
|
|
* @param UserManagerInterface $userManager |
34
|
|
|
*/ |
35
|
1 |
|
public function __construct( |
36
|
|
|
TokenConfigurationRegistry $registry, |
37
|
|
|
InformationGuesserInterface $informationGuesser, |
38
|
|
|
UserManagerInterface $userManager |
39
|
|
|
) { |
40
|
1 |
|
$this->registry = $registry; |
41
|
1 |
|
$this->informationGuesser = $informationGuesser; |
42
|
1 |
|
$this->userManager = $userManager; |
43
|
1 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
1 |
|
public function create($user, $purpose, array $payload = []) |
49
|
|
|
{ |
50
|
1 |
|
$configuration = $this->registry->get($purpose); |
51
|
|
|
|
52
|
1 |
|
return new Token( |
53
|
1 |
|
$this->userManager->getClass($user), |
54
|
1 |
|
$this->userManager->getId($user), |
55
|
1 |
|
$configuration->getGenerator()->generate(), |
56
|
|
|
$purpose, |
57
|
1 |
|
$configuration->getDuration(), |
58
|
1 |
|
$configuration->getKeep(), |
59
|
1 |
|
$configuration->getUsages(), |
60
|
|
|
$payload, |
61
|
1 |
|
$this->informationGuesser->get() |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|