|
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\Identity\Value; |
|
20
|
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionRole; |
|
22
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
|
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionAuthorization; |
|
24
|
|
|
|
|
25
|
|
|
class AuthorizedInstitutionCollection |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* The institution this collection represents |
|
29
|
|
|
* @var Institution |
|
30
|
|
|
*/ |
|
31
|
|
|
private $institution; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The related institutions |
|
35
|
|
|
* @var Institution[] |
|
36
|
|
|
*/ |
|
37
|
|
|
private $institutions = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Mapped on institution, a list of authorizations for the institution relation |
|
41
|
|
|
* |
|
42
|
|
|
* @example |
|
43
|
|
|
* [ |
|
44
|
|
|
* 'institution-1' => [use_ra, use_raa, select_raa], |
|
45
|
|
|
* 'institution-2' => [use_ra], |
|
46
|
|
|
* 'institution-3' => [select_raa], |
|
47
|
|
|
* ] |
|
48
|
|
|
* |
|
49
|
|
|
* @var InstitutionRole[] |
|
50
|
|
|
*/ |
|
51
|
|
|
private $authorizations = []; |
|
52
|
|
|
|
|
53
|
|
|
public function __construct(Institution $institution) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->institution = $institution; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param Institution $institution |
|
60
|
|
|
* @param InstitutionAuthorization[] $authorizations |
|
61
|
|
|
* @return AuthorizedInstitutionCollection |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function fromInstitutionAuthorization(Institution $institution, $authorizations) |
|
64
|
|
|
{ |
|
65
|
|
|
$collection = new self($institution); |
|
66
|
|
|
|
|
67
|
|
|
foreach ($authorizations as $authorization) { |
|
68
|
|
|
$collection->institutions[(string) $authorization->institutionRelation] = $authorization->institutionRelation; |
|
69
|
|
|
$collection->authorizations[(string) $authorization->institutionRelation][] = $authorization->institutionRole; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $collection; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getInstitutions() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->institutions; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getAuthorizations() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->authorizations; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|