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\Controller; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionRole; |
22
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
23
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorId; |
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Authorization\Service\InstitutionAuthorizationService; |
25
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VerifiedSecondFactorOfIdentityQuery; |
26
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VerifiedSecondFactorQuery; |
27
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\SecondFactorService; |
28
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse; |
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
30
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
32
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
33
|
|
|
|
34
|
|
|
class VerifiedSecondFactorController extends Controller |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var SecondFactorService |
38
|
|
|
*/ |
39
|
|
|
private $secondFactorService; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var InstitutionAuthorizationService |
43
|
|
|
*/ |
44
|
|
|
private $institutionAuthorizationService; |
45
|
|
|
|
46
|
|
|
public function __construct( |
47
|
|
|
SecondFactorService $secondFactorService, |
48
|
|
|
InstitutionAuthorizationService $authorizationService |
49
|
|
|
) { |
50
|
|
|
$this->secondFactorService = $secondFactorService; |
51
|
|
|
$this->institutionAuthorizationService = $authorizationService; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getAction($id) |
55
|
|
|
{ |
56
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
57
|
|
|
|
58
|
|
|
$secondFactor = $this->secondFactorService->findVerified(new SecondFactorId($id)); |
59
|
|
|
|
60
|
|
|
if ($secondFactor === null) { |
61
|
|
|
throw new NotFoundHttpException(sprintf("Verified second factor '%s' does not exist", $id)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return new JsonResponse($secondFactor); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function collectionAction(Request $request) |
68
|
|
|
{ |
69
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA']); |
70
|
|
|
|
71
|
|
|
$actorId = new IdentityId($request->get('actorId')); |
72
|
|
|
|
73
|
|
|
$query = new VerifiedSecondFactorQuery(); |
74
|
|
|
|
75
|
|
|
if ($request->get('identityId')) { |
76
|
|
|
$query->identityId = new IdentityId($request->get('identityId')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($request->get('secondFactorId')) { |
80
|
|
|
$query->secondFactorId = new SecondFactorId($request->get('secondFactorId')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$query->registrationCode = $request->get('registrationCode'); |
84
|
|
|
$query->pageNumber = (int) $request->get('p', 1); |
85
|
|
|
$query->authorizationContext = $this->institutionAuthorizationService->buildInstitutionAuthorizationContext( |
86
|
|
|
$actorId, |
87
|
|
|
new InstitutionRole(InstitutionRole::ROLE_USE_RA) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$paginator = $this->secondFactorService->searchVerifiedSecondFactors($query); |
91
|
|
|
|
92
|
|
|
return JsonCollectionResponse::fromPaginator($paginator); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function collectionOfIdentityAction(Request $request) |
96
|
|
|
{ |
97
|
|
|
$this->denyAccessUnlessGranted(['ROLE_SS']); |
98
|
|
|
$query = new VerifiedSecondFactorOfIdentityQuery(); |
99
|
|
|
|
100
|
|
|
$query->identityId = new IdentityId($request->get('identityId')); |
101
|
|
|
$query->pageNumber = (int) $request->get('p', 1); |
102
|
|
|
|
103
|
|
|
$paginator = $this->secondFactorService->searchVerifiedSecondFactorsOfIdentity($query); |
104
|
|
|
|
105
|
|
|
return JsonCollectionResponse::fromPaginator($paginator); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|