1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 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\Stepup\Identity\Value; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Exception\LogicException; |
22
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
23
|
|
|
|
24
|
|
|
final class SecondFactorIdentifierFactory |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param SecondFactorType $type |
28
|
|
|
* @param string $secondFactorIdentifier |
29
|
|
|
* @return SecondFactorIdentifier |
30
|
|
|
*/ |
31
|
|
|
public static function forType(SecondFactorType $type, $secondFactorIdentifier) |
32
|
|
|
{ |
33
|
|
|
if ($type->isSms()) { |
34
|
|
|
return new PhoneNumber($secondFactorIdentifier); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($type->isYubikey()) { |
38
|
|
|
return new YubikeyPublicId($secondFactorIdentifier); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($type->isGssf()) { |
42
|
|
|
return new GssfId($secondFactorIdentifier); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($type->isU2f()) { |
46
|
|
|
return new U2fKeyHandle($secondFactorIdentifier); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
throw new LogicException(sprintf('Unknown second factor type "%s" encountered', $type->getSecondFactorType())); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param SecondFactorType $type |
54
|
|
|
* @return SecondFactorIdentifier |
55
|
|
|
*/ |
56
|
|
|
public static function unknownForType(SecondFactorType $type) |
57
|
|
|
{ |
58
|
|
|
if ($type->isSms()) { |
59
|
|
|
return PhoneNumber::unknown(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($type->isYubikey()) { |
63
|
|
|
return YubikeyPublicId::unknown(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($type->isGssf()) { |
67
|
|
|
return GssfId::unknown(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($type->isU2f()) { |
71
|
|
|
return U2fKeyHandle::unknown(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
throw new LogicException(sprintf('Unknown second factor type "%s" encountered', $type->getSecondFactorType())); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|