Passed
Push — feature/symfony6-upgrade ( 35a069...81bcc7 )
by Paul
05:48
created

GssfAuthenticateController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 32 1
A __construct() 0 8 1
A getProvider() 0 3 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\Provider;
27
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ProviderRepository;
28
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\Controller;
29
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...
30
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService;
31
use Symfony\Component\HttpFoundation\Response;
32
use Symfony\Component\Routing\Attribute\Route;
33
34
/**
35
 * Controls registration with Generic SAML Stepup Providers (GSSPs), yielding Generic SAML Second Factors (GSSFs).
36
 */
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...
37
final class GssfAuthenticateController extends Controller
38
{
39
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
40
        private readonly LoggerInterface           $logger,
41
        InstitutionConfigurationOptionsService     $configurationOptionsService,
42
        private readonly ProviderRepository        $providerRepository,
43
        private readonly RedirectBinding           $redirectBinding,
44
        private readonly GsspUserAttributeService  $gsspUserAttributeService,
45
    ) {
46
        parent::__construct($logger, $configurationOptionsService);
47
    }
48
49
50
    #[Route(
51
        path: '/registration/gssf/{provider}/authenticate',
52
        name: 'ss_registration_gssf_authenticate',
53
        methods: ['POST'],
54
    )]
55
    public function authenticate(string $provider): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function authenticate()
Loading history...
56
    {
57
        $this->assertSecondFactorEnabled($provider);
58
59
        $provider = $this->getProvider($provider);
60
61
        $authnRequest = AuthnRequestFactory::createNewRequest(
62
            $provider->getServiceProvider(),
63
            $provider->getRemoteIdentityProvider()
64
        );
65
66
        $this->gsspUserAttributeService->addGsspUserAttributes(
67
            $authnRequest,
68
            $provider,
69
            $this->getIdentity()
70
        );
71
        $stateHandler = $provider->getStateHandler();
72
        $stateHandler->setRequestId($authnRequest->getRequestId());
73
74
        $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...
75
            'Sending AuthnRequest with request ID: "%s" to GSSP "%s" at "%s"',
76
            $authnRequest->getRequestId(),
77
            $provider->getName(),
78
            $provider->getRemoteIdentityProvider()->getSsoUrl()
79
        ));
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...
80
81
        return $this->redirectBinding->createResponseFor($authnRequest);
82
    }
83
84
    private function getProvider(string $provider): Provider
0 ignored issues
show
Coding Style introduced by
Private method name "GssfAuthenticateController::getProvider" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function getProvider()
Loading history...
85
    {
86
        return $this->providerRepository->get($provider);
87
    }
88
89
}
90