LoginFailureHandler::onAuthenticationFailure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\AppBundle\Security;
14
15
use Symfony\Component\HttpFoundation\RedirectResponse;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\Routing\RouterInterface;
18
use Symfony\Component\Security\Core\Exception\AuthenticationException;
19
use Symfony\Component\Security\Core\Security;
20
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
21
22
/**
23
 * Class LoginFailureHandler
24
 *
25
 * @author  Adam Piotrowski <[email protected]>
26
 */
27
final class LoginFailureHandler implements AuthenticationFailureHandlerInterface
28
{
29
    /**
30
     * @var RouterInterface
31
     */
32
    private $router;
33
    
34
    /**
35
     * @var string
36
     */
37
    private $loginRoute;
38
    
39
    public function __construct(RouterInterface $router, string $loginRoute)
40
    {
41
        $this->router     = $router;
42
        $this->loginRoute = $loginRoute;
43
    }
44
    
45
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
46
    {
47
        $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
48
        
49
        return new RedirectResponse($this->router->generate($this->loginRoute));
50
    }
51
}
52