aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php')
-rw-r--r--src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php b/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php
index 4d4f2145..6ffdfaf0 100644
--- a/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php
+++ b/src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php
@@ -9,16 +9,19 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException;
9use Symfony\Component\Security\Core\SecurityContextInterface; 9use Symfony\Component\Security\Core\SecurityContextInterface;
10use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; 10use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
11use Wallabag\CoreBundle\Security\Authentication\Token\WsseUserToken; 11use Wallabag\CoreBundle\Security\Authentication\Token\WsseUserToken;
12use Psr\Log\LoggerInterface;
12 13
13class WsseListener implements ListenerInterface 14class WsseListener implements ListenerInterface
14{ 15{
15 protected $securityContext; 16 protected $securityContext;
16 protected $authenticationManager; 17 protected $authenticationManager;
18 protected $logger;
17 19
18 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager) 20 public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger)
19 { 21 {
20 $this->securityContext = $securityContext; 22 $this->securityContext = $securityContext;
21 $this->authenticationManager = $authenticationManager; 23 $this->authenticationManager = $authenticationManager;
24 $this->logger = $logger;
22 } 25 }
23 26
24 public function handle(GetResponseEvent $event) 27 public function handle(GetResponseEvent $event)
@@ -41,17 +44,19 @@ class WsseListener implements ListenerInterface
41 $authToken = $this->authenticationManager->authenticate($token); 44 $authToken = $this->authenticationManager->authenticate($token);
42 45
43 $this->securityContext->setToken($authToken); 46 $this->securityContext->setToken($authToken);
44 } catch (AuthenticationException $failed) {
45 // ... you might log something here
46 47
47 // To deny the authentication clear the token. This will redirect to the login page. 48 return;
48 // $this->securityContext->setToken(null); 49 } catch (AuthenticationException $failed) {
49 // return; 50 $failedMessage = 'WSSE Login failed for '.$token->getUsername().'. Why ? '.$failed->getMessage();
51 $this->logger->err($failedMessage);
50 52
51 // Deny authentication with a '403 Forbidden' HTTP response 53 // Deny authentication with a '403 Forbidden' HTTP response
52 $response = new Response(); 54 $response = new Response();
53 $response->setStatusCode(403); 55 $response->setStatusCode(403);
56 $response->setContent($failedMessage);
54 $event->setResponse($response); 57 $event->setResponse($response);
58
59 return;
55 } 60 }
56 } 61 }
57} 62}