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