|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Norsys\SecurityBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use function preg_match; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* This is the class that validates and merges configuration from your app/config files. |
|
12
|
|
|
* |
|
13
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} |
|
14
|
|
|
*/ |
|
15
|
|
|
class Configuration implements ConfigurationInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getConfigTreeBuilder() |
|
21
|
|
|
{ |
|
22
|
|
|
$treeBuilder = new TreeBuilder(); |
|
23
|
|
|
$rootNode = $treeBuilder->root('norsys_security'); |
|
24
|
|
|
|
|
25
|
|
|
$rootNode |
|
26
|
|
|
->children() |
|
27
|
|
|
->arrayNode('https_redirect') |
|
28
|
|
|
->info('Optional https redirect configuration') |
|
29
|
|
|
->addDefaultsIfNotSet() |
|
30
|
|
|
->children() |
|
31
|
|
|
->booleanNode('enabled') |
|
32
|
|
|
->info('Enable force redirect to https') |
|
33
|
|
|
->defaultValue(false) |
|
34
|
|
|
->end() |
|
35
|
|
|
->end() |
|
36
|
|
|
->end() |
|
37
|
|
|
->arrayNode('proxy') |
|
38
|
|
|
->info('Optional proxy configuration') |
|
39
|
|
|
->addDefaultsIfNotSet() |
|
40
|
|
|
->children() |
|
41
|
|
|
->booleanNode('enabled') |
|
42
|
|
|
->info('Enable proxy') |
|
43
|
|
|
->defaultValue(false) |
|
44
|
|
|
->end() |
|
45
|
|
|
->scalarNode('env_variable_name') |
|
46
|
|
|
->info('Configure name to environment variable list trusted proxies') |
|
47
|
|
|
->defaultValue('TRUSTED_PROXIES') |
|
48
|
|
|
->end() |
|
49
|
|
|
->scalarNode('env_variable_separator') |
|
50
|
|
|
->info('Configure proxy separator in environment variable listed trusted proxies') |
|
51
|
|
|
->defaultValue(',') |
|
52
|
|
|
->end() |
|
53
|
|
|
->scalarNode('trusted_header_set') |
|
54
|
|
|
->info('A bit field of Request::HEADER_*, to set which headers to trust from your proxies') |
|
55
|
|
|
->defaultValue(Request::HEADER_X_FORWARDED_ALL) |
|
56
|
|
|
->validate() |
|
57
|
|
|
->ifEmpty() |
|
58
|
|
|
->then(function () { |
|
59
|
|
|
return Request::HEADER_X_FORWARDED_ALL; |
|
60
|
|
|
}) |
|
61
|
|
|
->end() |
|
62
|
|
|
->validate() |
|
63
|
|
|
->ifTrue( |
|
64
|
|
|
function (string $header) { |
|
65
|
|
|
if (preg_match('/^HEADER_FORWARDED$|^HEADER_X_[\w]+$/', $header) === 0 |
|
66
|
|
|
|| defined(Request::class . '::' . $header) === false |
|
67
|
|
|
) { |
|
68
|
|
|
return true; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
) |
|
72
|
|
|
->thenInvalid('Invalid header to trust from your proxies %s') |
|
73
|
|
|
->end() |
|
74
|
|
|
->end() |
|
75
|
|
|
->end() |
|
76
|
|
|
->end() |
|
77
|
|
|
->arrayNode('coming_soon') |
|
78
|
|
|
->info('Optional coming soon configuration') |
|
79
|
|
|
->addDefaultsIfNotSet() |
|
80
|
|
|
->children() |
|
81
|
|
|
->booleanNode('enabled') |
|
82
|
|
|
->info('Redirect all requests to coming soon page') |
|
83
|
|
|
->defaultValue(false) |
|
84
|
|
|
->end() |
|
85
|
|
|
->scalarNode('template') |
|
86
|
|
|
->info('Template to display coming soon page') |
|
87
|
|
|
->defaultValue('NorsysSecurityBundle::coming_soon.html.twig') |
|
88
|
|
|
->end() |
|
89
|
|
|
->arrayNode('allowed_ips') |
|
90
|
|
|
->prototype('scalar') |
|
91
|
|
|
->end() |
|
92
|
|
|
->defaultValue([]) |
|
93
|
|
|
->end() |
|
94
|
|
|
->end() |
|
95
|
|
|
->end() |
|
96
|
|
|
->end(); |
|
97
|
|
|
|
|
98
|
|
|
return $treeBuilder; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|