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

ContextInvalidationLogoutHandler::logout()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
crap 6
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