Completed
Pull Request — develop (#221)
by
unknown
03:04 queued 01:20
created

GsspUserAttributeService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2021 SURF 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
 */
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\Extensions;
24
use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk;
25
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
26
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\Provider;
27
28
final class GsspUserAttributeService
29
{
30
    /**
31
     * @var LoggerInterface
32
     */
33
    private $logger;
34
35
    /**
36
     * @param LoggerInterface $logger
37
     */
38
    public function __construct(LoggerInterface $logger)
39
    {
40
        $this->logger = $logger;
41
    }
42
43
    public function addGsspUserAttributes(AuthnRequest $request, Provider $provider, Identity $user): void
44
    {
45
        $chunk = new GsspUserAttributesChunk();
46
        $extensions = $request->getExtensions() ?? new Extensions();
0 ignored issues
show
Bug introduced by
The method getExtensions() does not seem to exist on object<Surfnet\SamlBundle\SAML2\AuthnRequest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
48
        switch ($provider->getName()) {
49
            case 'azuremfa':
50
                $chunk->addAttribute(
51
                    'urn:mace:dir:attribute-def:mail',
52
                    'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
53
                    $user->email
54
                );
55
                $extensions->addChunk($chunk);
56
                $this->logger->info(
57
                    sprintf(
58
                        'Adding GSSP UserAttribute urn:mace:dir:attribute-def:mail for provider %s',
59
                        $provider->getName()
60
                    )
61
                );
62
                break;
63
        }
64
        $request->setExtensions($extensions);
0 ignored issues
show
Bug introduced by
The method setExtensions() does not seem to exist on object<Surfnet\SamlBundle\SAML2\AuthnRequest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
}
67