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\Configuration\Service; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
22
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionConfigurationOptions; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionConfigurationOptionsRepository; |
24
|
|
|
|
25
|
|
|
class InstitutionConfigurationOptionsService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var InstitutionConfigurationOptionsRepository |
29
|
|
|
*/ |
30
|
|
|
private $repository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
private $numberOfTokensPerIdentity; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param InstitutionConfigurationOptionsRepository $repository |
39
|
|
|
* @param int $numberOfTokensPerIdentity |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
InstitutionConfigurationOptionsRepository $repository, |
43
|
|
|
$numberOfTokensPerIdentity |
44
|
|
|
) { |
45
|
|
|
$this->repository = $repository; |
46
|
|
|
$this->numberOfTokensPerIdentity = $numberOfTokensPerIdentity; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return InstitutionConfigurationOptions[] |
51
|
|
|
*/ |
52
|
|
|
public function findAllInstitutionConfigurationOptions() |
53
|
|
|
{ |
54
|
|
|
return $this->repository->findAll(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Institution $institution |
59
|
|
|
* @return InstitutionConfigurationOptions |
60
|
|
|
*/ |
61
|
|
|
public function findInstitutionConfigurationOptionsFor(Institution $institution) |
62
|
|
|
{ |
63
|
|
|
return $this->repository->findConfigurationOptionsFor($institution); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Retrieve the number of tokens an identity is allowed to register/vet for a given institution. |
68
|
|
|
* |
69
|
|
|
* When the DISABLED value is set on the institution (when no specific configuration was pushed) the application |
70
|
|
|
* default is returned. |
71
|
|
|
* |
72
|
|
|
* @param Institution $institution |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
public function getMaxNumberOfTokensFor(Institution $institution) |
76
|
|
|
{ |
77
|
|
|
$configuration = $this->findInstitutionConfigurationOptionsFor($institution); |
78
|
|
|
|
79
|
|
|
if ($configuration->numberOfTokensPerIdentityOption->isEnabled()) { |
80
|
|
|
return $configuration->numberOfTokensPerIdentityOption->getNumberOfTokensPerIdentity(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// Return the application globally set default when no institution specific value was set |
84
|
|
|
return $this->numberOfTokensPerIdentity; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|