IdentityController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 11 2
A collection() 0 14 1
A getRegistrationAuthorityCredentials() 0 13 2
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Controller;
20
21
use Surfnet\Stepup\Identity\Value\Institution;
22
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\IdentityQuery;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\IdentityService;
25
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse;
26
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonNotFoundResponse;
27
use Symfony\Component\HttpFoundation\JsonResponse;
28
use Symfony\Component\HttpFoundation\Request;
29
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30
31
class IdentityController extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class IdentityController
Loading history...
32
{
33
    public function __construct(
34
        private readonly IdentityService $identityService,
35
    ) {
36
    }
37
38
    public function get(string $id): JsonResponse
39
    {
40
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
41
42
        $identity = $this->identityService->find($id);
43
44
        if (!$identity instanceof Identity) {
45
            throw new NotFoundHttpException(sprintf("Identity '%s' does not exist", $id));
46
        }
47
48
        return new JsonResponse($identity);
49
    }
50
51
    public function collection(Request $request, Institution $institution): JsonCollectionResponse
52
    {
53
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
54
55
        $query = new IdentityQuery();
56
        $query->institution = $institution;
57
        $query->nameId = $request->get('NameID');
58
        $query->commonName = $request->get('commonName');
59
        $query->email = $request->get('email');
60
        $query->pageNumber = (int)$request->get('p', 1);
61
62
        $paginator = $this->identityService->search($query);
63
64
        return JsonCollectionResponse::fromPaginator($paginator);
65
    }
66
67
    public function getRegistrationAuthorityCredentials(string $identityId): JsonResponse
68
    {
69
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
70
71
        $identityService = $this->identityService;
72
73
        $credentials = $identityService->findRegistrationAuthorityCredentialsOf($identityId);
74
75
        if (!$credentials instanceof \Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RegistrationAuthorityCredentials) {
76
            return new JsonNotFoundResponse();
77
        }
78
79
        return new JsonResponse($credentials);
80
    }
81
}
82