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