1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Biurad opensource projects. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.4 and above required |
9
|
|
|
* |
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Biurad\Security\Event; |
20
|
|
|
|
21
|
|
|
use Biurad\Security\Interfaces\AuthenticatorInterface; |
22
|
|
|
use Psr\Http\Message\ResponseInterface; |
23
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
24
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
25
|
|
|
use Symfony\Contracts\EventDispatcher\Event; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* This event is dispatched after an error during authentication. |
29
|
|
|
* |
30
|
|
|
* Listeners to this event can change state based on authentication |
31
|
|
|
* failure (e.g. to implement login throttling). |
32
|
|
|
* |
33
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class AuthenticationFailureEvent extends Event |
36
|
|
|
{ |
37
|
|
|
private AuthenticationException $exception; |
38
|
|
|
private AuthenticatorInterface $authenticator; |
39
|
|
|
private ServerRequestInterface $request; |
40
|
|
|
private ?ResponseInterface $response; |
41
|
|
|
|
42
|
|
|
public function __construct(AuthenticationException $exception, AuthenticatorInterface $authenticator, ServerRequestInterface $request, ?ResponseInterface $response) |
43
|
|
|
{ |
44
|
|
|
$this->exception = $exception; |
45
|
|
|
$this->authenticator = $authenticator; |
46
|
|
|
$this->request = $request; |
47
|
|
|
$this->response = $response; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getException(): AuthenticationException |
51
|
|
|
{ |
52
|
|
|
return $this->exception; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getAuthenticator(): AuthenticatorInterface |
56
|
|
|
{ |
57
|
|
|
return $this->authenticator; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getRequest(): ServerRequestInterface |
61
|
|
|
{ |
62
|
|
|
return $this->request; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setResponse(?ResponseInterface $response): void |
66
|
|
|
{ |
67
|
|
|
$this->response = $response; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getResponse(): ?ResponseInterface |
71
|
|
|
{ |
72
|
|
|
return $this->response; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|