1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 SURFnet bv |
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\StepupGateway\SamlStepupProviderBundle\DependencyInjection; |
20
|
|
|
|
21
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
22
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
23
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
24
|
|
|
|
25
|
|
|
class Configuration implements ConfigurationInterface |
26
|
|
|
{ |
27
|
|
|
public function getConfigTreeBuilder() |
28
|
|
|
{ |
29
|
|
|
$treeBuilder = new TreeBuilder('surfnet_stepup_gateway_saml_stepup_provider'); |
30
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
31
|
|
|
|
32
|
|
|
$rootNode |
33
|
|
|
->children() |
34
|
|
|
->arrayNode('allowed_sps') |
35
|
|
|
->isRequired() |
36
|
|
|
->requiresAtLeastOneElement() |
37
|
|
|
->prototype('scalar') |
38
|
|
|
->end() |
39
|
|
|
->end(); |
40
|
|
|
|
41
|
|
|
$this->addRoutesSection($rootNode); |
42
|
|
|
$this->addProvidersSection($rootNode); |
43
|
|
|
|
44
|
|
|
return $treeBuilder; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ArrayNodeDefinition $rootNode |
49
|
|
|
*/ |
50
|
|
|
private function addRoutesSection(ArrayNodeDefinition $rootNode): void |
51
|
|
|
{ |
52
|
|
|
$rootNode |
53
|
|
|
->children() |
54
|
|
|
->arrayNode('routes') |
55
|
|
|
->children() |
56
|
|
|
->scalarNode('sso') |
57
|
|
|
->isRequired() |
58
|
|
|
->validate() |
59
|
|
|
->ifTrue(function ($v) { |
60
|
|
|
return !is_string($v) || strlen($v) === 0; |
61
|
|
|
}) |
62
|
|
|
->thenInvalid('SSO route must be a non-empty string') |
63
|
|
|
->end() |
64
|
|
|
->end() |
65
|
|
|
->scalarNode('consume_assertion') |
|
|
|
|
66
|
|
|
->isRequired() |
67
|
|
|
->validate() |
68
|
|
|
->ifTrue(function ($v) { |
69
|
|
|
return !is_string($v) || strlen($v) === 0; |
70
|
|
|
}) |
71
|
|
|
->thenInvalid('Consume assertion route must be a non-empty string') |
72
|
|
|
->end() |
73
|
|
|
->end() |
74
|
|
|
->scalarNode('metadata') |
75
|
|
|
->isRequired() |
76
|
|
|
->validate() |
77
|
|
|
->ifTrue(function ($v) { |
78
|
|
|
return !is_string($v) || strlen($v) === 0; |
79
|
|
|
}) |
80
|
|
|
->thenInvalid('Metadata route must be a non-empty string') |
81
|
|
|
->end() |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->end(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param ArrayNodeDefinition $rootNode |
89
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
90
|
|
|
*/ |
91
|
|
|
private function addProvidersSection(ArrayNodeDefinition $rootNode): void |
92
|
|
|
{ |
93
|
|
|
/** @var ArrayNodeDefinition $protoType */ |
94
|
|
|
$protoType = $rootNode |
95
|
|
|
->children() |
96
|
|
|
->arrayNode('providers') |
97
|
|
|
->isRequired() |
98
|
|
|
->requiresAtLeastOneElement() |
99
|
|
|
->useAttributeAsKey('type') |
100
|
|
|
->prototype('array'); |
101
|
|
|
|
102
|
|
|
$protoType |
103
|
|
|
->canBeDisabled() |
104
|
|
|
->children() |
105
|
|
|
->arrayNode('hosted') |
106
|
|
|
->children() |
107
|
|
|
->arrayNode('service_provider') |
108
|
|
|
->children() |
109
|
|
|
->scalarNode('public_key') |
110
|
|
|
->isRequired() |
111
|
|
|
->info('The absolute path to the public key used to sign AuthnRequests') |
112
|
|
|
->end() |
113
|
|
|
->scalarNode('private_key') |
114
|
|
|
->isRequired() |
115
|
|
|
->info('The absolute path to the private key used to sign AuthnRequests') |
116
|
|
|
->end() |
117
|
|
|
->end() |
118
|
|
|
->end() |
119
|
|
|
->arrayNode('identity_provider') |
120
|
|
|
->children() |
121
|
|
|
->scalarNode('service_provider_repository') |
122
|
|
|
->isRequired() |
123
|
|
|
->info( |
124
|
|
|
'Name of the service that is the Entity Repository. Must implement the ' |
125
|
|
|
. ' Surfnet\SamlBundle\Entity\ServiceProviderRepository interface.' |
126
|
|
|
) |
127
|
|
|
->end() |
128
|
|
|
->scalarNode('public_key') |
129
|
|
|
->isRequired() |
130
|
|
|
->info('The absolute path to the public key used to sign Responses to AuthRequests with') |
131
|
|
|
->end() |
132
|
|
|
->scalarNode('private_key') |
133
|
|
|
->isRequired() |
134
|
|
|
->info('The absolute path to the private key used to sign Responses to AuthRequests with') |
135
|
|
|
->end() |
136
|
|
|
->end() |
137
|
|
|
->end() |
138
|
|
|
->arrayNode('metadata') |
139
|
|
|
->children() |
140
|
|
|
->scalarNode('public_key') |
141
|
|
|
->isRequired() |
142
|
|
|
->info('The absolute path to the public key used to sign the metadata') |
143
|
|
|
->end() |
144
|
|
|
->scalarNode('private_key') |
145
|
|
|
->isRequired() |
146
|
|
|
->info('The absolute path to the private key used to sign the metadata') |
147
|
|
|
->end() |
148
|
|
|
->end() |
149
|
|
|
->end() |
150
|
|
|
->end() |
151
|
|
|
->end() |
152
|
|
|
->arrayNode('remote') |
153
|
|
|
->children() |
154
|
|
|
->scalarNode('entity_id') |
155
|
|
|
->isRequired() |
156
|
|
|
->info('The EntityID of the remote identity provider') |
157
|
|
|
->end() |
158
|
|
|
->scalarNode('sso_url') |
159
|
|
|
->isRequired() |
160
|
|
|
->info('The name of the route to generate the SSO URL') |
161
|
|
|
->end() |
162
|
|
|
->scalarNode('certificate') |
163
|
|
|
->isRequired() |
164
|
|
|
->info( |
165
|
|
|
'The contents of the certificate used to sign the AuthnResponse with, if different from' |
166
|
|
|
. ' the public key configured below' |
167
|
|
|
) |
168
|
|
|
->end() |
169
|
|
|
->end() |
170
|
|
|
->end() |
171
|
|
|
->arrayNode('view_config') |
172
|
|
|
->children() |
173
|
|
|
->scalarNode('logo') |
174
|
|
|
->isRequired() |
175
|
|
|
->info('The absolute path to the logo of the gssp') |
176
|
|
|
->end() |
177
|
|
|
->arrayNode('title') |
178
|
|
|
->children() |
179
|
|
|
->scalarNode('en_GB') |
180
|
|
|
->isRequired() |
181
|
|
|
->info('English title of the gssp') |
182
|
|
|
->end() |
183
|
|
|
->scalarNode('nl_NL') |
184
|
|
|
->isRequired() |
185
|
|
|
->info('Dutch title of the gssp') |
186
|
|
|
->end() |
187
|
|
|
->end() |
188
|
|
|
->end() |
189
|
|
|
->end() |
190
|
|
|
->end() |
191
|
|
|
->end(); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|