|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2016 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\Stepup\Configuration\Value\Institution; |
|
22
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionRole; |
|
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionConfigurationOptions; |
|
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\AllowedSecondFactorListService; |
|
25
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionAuthorizationService; |
|
26
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService; |
|
27
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Controller\AbstractController; |
|
28
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
29
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
30
|
|
|
|
|
31
|
|
|
final class InstitutionConfigurationOptionsController extends AbstractController |
|
32
|
|
|
{ |
|
33
|
|
|
public function __construct( |
|
34
|
|
|
private readonly InstitutionConfigurationOptionsService $institutionConfigurationOptionsService, |
|
35
|
|
|
private readonly InstitutionAuthorizationService $institutionAuthorizationService, |
|
36
|
|
|
private readonly AllowedSecondFactorListService $allowedSecondFactorListService, |
|
37
|
|
|
) { |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getForInstitution(string $institutionName): JsonResponse |
|
41
|
|
|
{ |
|
42
|
|
|
$this->denyAccessUnlessGrantedOneOff(['ROLE_SS', 'ROLE_RA', 'ROLE_READ']); |
|
43
|
|
|
|
|
44
|
|
|
$institution = new Institution($institutionName); |
|
45
|
|
|
|
|
46
|
|
|
$institutionConfigurationOptions = $this |
|
47
|
|
|
->institutionConfigurationOptionsService |
|
48
|
|
|
->findInstitutionConfigurationOptionsFor($institution); |
|
49
|
|
|
|
|
50
|
|
|
$allowedSecondFactorList = $this |
|
51
|
|
|
->allowedSecondFactorListService |
|
52
|
|
|
->getAllowedSecondFactorListFor($institution); |
|
53
|
|
|
|
|
54
|
|
|
if (!$institutionConfigurationOptions instanceof InstitutionConfigurationOptions) { |
|
55
|
|
|
throw new NotFoundHttpException( |
|
56
|
|
|
sprintf('No institution configuration options found for institution "%s"', $institution), |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$numberOfTokensPerIdentity = $this |
|
61
|
|
|
->institutionConfigurationOptionsService |
|
62
|
|
|
->getMaxNumberOfTokensFor($institution); |
|
63
|
|
|
|
|
64
|
|
|
// Get the authorization options for this institution |
|
65
|
|
|
$institutionConfigurationOptionsMap = $this->institutionAuthorizationService |
|
66
|
|
|
->findAuthorizationsFor($institution); |
|
67
|
|
|
|
|
68
|
|
|
return new JsonResponse([ |
|
69
|
|
|
'institution' => $institutionConfigurationOptions->institution, |
|
70
|
|
|
'use_ra_locations' => $institutionConfigurationOptions->useRaLocationsOption, |
|
71
|
|
|
'show_raa_contact_information' => $institutionConfigurationOptions->showRaaContactInformationOption, |
|
72
|
|
|
'verify_email' => $institutionConfigurationOptions->verifyEmailOption, |
|
73
|
|
|
'sso_on_2fa' => $institutionConfigurationOptions->ssoOn2faOption, |
|
74
|
|
|
'sso_registration_bypass' => $institutionConfigurationOptions->ssoRegistrationBypassOption, |
|
75
|
|
|
'self_vet' => $institutionConfigurationOptions->selfVetOption, |
|
76
|
|
|
'allow_self_asserted_tokens' => $institutionConfigurationOptions->selfAssertedTokensOption, |
|
77
|
|
|
'number_of_tokens_per_identity' => $numberOfTokensPerIdentity, |
|
78
|
|
|
'allowed_second_factors' => $allowedSecondFactorList, |
|
79
|
|
|
'use_ra' => $institutionConfigurationOptionsMap->getAuthorizationOptionsByRole( |
|
80
|
|
|
InstitutionRole::useRa(), |
|
81
|
|
|
)->jsonSerialize(), |
|
82
|
|
|
'use_raa' => $institutionConfigurationOptionsMap->getAuthorizationOptionsByRole( |
|
83
|
|
|
InstitutionRole::useRaa(), |
|
84
|
|
|
)->jsonSerialize(), |
|
85
|
|
|
'select_raa' => $institutionConfigurationOptionsMap->getAuthorizationOptionsByRole( |
|
86
|
|
|
InstitutionRole::selectRaa(), |
|
87
|
|
|
)->jsonSerialize(), |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|