1 | <?php |
||||
2 | /* |
||||
3 | * Copyright (C) 2020 Jan Böhmer |
||||
4 | * |
||||
5 | * This program is free software: you can redistribute it and/or modify |
||||
6 | * it under the terms of the GNU Affero General Public License as published |
||||
7 | * by the Free Software Foundation, either version 3 of the License, or |
||||
8 | * (at your option) any later version. |
||||
9 | * |
||||
10 | * This program is distributed in the hope that it will be useful, |
||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
13 | * GNU Affero General Public License for more details. |
||||
14 | * |
||||
15 | * You should have received a copy of the GNU Affero General Public License |
||||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
17 | */ |
||||
18 | |||||
19 | namespace App\EventSubscriber; |
||||
20 | |||||
21 | use Psr\Log\LoggerInterface; |
||||
22 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
||||
23 | use Symfony\Component\HttpFoundation\RequestStack; |
||||
24 | use Symfony\Component\Security\Core\AuthenticationEvents; |
||||
25 | use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent; |
||||
26 | |||||
27 | /** |
||||
28 | * This event subscriber. |
||||
29 | */ |
||||
30 | class Fail2BanSubscriber implements EventSubscriberInterface |
||||
31 | { |
||||
32 | /** |
||||
33 | * @var LoggerInterface |
||||
34 | */ |
||||
35 | private $logger; |
||||
36 | |||||
37 | /** |
||||
38 | * @var RequestStack |
||||
39 | */ |
||||
40 | private $request; |
||||
41 | |||||
42 | public function __construct(LoggerInterface $fail2banLogger, RequestStack $request) |
||||
43 | { |
||||
44 | $this->logger = $fail2banLogger; |
||||
45 | $this->request = $request; |
||||
46 | } |
||||
47 | |||||
48 | public function logFail2Ban(AuthenticationFailureEvent $event): void |
||||
0 ignored issues
–
show
|
|||||
49 | { |
||||
50 | $ipAddress = $this->request->getCurrentRequest() |
||||
51 | ->getClientIp(); |
||||
52 | $this->logger->error('Authentication failed for IP: '.$ipAddress); |
||||
53 | } |
||||
54 | |||||
55 | public static function getSubscribedEvents(): array |
||||
56 | { |
||||
57 | return [ |
||||
58 | AuthenticationEvents::AUTHENTICATION_FAILURE => [ |
||||
0 ignored issues
–
show
The constant
Symfony\Component\Securi...:AUTHENTICATION_FAILURE has been deprecated: since Symfony 5.4, use {@see Event\LoginFailureEvent} instead
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead. ![]() |
|||||
59 | 'logFail2Ban', |
||||
60 | ], |
||||
61 | ]; |
||||
62 | } |
||||
63 | } |
||||
64 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.