Failed Conditions
Push — ng ( 8fdb29...f5f23c )
by Florent
07:02
created

RequestObjectSource::prepend()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 7
nc 2
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\Bundle\Component\Endpoint\Authorization;
15
16
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
17
use OAuth2Framework\Bundle\Component\Component;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
22
23
class RequestObjectSource implements Component
24
{
25
    /**
26
     * @var Component[]
27
     */
28
    private $subComponents = [];
29
30
    /**
31
     * RequestObjectSource constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->subComponents = [
36
            new RequestObjectReferenceSource(),
37
            new RequestObjectEncryptionSource(),
38
        ];
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function name(): string
45
    {
46
        return 'request_object';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(array $configs, ContainerBuilder $container)
53
    {
54
        $config = $configs['endpoint']['authorization']['response_mode'];
55
        $container->setParameter('oauth2_server.endpoint.authorization.response_mode.allow_response_mode_parameter', $config['allow_response_mode_parameter']);
56
        //$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/authorization'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
        //$loader->load('response_mode.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
59
        foreach ($this->subComponents as $subComponent) {
60
            $subComponent->load($configs, $container);
61
        }
62
63
        foreach ($this->subComponents as $subComponent) {
64
            $subComponent->load($configs, $container);
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode)
72
    {
73
        $childNode = $node->children()
74
            ->arrayNode($this->name())
75
                ->canBeEnabled()
76
        ;
77
78
        $childNode->children()
79
            ->arrayNode('signature_algorithms')
80
                ->info('Supported signature algorithms.')
81
                ->useAttributeAsKey('name')
82
                ->scalarPrototype()->end()
83
                ->treatNullLike([])
84
            ->end()
85
        ->end();
86
87
        foreach ($this->subComponents as $subComponent) {
88
            $subComponent->getNodeDefinition($childNode, $node);
89
        }
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function prepend(ContainerBuilder $container, array $config): array
96
    {
97
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
        $currentPath = $path.'['.$this->name().']';
99
        $accessor = PropertyAccess::createPropertyAccessor();
100
        $sourceConfig = $accessor->getValue($bundleConfig, $currentPath);
101
        if (true === $sourceConfig['enabled']) {
102
            $claim_checkers = ['exp', 'iat', 'nbf', 'authorization_endpoint_aud']; // FIXME
103
        $header_checkers = ['crit']; // FIXME
104
        ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['signature_algorithms'], [], ['jws_compact'], false);
105
        ConfigurationHelper::addClaimChecker($container, $this->name(), $claim_checkers, false);
106
        if (true === $sourceConfig['encryption']['enabled']) {
107
            ConfigurationHelper::addJWELoader($container, $this->name(), $sourceConfig['encryption']['key_encryption_algorithms'], $sourceConfig['encryption']['content_encryption_algorithms'], ['DEF'], [], ['jwe_compact'], false);
108
        }
109
         */
110
111
        $updatedConfig = [];
112
        foreach ($this->subComponents as $subComponent) {
113
            $updatedConfig = array_merge(
114
                $updatedConfig,
115
                $subComponent->prepend($container, $config)
116
            );
117
        }
118
119
        return $updatedConfig;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function build(ContainerBuilder $container)
126
    {
127
        foreach ($this->subComponents as $component) {
128
            $component->build($container);
129
        }
130
    }
131
}
132