1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2019 SURFnet B.V. |
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\StepupMiddleware\ApiBundle\Identity\Service\ProfileService; |
22
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\Profile; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Controller\AbstractController; |
24
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
25
|
|
|
use Symfony\Component\HttpFoundation\Request; |
26
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
27
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
28
|
|
|
|
29
|
|
|
class ProfileController extends AbstractController |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
public function __construct( |
32
|
|
|
private readonly ProfileService $profileService, |
33
|
|
|
) { |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function get(Request $request, string $identityId): JsonResponse |
37
|
|
|
{ |
38
|
|
|
$this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_READ']); |
39
|
|
|
|
40
|
|
|
// Is the actor allowed to view the profile page? |
41
|
|
|
$actorId = $request->get('actorId'); |
42
|
|
|
if ($identityId !== $actorId) { |
43
|
|
|
throw new AccessDeniedHttpException( |
44
|
|
|
"Identity and actor id should match. It is not yet allowed to view the profile of somebody else.", |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$profile = $this->profileService->createProfile($identityId); |
49
|
|
|
if (!$profile instanceof Profile) { |
50
|
|
|
throw new NotFoundHttpException( |
51
|
|
|
"The profile cannot be created, the identity id did not match an identity.", |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
return new JsonResponse($profile); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|