Completed
Pull Request — 4.0 (#3859)
by k-yamamura
06:07
created

onAuthenticationFailure()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 34

Duplication

Lines 6
Ratio 17.65 %

Importance

Changes 0
Metric Value
cc 7
nc 24
nop 2
dl 6
loc 34
rs 8.4426
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Security\Http\Authentication;
15
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpKernel\HttpKernelInterface;
18
use Symfony\Component\Security\Core\Exception\AuthenticationException;
19
use Symfony\Component\Security\Core\Security;
20
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
21
use Symfony\Component\Security\Http\ParameterBagUtils;
22
23
class EccubeAuthenticationFailureHandler extends DefaultAuthenticationFailureHandler
24
{
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
30
    {
31
        if ($failureUrl = ParameterBagUtils::getRequestParameterValue($request, $this->options['failure_path_parameter'])) {
32
            if (preg_match('/^https?:\\\\/i', $failureUrl)) {
33
                $this->options['failure_path'] = '/';
34
            } else {
35
                $this->options['failure_path'] = $failureUrl;
36
            }
37
        }
38
39
        if (null === $this->options['failure_path']) {
40
            $this->options['failure_path'] = $this->options['login_path'];
41
        }
42
43
        if ($this->options['failure_forward']) {
44 View Code Duplication
            if (null !== $this->logger) {
45
                $this->logger->debug('Authentication failure, forward triggered.', array('failure_path' => $this->options['failure_path']));
46
            }
47
48
            $subRequest = $this->httpUtils->createRequest($request, $this->options['failure_path']);
49
            $subRequest->attributes->set(Security::AUTHENTICATION_ERROR, $exception);
50
51
            return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
52
        }
53
54 View Code Duplication
        if (null !== $this->logger) {
55
            $this->logger->debug('Authentication failure, redirect triggered.', array('failure_path' => $this->options['failure_path']));
56
        }
57
58
        $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
59
60
61
        return $this->httpUtils->createRedirectResponse($request, $this->options['failure_path']);
62
    }
63
64
}
65