Passed
Pull Request — main (#308)
by Paul
13:29 queued 06:46
created

GsspUserAttributeService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 3
1
<?php
2
3
/**
4
 * Copyright 2021 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
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...
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\SamlBundle\SAML2\AuthnRequest;
23
use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk;
24
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
25
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\Provider;
26
27
final readonly class GsspUserAttributeService
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 27 at column 6
Loading history...
Coding Style introduced by
Missing doc comment for class GsspUserAttributeService
Loading history...
28
{
29
    public function __construct(private LoggerInterface $logger)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
30
    {
31
    }
32
33
    public function addGsspUserAttributes(AuthnRequest $request, Provider $provider, Identity $user): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function addGsspUserAttributes()
Loading history...
34
    {
35
        $extensions = $request->getExtensions();
36
        $chunk = new GsspUserAttributesChunk();
37
38
        if ($provider->getName() === 'azuremfa') {
39
            $chunk->addAttribute(
40
                'urn:mace:dir:attribute-def:mail',
41
                'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
42
                $user->email
43
            );
44
            $this->logger->info(
45
                sprintf(
46
                    'Adding GSSP UserAttribute urn:mace:dir:attribute-def:mail for provider %s',
47
                    $provider->getName()
48
                )
49
            );
50
        }
51
        $extensions->addChunk($chunk);
52
        $request->setExtensions($extensions);
53
    }
54
}
55