|
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\Institution; |
|
22
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\IdentityQuery; |
|
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\IdentityService; |
|
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse; |
|
25
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonNotFoundResponse; |
|
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 IdentityController extends Controller |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var IdentityService |
|
35
|
|
|
*/ |
|
36
|
|
|
private $identityService; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct(IdentityService $identityService) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->identityService = $identityService; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getAction($id) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
|
46
|
|
|
|
|
47
|
|
|
$identity = $this->identityService->find($id); |
|
48
|
|
|
|
|
49
|
|
|
if ($identity === null) { |
|
50
|
|
|
throw new NotFoundHttpException(sprintf("Identity '%s' does not exist", $id)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return new JsonResponse($identity); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function collectionAction(Request $request, Institution $institution) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
|
59
|
|
|
|
|
60
|
|
|
$query = new IdentityQuery(); |
|
61
|
|
|
$query->institution = $institution; |
|
62
|
|
|
$query->nameId = $request->get('NameID'); |
|
63
|
|
|
$query->commonName = $request->get('commonName'); |
|
64
|
|
|
$query->email = $request->get('email'); |
|
65
|
|
|
$query->pageNumber = (int) $request->get('p', 1); |
|
66
|
|
|
|
|
67
|
|
|
$paginator = $this->identityService->search($query); |
|
68
|
|
|
|
|
69
|
|
|
return JsonCollectionResponse::fromPaginator($paginator); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $identityId |
|
74
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getRegistrationAuthorityCredentialsAction($identityId) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA', 'ROLE_SS']); |
|
79
|
|
|
|
|
80
|
|
|
$identityService = $this->identityService; |
|
81
|
|
|
|
|
82
|
|
|
$credentials = $identityService->findRegistrationAuthorityCredentialsOf($identityId); |
|
83
|
|
|
|
|
84
|
|
|
if (!$credentials) { |
|
85
|
|
|
return new JsonNotFoundResponse(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return new JsonResponse($credentials); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|