diff options
author | Jeremy <j0k3r@users.noreply.github.com> | 2015-02-10 13:49:57 +0100 |
---|---|---|
committer | Jeremy <j0k3r@users.noreply.github.com> | 2015-02-10 13:49:57 +0100 |
commit | 2c0ffcf3972e2f58267b805a26835f452e016761 (patch) | |
tree | b1146d6a9b98bb2ce238fff10fed4a1bf872c4b4 /src/Wallabag/CoreBundle/Security/Firewall | |
parent | cbce162b407024882d8c37a7e3298c85175d2651 (diff) | |
parent | 92504e0dd489c0d11abc87bee42ffca717db0480 (diff) | |
download | wallabag-2c0ffcf3972e2f58267b805a26835f452e016761.tar.gz wallabag-2c0ffcf3972e2f58267b805a26835f452e016761.tar.zst wallabag-2c0ffcf3972e2f58267b805a26835f452e016761.zip |
Merge pull request #1068 from wallabag/v2-api-authentication
V2 api authentication
Diffstat (limited to 'src/Wallabag/CoreBundle/Security/Firewall')
-rw-r--r-- | src/Wallabag/CoreBundle/Security/Firewall/WsseListener.php | 17 |
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; | |||
9 | use Symfony\Component\Security\Core\SecurityContextInterface; | 9 | use Symfony\Component\Security\Core\SecurityContextInterface; |
10 | use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; | 10 | use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; |
11 | use Wallabag\CoreBundle\Security\Authentication\Token\WsseUserToken; | 11 | use Wallabag\CoreBundle\Security\Authentication\Token\WsseUserToken; |
12 | use Psr\Log\LoggerInterface; | ||
12 | 13 | ||
13 | class WsseListener implements ListenerInterface | 14 | class 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 | } |