Passed
Pull Request — main (#308)
by Paul
29:45 queued 20:02
created

GssfAuthenticateController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 43
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 32 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2014 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller\Registration\Gssf;
22
23
use Psr\Log\LoggerInterface;
24
use Surfnet\SamlBundle\Http\RedirectBinding;
25
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory;
26
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ProviderRepository;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService;
28
use Surfnet\StepupSelfService\SelfServiceBundle\Service\GsspUserAttributeService;
0 ignored issues
show
Bug introduced by
The type Surfnet\StepupSelfServic...sspUserAttributeService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
30
use Symfony\Component\HttpFoundation\Response;
31
use Symfony\Component\Routing\Attribute\Route;
32
33
/**
34
 * Controls registration with Generic SAML Stepup Providers (GSSPs), yielding Generic SAML Second Factors (GSSFs).
35
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
36
final class GssfAuthenticateController extends AbstractController
37
{
38
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
39
        private readonly LoggerInterface           $logger,
40
        private readonly ProviderRepository        $providerRepository,
41
        private readonly RedirectBinding           $redirectBinding,
42
        private readonly GsspUserAttributeService  $gsspUserAttributeService,
43
        private readonly ControllerCheckerService  $checkerService,
44
    ) {
45
    }
46
47
    #[Route(
48
        path: '/registration/gssf/{provider}/authenticate',
49
        name: 'ss_registration_gssf_authenticate',
50
        methods: ['POST'],
51
    )]
52
    public function authenticate(string $provider): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function authenticate()
Loading history...
53
    {
54
        $this->checkerService->assertSecondFactorEnabled($provider);
55
56
        $provider = $this->providerRepository->get($provider);
57
58
        $authnRequest = AuthnRequestFactory::createNewRequest(
59
            $provider->getServiceProvider(),
60
            $provider->getRemoteIdentityProvider()
61
        );
62
63
        $this->gsspUserAttributeService->addGsspUserAttributes(
64
            $authnRequest,
65
            $provider,
66
            $this->getUser()->getIdentity()
0 ignored issues
show
Bug introduced by
The method getIdentity() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Surfnet\StepupSelfServic...n\AuthenticatedIdentity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            $this->getUser()->/** @scrutinizer ignore-call */ getIdentity()
Loading history...
67
        );
68
        $stateHandler = $provider->getStateHandler();
69
        $stateHandler->setRequestId($authnRequest->getRequestId());
70
71
        $this->logger->notice(sprintf(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
72
            'Sending AuthnRequest with request ID: "%s" to GSSP "%s" at "%s"',
73
            $authnRequest->getRequestId(),
74
            $provider->getName(),
75
            $provider->getRemoteIdentityProvider()->getSsoUrl()
76
        ));
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
77
78
        return $this->redirectBinding->createResponseFor($authnRequest);
79
    }
80
81
}
82