Passed
Pull Request — main (#308)
by Paul
18:42 queued 09:10
created

GssfAuthenticateController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 5
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2023 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
            false,
62
            'isGssfRequest'
63
        );
64
65
        $this->gsspUserAttributeService->addGsspUserAttributes(
66
            $authnRequest,
67
            $provider,
68
            $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

68
            $this->getUser()->/** @scrutinizer ignore-call */ getIdentity()
Loading history...
69
        );
70
        $stateHandler = $provider->getStateHandler();
71
        $stateHandler->setRequestId($authnRequest->getRequestId());
72
73
        $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...
74
            'Sending AuthnRequest with request ID: "%s" to GSSP "%s" at "%s"',
75
            $authnRequest->getRequestId(),
76
            $provider->getName(),
77
            $provider->getRemoteIdentityProvider()->getSsoUrl()
78
        ));
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...
79
80
        return $this->redirectBinding->createResponseFor($authnRequest);
81
    }
82
}
83