|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the U2F Security bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Michael Barbey <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Mbarbey\U2fSecurityBundle\Event\Authentication; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
15
|
|
|
use Mbarbey\U2fSecurityBundle\Model\User\U2fUserInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* U2F authentication failure event |
|
19
|
|
|
* |
|
20
|
|
|
* An event dispatched when a user fail to authenticate with it U2F security key. |
|
21
|
|
|
* |
|
22
|
|
|
* This event contain the user, an error message and the number of time the user failed to authenticate consecutively. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Michael Barbey <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class U2fAuthenticationFailureEvent extends Event |
|
27
|
|
|
{ |
|
28
|
|
|
private $user; |
|
29
|
|
|
private $error; |
|
30
|
|
|
private $failureCounter; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Return the name of the event to use when dispatching this event. |
|
34
|
|
|
* |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public static function getName() |
|
38
|
|
|
{ |
|
39
|
1 |
|
return 'u2f.authentication.failure'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param U2fUserInterface $user The user who failed to authenticate |
|
44
|
|
|
* @param \Exception $error The exception which triggered the failure |
|
45
|
|
|
* @param int $failureCounter The number of consecutive fails of this user |
|
46
|
|
|
*/ |
|
47
|
4 |
|
public function __construct(U2fUserInterface $user, \Exception $error, $failureCounter = 1) |
|
48
|
|
|
{ |
|
49
|
4 |
|
$this->user = $user; |
|
50
|
4 |
|
$this->error = $error; |
|
51
|
4 |
|
$this->failureCounter = $failureCounter; |
|
52
|
4 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Return the user who failed to authenticate. |
|
56
|
|
|
* |
|
57
|
|
|
* @return U2fUserInterface |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getUser() |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->user; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Return the exception which triggered the failure |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Exception |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function getError() |
|
70
|
|
|
{ |
|
71
|
1 |
|
return $this->error; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return the number of consecutive times the user failed to authenticate. |
|
76
|
|
|
* |
|
77
|
|
|
* @return int |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function getFailureCounter() |
|
80
|
|
|
{ |
|
81
|
1 |
|
return $this->failureCounter; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|