aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/EventListener
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-06-09 09:45:43 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-09 09:45:43 +0200
commitf81a34e37929a822755d120215d2f18f042ff713 (patch)
tree086049b73cf8d547f18c28963a60f36c5679cfcc /src/Wallabag/UserBundle/EventListener
parentfa1c9d7cc7f3c4d2f9167a5b62bbc8cd1f9df59b (diff)
downloadwallabag-f81a34e37929a822755d120215d2f18f042ff713.tar.gz
wallabag-f81a34e37929a822755d120215d2f18f042ff713.tar.zst
wallabag-f81a34e37929a822755d120215d2f18f042ff713.zip
Use a listener to catch auth failure
Diffstat (limited to 'src/Wallabag/UserBundle/EventListener')
-rw-r--r--src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php
new file mode 100644
index 00000000..10f13233
--- /dev/null
+++ b/src/Wallabag/UserBundle/EventListener/AuthenticationFailureListener.php
@@ -0,0 +1,40 @@
1<?php
2
3namespace Wallabag\UserBundle\EventListener;
4
5use Psr\Log\LoggerInterface;
6use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7use Symfony\Component\HttpFoundation\RequestStack;
8use Symfony\Component\Security\Core\AuthenticationEvents;
9
10class AuthenticationFailureListener implements EventSubscriberInterface
11{
12 private $requestStack;
13 private $logger;
14
15 public function __construct(RequestStack $requestStack, LoggerInterface $logger)
16 {
17 $this->requestStack = $requestStack;
18 $this->logger = $logger;
19 }
20
21 /**
22 * {@inheritdoc}
23 */
24 public static function getSubscribedEvents()
25 {
26 return [
27 AuthenticationEvents::AUTHENTICATION_FAILURE => 'onAuthenticationFailure',
28 ];
29 }
30
31 /**
32 * On failure, add a custom error in log so server admin can configure fail2ban to block IP from people who try to login too much.
33 */
34 public function onAuthenticationFailure()
35 {
36 $request = $this->requestStack->getMasterRequest();
37
38 $this->logger->error('Authentication failure for user "'.$request->request->get('_username').'", from IP "'.$request->getClientIp().'", with UA: "'.$request->server->get('HTTP_USER_AGENT').'".');
39 }
40}