Failed Conditions
Push — ng ( e90992...13fb6e )
by Florent
17:32
created

getNodeDefinition()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 31
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 26
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Bundle\DependencyInjection\Component\OpenIdConnect;
15
16
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
17
use OAuth2Framework\Bundle\DependencyInjection\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\PropertyAccess\PropertyAccess;
21
22
final class UserinfoEndpointEncryptionSource implements Component
0 ignored issues
show
Bug introduced by
There is one abstract method load in this class; you could implement it, or declare this class as abstract.
Loading history...
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name(): string
28
    {
29
        return 'encryption';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function continueLoading(string $path, ContainerBuilder $container, array $config)
36
    {
37
        $container->setParameter($path.'.key_encryption_algorithms', $config['key_encryption_algorithms']);
38
        $container->setParameter($path.'.content_encryption_algorithms', $config['content_encryption_algorithms']);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getNodeDefinition(NodeDefinition $node)
45
    {
46
47
        $node
48
            ->validate()
49
                ->ifTrue(function ($config) {
50
                    return true === $config['enabled'] && empty($config['key_encryption_algorithms']);
51
                })
52
                ->thenInvalid('You must set at least one key encryption algorithm.')
53
            ->end()
54
            ->validate()
55
                ->ifTrue(function ($config) {
56
                    return true === $config['enabled'] && empty($config['content_encryption_algorithms']);
57
                })
58
                ->thenInvalid('You must set at least one content encryption algorithm.')
59
            ->end()
60
            ->children()
61
                ->arrayNode('key_encryption_algorithms')
62
                    ->info('Supported key encryption algorithms.')
63
                    ->useAttributeAsKey('name')
64
                    ->prototype('scalar')->end()
65
                    ->treatNullLike([])
66
                ->end()
67
                    ->arrayNode('content_encryption_algorithms')
68
                    ->info('Supported content encryption algorithms.')
69
                    ->useAttributeAsKey('name')
70
                    ->prototype('scalar')->end()
71
                ->treatNullLike([])
72
                ->end()
73
            ->end();
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function prepend(array $bundleConfig, string $path, ContainerBuilder $container)
80
    {
81
        parent::prepend($bundleConfig, $path, $container);
82
        $currentPath = $path.'['.$this->name().']';
83
        $accessor = PropertyAccess::createPropertyAccessor();
84
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
85
86
        ConfigurationHelper::addJWEBuilder($container, 'oauth2_server.userinfo', $sourceConfig['key_encryption_algorithms'], $sourceConfig['content_encryption_algorithms'], ['DEF'], false);
87
    }
88
}
89