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\InstitutionAuthorization; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionAuthorizationRepository; |
24
|
|
|
|
25
|
|
|
class InstitutionAuthorizationService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var InstitutionAuthorizationRepository |
29
|
|
|
*/ |
30
|
|
|
private $repository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param InstitutionAuthorizationRepository $repository |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
InstitutionAuthorizationRepository $repository |
37
|
|
|
) { |
38
|
|
|
$this->repository = $repository; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Institution $institution |
43
|
|
|
* @param Institution $for |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function canInstitutionUseRaFor(Institution $institution, Institution $for) |
47
|
|
|
{ |
48
|
|
|
$authorization = $this->findAuthorizationFor($institution); |
49
|
|
|
return $authorization->useRaOption->hasOptions() && $authorization->useRaOption->isOption($for->getInstitution()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Institution $institution |
54
|
|
|
* @param Institution $for |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function canInstitutionUseRaaFor(Institution $institution, Institution $for) |
58
|
|
|
{ |
59
|
|
|
$authorization = $this->findAuthorizationFor($institution); |
60
|
|
|
return $authorization->useRaaOption->hasOptions() && $authorization->useRaaOption->isOption($for->getInstitution()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Institution $institution |
65
|
|
|
* @param Institution $for |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function canInstitutionSelectRaaFor(Institution $institution, Institution $for) |
69
|
|
|
{ |
70
|
|
|
$authorization = $this->findAuthorizationFor($institution); |
71
|
|
|
return $authorization->selectRaaOption->hasOptions() && $authorization->selectRaaOption->isOption($for->getInstitution()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param Institution $institution |
76
|
|
|
* @return InstitutionAuthorization |
77
|
|
|
*/ |
78
|
|
|
private function findAuthorizationFor(Institution $institution) |
79
|
|
|
{ |
80
|
|
|
return $this->repository->findAuthorizationOptionsForInstitution($institution); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|