Completed
Pull Request — master (#390)
by Wesley
03:57
created

ContextInvalidationLogoutHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 41.67%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 49
ccs 5
cts 12
cp 0.4167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A logout() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Security\Http\Logout;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\BanCapable;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
19
20
class ContextInvalidationLogoutHandler implements LogoutHandlerInterface
21
{
22
    /**
23
     * Service used to ban hash request.
24
     *
25
     * @var \FOS\HttpCache\ProxyClient\Invalidation\BanCapable
26
     */
27
    private $banner;
28
29
    /**
30
     * Accept header.
31
     *
32
     * @var string
33
     */
34
    private $acceptHeader;
35
36
    /**
37
     * User identifier headers.
38
     *
39
     * @var string[]
40
     */
41
    private $userIdentifierHeaders;
42
43 1
    public function __construct(BanCapable $banner, $userIdentifierHeaders, $acceptHeader)
44
    {
45 1
        $this->banner = $banner;
46 1
        $this->acceptHeader = $acceptHeader;
47 1
        $this->userIdentifierHeaders = $userIdentifierHeaders;
48 1
    }
49
50
    /**
51
     * Invalidate the user context hash.
52
     *
53
     * @param Request        $request
54
     * @param Response       $response
55
     * @param TokenInterface $token
56
     */
57
    public function logout(Request $request, Response $response, TokenInterface $token)
58
    {
59
        $sessionId = $request->getSession()->getId();
60
61
        foreach ($this->userIdentifierHeaders as $header) {
62
            $this->banner->ban([
63
                'accept' => $this->acceptHeader,
64
                $header => sprintf('.*%s.*', $sessionId),
65
            ]);
66
        }
67
    }
68
}
69