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\SessionManagement; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\ServerBundle\Component\Component; |
17
|
|
|
use OAuth2Framework\ServerBundle\Component\Endpoint\SessionManagement\Compiler\SessionManagementRouteCompilerPass; |
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 SessionManagementEndpointSource implements Component |
24
|
|
|
{ |
25
|
|
|
public function name(): string |
26
|
|
|
{ |
27
|
|
|
return 'session_management'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function load(array $configs, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
|
|
$config = $configs['endpoint']['session_management']; |
33
|
|
|
$container->setParameter('oauth2_server.endpoint.session_management.enabled', $config['enabled']); |
34
|
|
|
if (!$config['enabled']) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
$container->setParameter('oauth2_server.endpoint.session_management.path', $config['path']); |
38
|
|
|
$container->setParameter('oauth2_server.endpoint.session_management.host', $config['host']); |
39
|
|
|
$container->setParameter('oauth2_server.endpoint.session_management.storage_name', $config['storage_name']); |
40
|
|
|
$container->setParameter('oauth2_server.endpoint.session_management.template', $config['template']); |
41
|
|
|
|
42
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/session_management')); |
43
|
|
|
$loader->load('session_management.php'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode) |
47
|
|
|
{ |
48
|
|
|
$node->children() |
49
|
|
|
->arrayNode($this->name()) |
50
|
|
|
->canBeEnabled() |
51
|
|
|
->validate() |
52
|
|
|
->ifTrue(function ($config) { |
53
|
|
|
return true === $config['enabled'] && empty($config['path']); |
54
|
|
|
}) |
55
|
|
|
->thenInvalid('The route name must be set.') |
56
|
|
|
->end() |
57
|
|
|
->validate() |
58
|
|
|
->ifTrue(function ($config) { |
59
|
|
|
return true === $config['enabled'] && empty($config['storage_name']); |
60
|
|
|
})->thenInvalid('The option "storage_name" must be set.') |
61
|
|
|
->end() |
62
|
|
|
->validate() |
63
|
|
|
->ifTrue(function ($config) { |
64
|
|
|
return true === $config['enabled'] && empty($config['template']); |
65
|
|
|
})->thenInvalid('The option "template" must be set.') |
66
|
|
|
->end() |
67
|
|
|
->children() |
68
|
|
|
->scalarNode('path') |
69
|
|
|
->info('The session management endpoint') |
70
|
|
|
->defaultValue('/session') |
71
|
|
|
->end() |
72
|
|
|
->scalarNode('host') |
73
|
|
|
->info('If set, the route will be limited to that host') |
74
|
|
|
->defaultValue('') |
75
|
|
|
->treatNullLike('') |
76
|
|
|
->treatFalseLike('') |
77
|
|
|
->end() |
78
|
|
|
->scalarNode('storage_name') |
79
|
|
|
->info('The name used for the cookie storage') |
80
|
|
|
->defaultValue('oidc_browser_state') |
81
|
|
|
->end() |
82
|
|
|
->scalarNode('template') |
83
|
|
|
->info('The template of the OP iframe.') |
84
|
|
|
->defaultValue('@OAuth2FrameworkServerBundle/iframe/iframe.html.twig') |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->end(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function build(ContainerBuilder $container) |
92
|
|
|
{ |
93
|
|
|
$container->addCompilerPass(new SessionManagementRouteCompilerPass()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
97
|
|
|
{ |
98
|
|
|
return []; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|