|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Repository; |
|
20
|
|
|
|
|
21
|
|
|
use DateTime; |
|
22
|
|
|
use Doctrine\ORM\EntityManager; |
|
23
|
|
|
use Doctrine\ORM\EntityRepository; |
|
24
|
|
|
use Doctrine\ORM\Mapping; |
|
25
|
|
|
use Doctrine\ORM\Query; |
|
26
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
|
27
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Filter\InstitutionAuthorizationRepositoryFilter; |
|
28
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Value\InstitutionAuthorizationContextInterface; |
|
29
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VerifiedSecondFactor; |
|
30
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VerifiedSecondFactorQuery; |
|
31
|
|
|
|
|
32
|
|
|
class VerifiedSecondFactorRepository extends EntityRepository |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var InstitutionAuthorizationRepositoryFilter |
|
36
|
|
|
*/ |
|
37
|
|
|
private $authorizationRepositoryFilter; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* VerifiedSecondFactorRepository constructor. |
|
41
|
|
|
* @param EntityManager $em |
|
42
|
|
|
* @param Mapping\ClassMetadata $class |
|
43
|
|
|
* @param InstitutionAuthorizationRepositoryFilter $authorizationRepositoryFilter |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
EntityManager $em, |
|
47
|
|
|
Mapping\ClassMetadata $class, |
|
48
|
|
|
InstitutionAuthorizationRepositoryFilter $authorizationRepositoryFilter |
|
49
|
|
|
) { |
|
50
|
|
|
parent::__construct($em, $class); |
|
51
|
|
|
$this->authorizationRepositoryFilter = $authorizationRepositoryFilter; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $id |
|
57
|
|
|
* @return VerifiedSecondFactor|null |
|
58
|
|
|
*/ |
|
59
|
|
|
public function find($id) |
|
60
|
|
|
{ |
|
61
|
|
|
/** @var VerifiedSecondFactor|null $secondFactor */ |
|
62
|
|
|
$secondFactor = parent::find($id); |
|
63
|
|
|
|
|
64
|
|
|
return $secondFactor; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param DateTime $requestedAt |
|
69
|
|
|
* @return VerifiedSecondFactor[] |
|
70
|
|
|
*/ |
|
71
|
|
|
public function findByDate(DateTime $requestedAt) |
|
72
|
|
|
{ |
|
73
|
|
|
$fromDate = clone $requestedAt; |
|
74
|
|
|
$fromDate->setTime(0, 0, 0); |
|
75
|
|
|
|
|
76
|
|
|
$toDate = clone $requestedAt; |
|
77
|
|
|
$toDate->setTime(23, 59, 59); |
|
78
|
|
|
|
|
79
|
|
|
return $this->createQueryBuilder('sf') |
|
80
|
|
|
->where('sf.registrationRequestedAt <= :toDate') |
|
81
|
|
|
->andWhere('sf.registrationRequestedAt >= :fromDate') |
|
82
|
|
|
->setParameter('toDate', $toDate) |
|
83
|
|
|
->setParameter('fromDate', $fromDate) |
|
84
|
|
|
->getQuery() |
|
85
|
|
|
->getResult(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param VerifiedSecondFactorQuery $query |
|
90
|
|
|
* @param InstitutionAuthorizationContextInterface $authorizationContext |
|
|
|
|
|
|
91
|
|
|
* @param InstitutionAuthorizationRepositoryFilter $authorizationRepositoryFilter |
|
|
|
|
|
|
92
|
|
|
* @return Query |
|
93
|
|
|
*/ |
|
94
|
|
View Code Duplication |
public function createSearchQuery(VerifiedSecondFactorQuery $query) |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
|
|
$queryBuilder = $this->createQueryBuilder('sf'); |
|
97
|
|
|
|
|
98
|
|
|
// Modify query to filter on authorization |
|
99
|
|
|
$this->authorizationRepositoryFilter->filter($queryBuilder, $query->authorizationContext, 'sf.id', 'sf.institution', 'iac'); |
|
100
|
|
|
|
|
101
|
|
|
if ($query->identityId) { |
|
102
|
|
|
$queryBuilder |
|
103
|
|
|
->andWhere('sf.identityId = :identityId') |
|
104
|
|
|
->setParameter('identityId', (string) $query->identityId); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if ($query->secondFactorId) { |
|
108
|
|
|
$queryBuilder |
|
109
|
|
|
->andWhere('sf.id = :secondFactorId') |
|
110
|
|
|
->setParameter('secondFactorId', (string) $query->secondFactorId); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (is_string($query->registrationCode)) { |
|
114
|
|
|
$queryBuilder |
|
115
|
|
|
->andWhere('sf.registrationCode = :registrationCode') |
|
116
|
|
|
->setParameter('registrationCode', $query->registrationCode); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $queryBuilder->getQuery(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
View Code Duplication |
public function removeByIdentityId(IdentityId $identityId) |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
$this->getEntityManager()->createQueryBuilder() |
|
125
|
|
|
->delete($this->_entityName, 'sf') |
|
126
|
|
|
->where('sf.identityId = :identityId') |
|
127
|
|
|
->setParameter('identityId', $identityId->getIdentityId()) |
|
128
|
|
|
->getQuery() |
|
129
|
|
|
->execute(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param VerifiedSecondFactor $secondFactor |
|
134
|
|
|
*/ |
|
135
|
|
|
public function save(VerifiedSecondFactor $secondFactor) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->getEntityManager()->persist($secondFactor); |
|
138
|
|
|
$this->getEntityManager()->flush(); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function remove(VerifiedSecondFactor $secondFactor) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->getEntityManager()->remove($secondFactor); |
|
144
|
|
|
$this->getEntityManager()->flush(); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.