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\Identity\Value\IdentityId; |
22
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorId; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\VerifiedSecondFactorQuery; |
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\SecondFactorService; |
25
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse; |
26
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
27
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
28
|
|
|
use Symfony\Component\HttpFoundation\Request; |
29
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
30
|
|
|
|
31
|
|
|
class VerifiedSecondFactorController extends Controller |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var SecondFactorService |
35
|
|
|
*/ |
36
|
|
|
private $secondFactorService; |
37
|
|
|
|
38
|
|
|
public function __construct(SecondFactorService $secondFactorService) |
39
|
|
|
{ |
40
|
|
|
$this->secondFactorService = $secondFactorService; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getAction($id) |
44
|
|
|
{ |
45
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
46
|
|
|
|
47
|
|
|
$secondFactor = $this->secondFactorService->findVerified(new SecondFactorId($id)); |
48
|
|
|
|
49
|
|
|
if ($secondFactor === null) { |
50
|
|
|
throw new NotFoundHttpException(sprintf("Verified second factor '%s' does not exist", $id)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return new JsonResponse($secondFactor); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function collectionAction(Request $request) |
57
|
|
|
{ |
58
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
59
|
|
|
|
60
|
|
|
$query = new VerifiedSecondFactorQuery(); |
61
|
|
|
|
62
|
|
|
if ($request->get('identityId')) { |
63
|
|
|
$query->identityId = new IdentityId($request->get('identityId')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($request->get('secondFactorId')) { |
67
|
|
|
$query->secondFactorId = new SecondFactorId($request->get('secondFactorId')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$query->registrationCode = $request->get('registrationCode'); |
71
|
|
|
$query->pageNumber = (int) $request->get('p', 1); |
72
|
|
|
|
73
|
|
|
$paginator = $this->secondFactorService->searchVerifiedSecondFactors($query); |
74
|
|
|
|
75
|
|
|
return JsonCollectionResponse::fromPaginator($paginator); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|