Failed Conditions
Push — master ( 77805d...335a52 )
by Florent
10:18
created

RequestObjectSource::prepend()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 14
nc 4
nop 2
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\ServerBundle\Component\Endpoint\Authorization;
15
16
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
17
use OAuth2Framework\ServerBundle\Component\Component;
18
use OAuth2Framework\ServerBundle\Component\Endpoint\Authorization\Compiler\RequestObjectCompilerPass;
19
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
22
class RequestObjectSource implements Component
23
{
24
    /**
25
     * @var Component[]
26
     */
27
    private $subComponents = [];
28
29
    /**
30
     * RequestObjectSource constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->subComponents = [
35
            new RequestObjectReferenceSource(),
36
            new RequestObjectEncryptionSource(),
37
        ];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function name(): string
44
    {
45
        return 'request_object';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function load(array $configs, ContainerBuilder $container)
52
    {
53
        $config = $configs['endpoint']['authorization']['request_object'];
54
        $container->setParameter('oauth2_server.endpoint.authorization.request_object.enabled', $config['enabled']);
55
56
        foreach ($this->subComponents as $subComponent) {
57
            $subComponent->load($configs, $container);
58
        }
59
60
        foreach ($this->subComponents as $subComponent) {
61
            $subComponent->load($configs, $container);
62
        }
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode)
69
    {
70
        $childNode = $node->children()
71
            ->arrayNode($this->name())
72
                ->canBeEnabled()
73
        ;
74
75
        $childNode->children()
76
            ->arrayNode('signature_algorithms')
77
                ->info('Supported signature algorithms.')
78
                ->useAttributeAsKey('name')
79
                ->scalarPrototype()->end()
80
                ->treatNullLike([])
81
            ->end()
82
        ->end();
83
84
        foreach ($this->subComponents as $subComponent) {
85
            $subComponent->getNodeDefinition($childNode, $node);
86
        }
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function prepend(ContainerBuilder $container, array $config): array
93
    {
94
        $sourceConfig = $config['endpoint']['authorization']['request_object'];
95
        if (true === $sourceConfig['enabled']) {
96
            $claim_checkers = ['exp', 'iat', 'nbf', /*'authorization_endpoint_aud'*/]; // FIXME
97
            $header_checkers = []; // FIXME
98
            ConfigurationHelper::addJWSVerifier($container, 'oauth2_server.endpoint.authorization.request_object', $sourceConfig['signature_algorithms'], false);
99
            ConfigurationHelper::addHeaderChecker($container, 'oauth2_server.endpoint.authorization.request_object', $header_checkers, false);
100
            ConfigurationHelper::addClaimChecker($container, 'oauth2_server.endpoint.authorization.request_object', $claim_checkers, false);
101
        }
102
103
        $updatedConfig = [];
104
        foreach ($this->subComponents as $subComponent) {
105
            $updatedConfig = array_merge(
106
                $updatedConfig,
107
                $subComponent->prepend($container, $config)
108
            );
109
        }
110
111
        return $updatedConfig;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function build(ContainerBuilder $container)
118
    {
119
        $container->addCompilerPass(new RequestObjectCompilerPass());
120
121
        foreach ($this->subComponents as $component) {
122
            $component->build($container);
123
        }
124
    }
125
}
126