1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 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\StepupBundle\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
|
|
|
/** |
26
|
|
|
* @codeCoverageIgnore |
27
|
|
|
*/ |
28
|
|
|
class Configuration implements ConfigurationInterface |
29
|
|
|
{ |
30
|
|
|
const DEFAULT_SMS_SERVICE = 'surfnet_stepup.service.gateway_api_sms'; |
31
|
|
|
|
32
|
|
|
public function getConfigTreeBuilder() |
33
|
|
|
{ |
34
|
|
|
$treeBuilder = new TreeBuilder; |
35
|
|
|
|
36
|
|
|
$rootNode = $treeBuilder->root('surfnet_bundle'); |
37
|
|
|
$rootNode |
38
|
|
|
->children() |
39
|
|
|
->arrayNode('logging') |
40
|
|
|
->isRequired() |
41
|
|
|
->children() |
42
|
|
|
->scalarNode('application_name') |
43
|
|
|
->info('This is the application name that is included with each log message') |
44
|
|
|
->isRequired() |
45
|
|
|
->validate() |
46
|
|
|
->ifTrue(function ($name) { |
47
|
|
|
return !is_string($name); |
48
|
|
|
}) |
49
|
|
|
->thenInvalid('surfnet_bundle.logging.application_name must be string') |
50
|
|
|
->end() |
51
|
|
|
->end() |
52
|
|
|
->end() |
53
|
|
|
->end() |
54
|
|
|
->arrayNode('loa_definition') |
55
|
|
|
->children() |
56
|
|
|
->scalarNode('loa1') |
57
|
|
|
->example('https://gateway.tld/authentication/loa1') |
58
|
|
|
->isRequired() |
59
|
|
|
->validate() |
60
|
|
|
->ifTrue(function ($value) { |
61
|
|
|
return !is_string($value); |
62
|
|
|
}) |
63
|
|
|
->thenInvalid('Loa definition for "loa1" must be a string') |
64
|
|
|
->end() |
65
|
|
|
->end() |
66
|
|
|
->scalarNode('loa2') |
67
|
|
|
->example('https://gateway.tld/authentication/loa2') |
68
|
|
|
->isRequired() |
69
|
|
|
->validate() |
70
|
|
|
->ifTrue(function ($value) { |
71
|
|
|
return !is_string($value); |
72
|
|
|
}) |
73
|
|
|
->thenInvalid('Loa definition for "loa2" must be a string') |
74
|
|
|
->end() |
75
|
|
|
->end() |
76
|
|
|
->scalarNode('loa3') |
77
|
|
|
->example('https://gateway.tld/authentication/loa3') |
78
|
|
|
->isRequired() |
79
|
|
|
->validate() |
80
|
|
|
->ifTrue(function ($value) { |
81
|
|
|
return !is_string($value); |
82
|
|
|
}) |
83
|
|
|
->thenInvalid('Loa definition for "loa3" must be a string') |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->arrayNode('attach_request_id_injector_to') |
89
|
|
|
->prototype('scalar') |
90
|
|
|
->validate() |
91
|
|
|
->ifTrue(function ($serviceId) { return !is_string($serviceId); }) |
92
|
|
|
->thenInvalid('surfnet_bundle.attach_request_id_injector_to must be array of strings') |
93
|
|
|
->end() |
94
|
|
|
->end() |
95
|
|
|
->end(); |
96
|
|
|
|
97
|
|
|
$this->createGatewayApiConfiguration($rootNode); |
98
|
|
|
$this->createSmsConfiguration($rootNode); |
99
|
|
|
$this->createLocaleCookieConfiguration($rootNode); |
100
|
|
|
|
101
|
|
|
return $treeBuilder; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private function createGatewayApiConfiguration(ArrayNodeDefinition $root) |
105
|
|
|
{ |
106
|
|
|
$root |
107
|
|
|
->children() |
108
|
|
|
->arrayNode('gateway_api') |
109
|
|
|
->canBeEnabled() |
110
|
|
|
->info('Gateway API configuration') |
111
|
|
|
->children() |
112
|
|
|
->arrayNode('credentials') |
113
|
|
|
->info('Basic authentication credentials') |
114
|
|
|
->children() |
115
|
|
|
->scalarNode('username') |
116
|
|
|
->info('Username for the Gateway API') |
117
|
|
|
->isRequired() |
118
|
|
|
->validate() |
119
|
|
|
->ifTrue(function ($value) { |
120
|
|
|
return (!is_string($value) || empty($value)); |
121
|
|
|
}) |
122
|
|
|
->thenInvalid( |
123
|
|
|
'Invalid Gateway API username specified: "%s". Must be non-empty string' |
124
|
|
|
) |
125
|
|
|
->end() |
126
|
|
|
->end() |
127
|
|
|
->scalarNode('password') |
128
|
|
|
->info('Password for the Gateway API') |
129
|
|
|
->isRequired() |
130
|
|
|
->validate() |
131
|
|
|
->ifTrue(function ($value) { |
132
|
|
|
return (!is_string($value) || empty($value)); |
133
|
|
|
}) |
134
|
|
|
->thenInvalid( |
135
|
|
|
'Invalid Gateway API password specified: "%s". Must be non-empty string' |
136
|
|
|
) |
137
|
|
|
->end() |
138
|
|
|
->end() |
139
|
|
|
->end() |
140
|
|
|
->end() |
141
|
|
|
->scalarNode('url') |
142
|
|
|
->info('The URL to the Gateway application (e.g. https://gateway.tld)') |
143
|
|
|
->isRequired() |
144
|
|
|
->validate() |
145
|
|
|
->ifTrue(function ($value) { |
146
|
|
|
return (!is_string($value) || empty($value) || !preg_match('~/$~', $value)); |
147
|
|
|
}) |
148
|
|
|
->thenInvalid( |
149
|
|
|
'Invalid Gateway URL specified: "%s". Must be string ending in forward slash' |
150
|
|
|
) |
151
|
|
|
->end() |
152
|
|
|
->end() |
153
|
|
|
->end() |
154
|
|
|
->end() |
155
|
|
|
->end(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
private function createSmsConfiguration(ArrayNodeDefinition $root) |
159
|
|
|
{ |
160
|
|
|
$root |
161
|
|
|
->children() |
162
|
|
|
->arrayNode('sms') |
163
|
|
|
->canBeDisabled() |
164
|
|
|
->info('SMS configuration') |
165
|
|
|
->isRequired() |
166
|
|
|
->children() |
167
|
|
|
->scalarNode('service') |
168
|
|
|
->info( |
169
|
|
|
'The ID of the SMS service used for sending SMS messages. ' . |
170
|
|
|
'Must implement "Surfnet\StepupBundle\Service\SmsService".' |
171
|
|
|
) |
172
|
|
|
->defaultValue(self::DEFAULT_SMS_SERVICE) |
173
|
|
|
->validate() |
174
|
|
|
->ifTrue(function ($value) { |
175
|
|
|
return !is_string($value); |
176
|
|
|
}) |
177
|
|
|
->thenInvalid('The SMS service ID must be specified using a string.') |
178
|
|
|
->end() |
179
|
|
|
->end() |
180
|
|
|
->scalarNode('originator') |
181
|
|
|
->info('Originator (sender) for SMS messages') |
182
|
|
|
->validate() |
183
|
|
|
->ifTrue(function ($value) { |
184
|
|
|
return (!is_string($value) || !preg_match('~^[a-z0-9]{1,11}$~i', $value)); |
185
|
|
|
}) |
186
|
|
|
->thenInvalid( |
187
|
|
|
'Invalid SMS originator specified: "%s". Must be a string matching ' |
188
|
|
|
. '"~^[a-z0-9]{1,11}$~i".' |
189
|
|
|
) |
190
|
|
|
->end() |
191
|
|
|
->end() |
192
|
|
|
->integerNode('otp_expiry_interval') |
193
|
|
|
->info('After how many seconds an SMS challenge OTP expires') |
194
|
|
|
->validate() |
195
|
|
|
->ifTrue(function ($value) { |
196
|
|
|
return $value <= 0; |
197
|
|
|
}) |
198
|
|
|
->thenInvalid( |
199
|
|
|
'Invalid SMS challenge OTP expiry, must be one or more seconds.' |
200
|
|
|
) |
201
|
|
|
->end() |
202
|
|
|
->end() |
203
|
|
|
->integerNode('maximum_otp_requests') |
204
|
|
|
->info('How many challenges a user may request during a session') |
205
|
|
|
->validate() |
206
|
|
|
->ifTrue(function ($value) { |
207
|
|
|
return $value <= 0; |
208
|
|
|
}) |
209
|
|
|
->thenInvalid( |
210
|
|
|
'Maximum OTP requests has a minimum of 1' |
211
|
|
|
) |
212
|
|
|
->end() |
213
|
|
|
->end() |
214
|
|
|
->end() |
215
|
|
|
->end() |
216
|
|
|
->end(); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
private function createLocaleCookieConfiguration(ArrayNodeDefinition $root) |
220
|
|
|
{ |
221
|
|
|
$root |
222
|
|
|
->children() |
223
|
|
|
->arrayNode('locale_cookie') |
224
|
|
|
->info('Cookie settings for locale cookie') |
225
|
|
|
->isRequired() |
226
|
|
|
->children() |
227
|
|
|
->scalarNode('name') |
228
|
|
|
->info('Name for the cookie') |
229
|
|
|
->defaultValue('stepup_locale') |
230
|
|
|
->isRequired() |
231
|
|
|
->end() |
232
|
|
|
->scalarNode('domain') |
233
|
|
|
->info('Domain the cookie is scoped to') |
234
|
|
|
->defaultValue('surfconext.nl') |
235
|
|
|
->isRequired() |
236
|
|
|
->end() |
237
|
|
|
->integerNode('expire') |
238
|
|
|
->info('Defines a specific date and time for when the browser should delete the cookie') |
239
|
|
|
->defaultValue('surfconext.nl') |
240
|
|
|
->isRequired() |
241
|
|
|
->end() |
242
|
|
|
->scalarNode('path') |
243
|
|
|
->info('Path the cookie is scoped to') |
244
|
|
|
->defaultValue('/') |
245
|
|
|
->isRequired() |
246
|
|
|
->end() |
247
|
|
|
->booleanNode('secure') |
248
|
|
|
->info('Only transmit cookie over secure connections?') |
249
|
|
|
->defaultValue(true) |
250
|
|
|
->isRequired() |
251
|
|
|
->end() |
252
|
|
|
->booleanNode('http_only') |
253
|
|
|
->info('Directs browsers not to expose cookies through channels other than HTTP (and HTTPS) requests') |
|
|
|
|
254
|
|
|
->defaultValue(false) |
255
|
|
|
->isRequired() |
256
|
|
|
->end() |
257
|
|
|
->end() |
258
|
|
|
->end() |
259
|
|
|
->end(); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.