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\Identity\Collection\InstitutionCollection; |
22
|
|
|
|
23
|
|
|
class AuthorizedInstitutionCollection |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Mapped on institution, a list of authorizations for the institution relation |
27
|
|
|
* |
28
|
|
|
* @example |
29
|
|
|
* [ |
30
|
|
|
* 'institution-1' => [use_ra, use_raa, select_raa], |
31
|
|
|
* 'institution-2' => [use_ra], |
32
|
|
|
* 'institution-3' => [select_raa], |
33
|
|
|
* ] |
34
|
|
|
* |
35
|
|
|
* @var string[] |
36
|
|
|
*/ |
37
|
|
|
private $authorizations = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param InstitutionCollection $raInstitutions |
41
|
|
|
* @param InstitutionCollection|null $raaInstitutions |
42
|
|
|
* @return AuthorizedInstitutionCollection |
43
|
|
|
*/ |
44
|
|
|
public static function from(InstitutionCollection $raInstitutions, InstitutionCollection $raaInstitutions = null) |
45
|
|
|
{ |
46
|
|
|
$collection = new self(); |
47
|
|
|
|
48
|
|
|
foreach ($raInstitutions as $institution) { |
49
|
|
|
$collection->authorizations[(string) $institution][] = (string) AuthorityRole::ROLE_RA; |
50
|
|
|
} |
51
|
|
|
if ($raaInstitutions) { |
52
|
|
|
foreach ($raaInstitutions as $institution) { |
53
|
|
|
// Override existing lower role |
54
|
|
|
if (isset($collection->authorizations[(string) $institution]) |
55
|
|
|
&& in_array(AuthorityRole::ROLE_RA, $collection->authorizations[(string) $institution]) |
56
|
|
|
) { |
57
|
|
|
$collection->authorizations[(string) $institution] = []; |
58
|
|
|
} |
59
|
|
|
$collection->authorizations[(string) $institution][] = (string) AuthorityRole::ROLE_RAA; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
return $collection; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getAuthorizations() |
66
|
|
|
{ |
67
|
|
|
return $this->authorizations; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|