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 required event |
19
|
|
|
* |
20
|
|
|
* An event dispatcher when a user successfully log-in with it basic username/password and own one or more |
21
|
|
|
* U2F security key(s). |
22
|
|
|
* |
23
|
|
|
* This event aim to allow subscribers to define if this user must not being forced to authenticate with a second factor. |
24
|
|
|
* |
25
|
|
|
* This event contain the user and an abort function allowing to cancel the request for a fully U2F authentication. |
26
|
|
|
* |
27
|
|
|
* @author Michael Barbey <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
class U2fAuthenticationRequiredEvent extends Event |
31
|
|
|
{ |
32
|
|
|
private $user; |
33
|
|
|
private $mustAuthenticate = true; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Return the name of the event to use when dispatching this event. |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
1 |
|
public static function getName() |
41
|
|
|
{ |
42
|
1 |
|
return 'u2f.authentication.required'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param U2fUserInterface $user The user who will be requested to authenticate with a security key |
47
|
|
|
*/ |
48
|
4 |
|
public function __construct(U2fUserInterface $user) |
49
|
|
|
{ |
50
|
4 |
|
$this->user = $user; |
51
|
4 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Return the user who successfully logged-in with it basic username/password. |
55
|
|
|
* |
56
|
|
|
* @return U2fUserInterface |
57
|
|
|
*/ |
58
|
1 |
|
public function getUser() |
59
|
|
|
{ |
60
|
1 |
|
return $this->user; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Inform that even if this user has one or more U2F security key(s), it must be redirected |
65
|
|
|
* to the U2F authentication page. |
66
|
|
|
* |
67
|
|
|
* Calling this function stop the propagation of the event. |
68
|
|
|
*/ |
69
|
1 |
|
public function abort() |
70
|
|
|
{ |
71
|
1 |
|
$this->mustAuthenticate = false; |
72
|
1 |
|
$this->stopPropagation(); |
73
|
1 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Return if the U2F authentication request must be aborted or not. |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
2 |
|
public function mustAuthenticate() |
81
|
|
|
{ |
82
|
2 |
|
return $this->mustAuthenticate; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|