1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the GesdinetJWTRefreshTokenBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Gesdinet <http://www.gesdinet.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gesdinet\JWTRefreshTokenBundle\Doctrine; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
15
|
|
|
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshTokenRepository; |
16
|
|
|
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManager as BaseRefreshTokenManager; |
17
|
|
|
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface; |
18
|
|
|
|
19
|
|
|
class RefreshTokenManager extends BaseRefreshTokenManager |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ObjectManager |
23
|
|
|
*/ |
24
|
|
|
protected $objectManager; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $class; |
30
|
7 |
|
|
31
|
|
|
/** |
32
|
7 |
|
* @var RefreshTokenRepository |
33
|
7 |
|
*/ |
34
|
7 |
|
protected $repository; |
35
|
7 |
|
|
36
|
7 |
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
* |
39
|
|
|
* @param ObjectManager $om |
40
|
|
|
* @param string $class |
41
|
|
|
*/ |
42
|
|
|
public function __construct(ObjectManager $om, $class) |
43
|
1 |
|
{ |
44
|
|
|
$this->objectManager = $om; |
45
|
1 |
|
$this->repository = $om->getRepository($class); |
46
|
|
|
$metadata = $om->getClassMetadata($class); |
47
|
|
|
$this->class = $metadata->getName(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $refreshToken |
52
|
|
|
* |
53
|
1 |
|
* @return RefreshTokenInterface |
54
|
|
|
*/ |
55
|
1 |
|
public function get($refreshToken) |
56
|
|
|
{ |
57
|
|
|
return $this->repository->findOneBy(array('refreshToken' => $refreshToken)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $username |
62
|
1 |
|
* |
63
|
|
|
* @return RefreshTokenInterface |
64
|
1 |
|
*/ |
65
|
|
|
public function getLastFromUsername($username) |
66
|
1 |
|
{ |
67
|
1 |
|
return $this->repository->findOneBy(array('username' => $username), array('valid' => 'DESC')); |
68
|
1 |
|
} |
69
|
1 |
|
|
70
|
|
|
/** |
71
|
|
|
* @param RefreshTokenInterface $refreshToken |
72
|
|
|
* @param bool|true $andFlush |
73
|
|
|
*/ |
74
|
|
|
public function save(RefreshTokenInterface $refreshToken, $andFlush = true) |
75
|
1 |
|
{ |
76
|
|
|
$this->objectManager->persist($refreshToken); |
77
|
1 |
|
|
78
|
|
|
if ($andFlush) { |
79
|
1 |
|
$this->objectManager->flush(); |
80
|
1 |
|
} |
81
|
1 |
|
} |
82
|
1 |
|
|
83
|
|
|
/** |
84
|
|
|
* @param RefreshTokenInterface $refreshToken |
85
|
|
|
* @param bool $andFlush |
86
|
|
|
*/ |
87
|
|
|
public function delete(RefreshTokenInterface $refreshToken, $andFlush = true) |
88
|
|
|
{ |
89
|
|
|
$this->objectManager->remove($refreshToken); |
90
|
1 |
|
|
91
|
|
|
if ($andFlush) { |
92
|
1 |
|
$this->objectManager->flush(); |
93
|
|
|
} |
94
|
1 |
|
} |
95
|
1 |
|
|
96
|
1 |
|
/** |
97
|
|
|
* @param \DateTime $datetime |
98
|
1 |
|
* @param bool $andFlush |
99
|
1 |
|
* |
100
|
1 |
|
* @return RefreshTokenInterface[] |
101
|
|
|
*/ |
102
|
1 |
|
public function revokeAllInvalid($datetime = null, $andFlush = true) |
103
|
|
|
{ |
104
|
|
|
$invalidTokens = $this->repository->findInvalid($datetime); |
|
|
|
|
105
|
|
|
|
106
|
|
|
foreach ($invalidTokens as $invalidToken) { |
107
|
|
|
$this->objectManager->remove($invalidToken); |
108
|
|
|
} |
109
|
|
|
|
110
|
1 |
|
if ($andFlush) { |
111
|
|
|
$this->objectManager->flush(); |
112
|
1 |
|
} |
113
|
|
|
|
114
|
|
|
return $invalidTokens; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns the RefreshToken fully qualified class name. |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getClass() |
123
|
|
|
{ |
124
|
|
|
return $this->class; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.