|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2022 SURFnet bv |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType; |
|
22
|
|
|
|
|
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\ActivationFlowPreferenceInterface; |
|
24
|
|
|
|
|
25
|
|
|
class VettingTypeCollection |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
|
|
|
|
|
28
|
|
|
* @var VettingTypeInterface[] |
|
29
|
|
|
*/ |
|
30
|
|
|
private array $collection = []; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function add(VettingTypeInterface $vettingType): void |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$this->collection[$vettingType->identifier()] = $vettingType; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function expressVettingPreference(ActivationFlowPreferenceInterface $preference): void |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
switch ((string) $preference) { |
|
40
|
|
|
case 'ra': |
|
|
|
|
|
|
41
|
|
|
if (array_key_exists(VettingTypeInterface::ON_PREMISE, $this->collection)) { |
|
|
|
|
|
|
42
|
|
|
$this->collection[VettingTypeInterface::ON_PREMISE]->setPrefered(); |
|
43
|
|
|
} |
|
|
|
|
|
|
44
|
|
|
break; |
|
45
|
|
|
case 'self': |
|
|
|
|
|
|
46
|
|
|
if (array_key_exists(VettingTypeInterface::SELF_ASSERTED_TOKENS, $this->collection)) { |
|
|
|
|
|
|
47
|
|
|
$this->collection[VettingTypeInterface::SELF_ASSERTED_TOKENS]->setPrefered(); |
|
48
|
|
|
} |
|
|
|
|
|
|
49
|
|
|
break; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function allowSelfVetting(): bool |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
return array_key_exists(VettingTypeInterface::SELF_VET, $this->collection); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function allowSelfAssertedTokens(): bool |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
return array_key_exists(VettingTypeInterface::SELF_ASSERTED_TOKENS, $this->collection); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function isPreferred(string $vettingType): bool |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
if (!array_key_exists($vettingType, $this->collection)) { |
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
return $this->collection[$vettingType]->isPrefered(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|