Completed
Push — develop ( 63d5fd...833651 )
by
unknown
15s queued 10s
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 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
 */
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 class GsspUserAttributeService
28
{
29
    /**
30
     * @var LoggerInterface
31
     */
32
    private $logger;
33
34
    /**
35
     * @param LoggerInterface $logger
36
     */
37
    public function __construct(LoggerInterface $logger)
38
    {
39
        $this->logger = $logger;
40
    }
41
42
    public function addGsspUserAttributes(AuthnRequest $request, Provider $provider, Identity $user): void
43
    {
44
        $extensions = $request->getExtensions();
45
        $chunk = new GsspUserAttributesChunk();
46
47
        switch ($provider->getName()) {
48
            case 'azuremfa':
49
                $chunk->addAttribute(
50
                    'urn:mace:dir:attribute-def:mail',
51
                    'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
52
                    $user->email
53
                );
54
                $this->logger->info(
55
                    sprintf(
56
                        'Adding GSSP UserAttribute urn:mace:dir:attribute-def:mail for provider %s',
57
                        $provider->getName()
58
                    )
59
                );
60
                break;
61
        }
62
        $extensions->addChunk($chunk);
63
        $request->setExtensions($extensions);
64
    }
65
}
66