|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2017 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\Stepup\Configuration\Value; |
|
20
|
|
|
|
|
21
|
|
|
use ArrayIterator; |
|
22
|
|
|
use IteratorAggregate; |
|
23
|
|
|
use JsonSerializable; |
|
24
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
25
|
|
|
|
|
26
|
|
|
final class AllowedSecondFactorList implements JsonSerializable, IteratorAggregate |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var SecondFactor[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private $allowedSecondFactors; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(array $allowedSecondFactors) |
|
34
|
|
|
{ |
|
35
|
|
|
foreach ($allowedSecondFactors as $allowedSecondFactor) { |
|
36
|
|
|
if (!$allowedSecondFactor instanceof SecondFactor) { |
|
37
|
|
|
throw InvalidArgumentException::invalidType( |
|
38
|
|
|
SecondFactor::class, |
|
39
|
|
|
'allowedSecondFactor', |
|
40
|
|
|
$allowedSecondFactor |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->allowedSecondFactors = $allowedSecondFactors; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param SecondFactor $other |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
|
|
public function isAllowed(SecondFactor $other) |
|
53
|
|
|
{ |
|
54
|
|
|
if (empty($this->allowedSecondFactors)) { |
|
55
|
|
|
return true; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
foreach ($this->allowedSecondFactors as $secondFactorType) { |
|
59
|
|
|
if ($secondFactorType->equals($other)) { |
|
|
|
|
|
|
60
|
|
|
return true; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getIterator() |
|
68
|
|
|
{ |
|
69
|
|
|
return new ArrayIterator($this->allowedSecondFactors); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function jsonSerialize() |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
|
|
'allowedSecondFactors' => $this->allowedSecondFactors |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: