1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2018 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; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* AvailableTokenCollection is used in the display second factor types view to be able to handle GSSP and non GSSP |
25
|
|
|
* tokens in a more homogeneous manner. |
26
|
|
|
*/ |
|
|
|
|
27
|
|
|
class AvailableTokenCollection |
28
|
|
|
{ |
29
|
|
|
/** |
|
|
|
|
30
|
|
|
* @var AvailableTokenInterface[] |
31
|
|
|
*/ |
32
|
|
|
private array $collection = []; |
|
|
|
|
33
|
|
|
|
34
|
|
|
public static function from(array $builtInTokens, array $gsspTokens): self |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$collection = new self(); |
37
|
|
|
|
38
|
|
|
foreach ($builtInTokens as $token) { |
39
|
|
|
$collection->collection[$token] = BuiltInToken::fromSecondFactorType($token); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
foreach ($gsspTokens as $type => $token) { |
43
|
|
|
$collection->collection[$type] = GsspToken::fromViewConfig($token, $type); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $collection; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Sorts and returns the available tokens |
51
|
|
|
* @return AvailableTokenInterface[] |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
public function getData(): array |
54
|
|
|
{ |
55
|
|
|
$this->sortCollection(); |
56
|
|
|
return $this->collection; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function sortCollection(): void |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
// The collection is first sorted by LoA level and then in alphabetic order. |
62
|
|
|
uasort($this->collection, function (AvailableTokenInterface $a, AvailableTokenInterface $b): int { |
|
|
|
|
63
|
|
|
if ($a->getLoaLevel() === $b->getLoaLevel()) { |
64
|
|
|
return strcmp((string) $a->getType(), (string) $b->getType()); |
65
|
|
|
} |
66
|
|
|
return $a->getLoaLevel() > $b->getLoaLevel() ? 1 : -1; |
67
|
|
|
}); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|