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

EccubeAuthenticationFailureHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 6
loc 42
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B onAuthenticationFailure() 6 34 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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