1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2022 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\Service\SelfAssertedTokens; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @SuppressWarnings(PHPMD.TooManyMethods) |
23
|
|
|
*/ |
24
|
|
|
final class ProofOfPossessionResult |
25
|
|
|
{ |
26
|
|
|
const STATUS_CHALLENGE_OK = 0; |
27
|
|
|
const STATUS_INCORRECT_CHALLENGE = 1; |
28
|
|
|
const STATUS_CHALLENGE_EXPIRED = 2; |
29
|
|
|
const STATUS_TOO_MANY_ATTEMPTS = 3; |
30
|
|
|
|
31
|
|
|
private $status; |
32
|
|
|
|
33
|
|
|
private $recoveryTokenId; |
34
|
|
|
|
35
|
|
|
private function __construct(int $status, ?string $recoveryTokenId = null) |
36
|
|
|
{ |
37
|
|
|
$this->recoveryTokenId = $recoveryTokenId; |
38
|
|
|
$this->status = $status; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function challengeExpired(): ProofOfPossessionResult |
42
|
|
|
{ |
43
|
|
|
return new self(self::STATUS_CHALLENGE_EXPIRED); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function incorrectChallenge(): ProofOfPossessionResult |
47
|
|
|
{ |
48
|
|
|
return new self(self::STATUS_INCORRECT_CHALLENGE); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function proofOfPossessionCommandFailed(): ProofOfPossessionResult |
52
|
|
|
{ |
53
|
|
|
return new self(self::STATUS_CHALLENGE_OK); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function recoveryTokenCreated(string $recoveryTokenId): ProofOfPossessionResult |
57
|
|
|
{ |
58
|
|
|
return new self(self::STATUS_CHALLENGE_OK, $recoveryTokenId); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public static function recoveryTokenVerified(): ProofOfPossessionResult |
62
|
|
|
{ |
63
|
|
|
return new self(self::STATUS_CHALLENGE_OK); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public static function tooManyAttempts(): ProofOfPossessionResult |
67
|
|
|
{ |
68
|
|
|
return new self(self::STATUS_TOO_MANY_ATTEMPTS); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function isSuccessful(): bool |
72
|
|
|
{ |
73
|
|
|
return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId !== null; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function authenticated(): bool |
77
|
|
|
{ |
78
|
|
|
return $this->status === self::STATUS_CHALLENGE_OK; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function didProofOfPossessionFail(): bool |
82
|
|
|
{ |
83
|
|
|
return $this->status === self::STATUS_CHALLENGE_OK && $this->recoveryTokenId === null; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function wasIncorrectChallengeResponseGiven(): bool |
87
|
|
|
{ |
88
|
|
|
return $this->status === self::STATUS_INCORRECT_CHALLENGE; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function hasChallengeExpired(): bool |
92
|
|
|
{ |
93
|
|
|
return $this->status === self::STATUS_CHALLENGE_EXPIRED; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function wereTooManyAttemptsMade(): bool |
97
|
|
|
{ |
98
|
|
|
return $this->status === self::STATUS_TOO_MANY_ATTEMPTS; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|