8000 Merge branch '2.8' · symfony/symfony@4067a5c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4067a5c

Browse files
committed
Merge branch '2.8'
* 2.8: Updated the stlyes of the YAML commands [Security] Configuring a user checker per firewall [PropertyInfo] Test behavior when an extractor return null.
2 parents 7e3c4a6 + 112c66c commit 4067a5c

24 files changed

+203
-34
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
1819
use Symfony\Component\Finder\Finder;
1920
use Symfony\Component\Yaml\Exception\ParseException;
2021
use Symfony\Component\Yaml\Parser;
@@ -61,6 +62,8 @@ protected function configure()
6162

6263
protected function execute(InputInterface $input, OutputInterface $output)
6364
{
65+
$stdout = $output;
66+
$output = new SymfonyStyle($input, $output);
6467
$filename = $input->getArgument('filename');
6568

6669
if (!$filename) {
@@ -73,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7376
$content .= fread(STDIN, 1024);
7477
}
7578

76-
return $this->display($input, $output, array($this->validate($content)));
79+
return $this->display($input, $stdout, $output, array($this->validate($content)));
7780
}
7881

7982
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -95,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9598
$filesInfo[] = $this->validate(file_get_contents($file), $file);
9699
}
97100

98-
return $this->display($input, $output, $filesInfo);
101+
return $this->display($input, $stdout, $output, $filesInfo);
99102
}
100103

101104
private function validate($content, $file = null)
@@ -110,33 +113,37 @@ private function validate($content, $file = null)
110113
return array('file' => $file, 'valid' => true);
111114
}
112115

113-
private function display(InputInterface $input, OutputInterface $output, $files)
116+
private function display(InputInterface $input, OutputInterface $stdout, $output, $files)
114117
{
115118
switch ($input->getOption('format')) {
116119
case 'txt':
117-
return $this->displayTxt($output, $files);
120+
return $this->displayTxt($stdout, $output, $files);
118121
case 'json':
119122
return $this->displayJson($output, $files);
120123
default:
121124
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
122125
}
123126
}
124127

125-
private function displayTxt(OutputInterface $output, $filesInfo)
128+
private function displayTxt(OutputInterface $stdout, $output, $filesInfo)
126129
{
127130
$errors = 0;
128131

129132
foreach ($filesInfo as $info) {
130-
if ($info['valid'] && $output->isVerbose()) {
131-
$output->writeln('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
133+
if ($info['valid'] && $stdout->isVerbose()) {
134+
$output->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
132135
} elseif (!$info['valid']) {
133136
++$errors;
134-
$output->writeln(sprintf('<error>KO</error> in %s', $info['file']));
135-
$output->writeln(sprintf('<error>>> %s</error>', $info['message']));
137+
$output->text(sprintf('<error> ERROR </error> in %s', $info['file']));
138+
$output->text(sprintf('<error> >> %s</error>', $info['message']));
136139
}
137140
}
138141

139-
$output->writeln(sprintf('<comment>%d/%d valid files</comment>', count($filesInfo) - $errors, count($filesInfo)));
142+
if ($errors === 0) {
143+
$output->success(sprintf('All %d YAML files contain valid syntax.', count($filesInfo)));
144+
} else {
145+
$output->warning(sprintf('%d YAML files have valid syntax and %d contain errors.', count($filesInfo) - $errors, $errors));
146+
}
140147

141148
return min($errors, 1);
142149
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public function testDebugAllRoutes()
2525
$ret = $tester->execute(array('name' => null), array('decorated' => false));
2626

2727
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
28-
$this->assertContains('Path', $tester->getDisplay());
29-
$this->assertContains('/foo', $tester->getDisplay());
28+
$this->assertContains('Name Method Scheme Host Path', $tester->getDisplay());
3029
}
3130

3231
public function testDebugSingleRoute()

src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
216216
->prototype('scalar')->end()
217217
->end()
218218
->booleanNode('security')->defaultTrue()->end()
219+
->scalarNode('user_checker')
220+
->defaultValue('security.user_checker')
221+
->treatNullLike('security.user_checker')
222+
->info('The UserChecker to use when authenticating users in this firewall.')
223+
->end()
219224
->scalarNode('request_matcher')->end()
93C6 220225
->scalarNode('access_denied_url')->end()
221226
->scalarNode('access_denied_handler')->end()

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config,
6565
$container
6666
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao'))
6767
->replaceArgument(0, new Reference($userProviderId))
68+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
6869
->replaceArgument(2, $id)
6970
;
7071

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginLdapFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config,
3030
$container
3131
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind'))
3232
->replaceArgument(0, new Reference($userProviderId))
33+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3334
->replaceArgument(2, $id)
3435
->replaceArgument(3, new Reference($config['service']))
3536
->replaceArgument(4, $config['dn_string'])

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
6969
->replaceArgument(0, $authenticatorReferences)
7070
->replaceArgument(1, new Reference($userProvider))
7171
->replaceArgument(2, $id)
72+
->replaceArgument(3, new Reference('security.user_checker.'.$id))
7273
;
7374

7475
// listener

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
2929
$container
3030
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao'))
3131
->replaceArgument(0, new Reference($userProvider))
32+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3233
->replaceArgument(2, $id)
3334
;
3435

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicLdapFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
3131
$container
3232
->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind'))
3333
->replaceArgument(0, new Reference($userProvider))
34+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3435
->replaceArgument(2, $id)
3536
->replaceArgument(3, new Reference($config['service']))
3637
->replaceArgument(4, $config['dn_string'])

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
3535
$authProviderId = 'security.authentication.provider.rememberme.'.$id;
3636
$container
3737
->setDefinition($authProviderId, new DefinitionDecorator('security.authentication.provider.rememberme'))
38+
->replaceArgument(0, new Reference('security.user_checker.'.$id))
3839
->addArgument($config['secret'])
3940
->addArgument($id)
4041
;

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
3030
$container
3131
->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.pre_authenticated'))
3232
->replaceArgument(0, new Reference($userProvider))
33+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3334
->addArgument($id)
3435
;
3536

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
2929
$container
3030
->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.pre_authenticated'))
3131
->replaceArgument(0, new Reference($userProvider))
32+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
3233
->addArgument($id)
3334
;
3435

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
1616
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
17+
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1819
use Symfony\Component\DependencyInjection\Alias;
1920
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -100,16 +101,16 @@ public function load(array $configs, ContainerBuilder $container)
100101

101102
// add some required classes for compilation
102103
$this->addClassesToCompile(array(
103-
'Symfony\\Component\\Security\\Http\\Firewall',
104-
'Symfony\\Component\\Security\\Core\\User\\UserProviderInterface',
105-
'Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationProviderManager',
106-
'Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorage',
107-
'Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManager',
108-
'Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationChecker',
109-
'Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface',
110-
'Symfony\\Bundle\\SecurityBundle\\Security\\FirewallMap',
111-
'Symfony\\Bundle\\SecurityBundle\\Security\\FirewallContext',
112-
'Symfony\\Component\\HttpFoundation\\RequestMatcher',
104+
'Symfony\Component\Security\Http\Firewall',
105+
'Symfony\Component\Security\Core\User\UserProviderInterface',
106+
'Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager',
107+
'Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage',
108+
'Symfony\Component\Security\Core\Authorization\AccessDecisionManager',
109+
'Symfony\Component\Security\Core\Authorization\AuthorizationChecker',
110+
'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface',
111+
'Symfony\Bundle\SecurityBundle\Security\FirewallMap',
112+
'Symfony\Bundle\SecurityBundle\Security\FirewallContext',
113+
'Symfony\Component\HttpFoundation\RequestMatcher',
113114
));
114115
}
115116

@@ -369,6 +370,8 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
369370
// Exception listener
370371
$exceptionListener = new Reference($this->createExceptionListener($container, $firewall, $id, $configuredEntryPoint ?: $defaultEntryPoint, $firewall['stateless']));
371372

373+
$container->setAlias(new Alias('security.user_checker.'.$id, false), $firewall['user_checker']);
374+
372375
return array($matcher, $listeners, $exceptionListener);
373376
}
374377

@@ -577,6 +580,7 @@ private function createSwitchUserListener($container, $id, $config, $defaultProv
577580
$switchUserListenerId = 'security.authentication.switchuser_listener.'.$id;
578581
$listener = $container->setDefinition($switchUserListenerId, new DefinitionDecorator('security.authentication.switchuser_listener'));
579582
$listener->replaceArgument(1, new Reference($userProvider));
583+
$listener->replaceArgument(2, new Reference('security.user_checker.'.$id));
580584
$listener->replaceArgument(3, $id);
581585
$listener->replaceArgument(6, $config['parameter']);
582586
$listener->replaceArgument(7, $config['role']);

src/Symfony/Bundle/SecurityBundle/Resources/config/guard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<argument /> <!-- Simple Authenticator -->
2222
<argument /> <!-- User Provider -->
2323
<argument /> <!-- Provider-shared Key -->
24-
<argument type="service" id="security.user_checker" />
24+
<argument /> <!-- User Checker -->
2525
</service>
2626

2727
<service id="security.authentication.listener.guard"

src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@
172172

173173
<service id="security.authentication.provider.dao" class="Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider" abstract="true" public="false">
174174
<argument /> <!-- User Provider -->
175-
<argument type="service" id="security.user_checker" />
175+
<argument /> <!-- User Checker -->
176176
<argument /> <!-- Provider-shared Key -->
177177
<argument type="service" id="security.encoder_factory" />
178178
<argument>%security.authentication.hide_user_not_found%</argument>
179179
</service>
180180

181181
<service id="security.authentication.provider.ldap_bind" class="Symfony\Component\Security\Core\Authentication\Provider\LdapBindAuthenticationProvider" public="false" abstract="true">
182182
<argument /> <!-- User Provider -->
183-
<argument type="service" id="security.user_checker" />
183+
<argument /> <!-- UserChecker -->
184184
<argument /> <!-- Provider-shared Key -->
185185
<argument /> <!-- LDAP -->
186186
<argument /> <!-- Base DN -->
@@ -195,7 +195,7 @@
195195

196196
<service id="security.authentication.provider.pre_authenticated" class="Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider" abstract="true" public="false">
197197
<argument /> <!-- User Provider -->
198-
<argument type="service" id="security.user_checker" />
198+
<argument /> <!-- User Checker -->
199199
</service>
200200

201201
<service id="security.exception_listener" class="Symfony\Component\Security\Http\Firewall\ExceptionListener" public="false" abstract="true">
@@ -215,7 +215,7 @@
215215
<tag name="monolog.logger" channel="security" />
216216
<argument type="service" id="security.token_storage" />
217217
<argument /> <!-- User Provider -->
218-
<argument type="service" id="security.user_checker" />
218+
<argument /> <!-- User Checker -->
219219
<argument /> <!-- Provider Key -->
220220
<argument type="service" id="security.access.decision_manager" />
221221
<argument type="service" id="logger" on-invalid="null" />

src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</service>
1717

1818
<service id="security.authentication.provider.rememberme" class="Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider" abstract="true" public="false">
19-
<argument type="service" id="security.user_checker" />
19+
<argument /> <!-- User Checker -->
2020
</service>
2121

2222
<service id="security.rememberme.token.provider.in_memory" class="Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider" public="false" />

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ public function testFirewalls()
9292
'security.authentication.listener.anonymous.host',
9393
'security.access_listener',
9494
),
95+
array(
96+
'security.channel_listener',
97+
'security.context_listener.1',
98+
'security.authentication.listener.basic.with_user_checker',
99+
'security.authentication.listener.anonymous.with_user_checker',
100+
'security.access_listener',
101+
),
95102
), $listeners);
96103
}
97104

@@ -231,6 +238,21 @@ public function testRememberMeThrowExceptions()
231238
$this->assertFalse($service->getArgument(5));
232239
}
233240

241+
public function testUserCheckerConfig()
242+
{
243+
$this->assertEquals('app.user_checker', $this->getContainer('container1')->getAlias('security.user_checker.with_user_checker'));
244+
}
245+
246+
public function testUserCheckerConfigWithDefaultChecker()
247+
{
248+
$this->assertEquals('security.user_checker', $this->getContainer('container1')->getAlias('security.user_checker.host'));
249+
}
250+
251+
public function testUserCheckerConfigWithNoCheckers()
252+
{
253+
$this->assertEquals('security.user_checker', $this->getContainer('container1')->getAlias('security.user_checker.secure'));
254+
}
255+
234256
protected function getContainer($file)
235257
{
236258
$container = new ContainerBuilder();

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'remote_user' => true,
7373
'logout' => true,
7474
'remember_me' => array('secret' => 'TheSecret'),
75+
'user_checker' => null,
7576
),
7677
'host' => array(
7778
'pattern' => '/test',
@@ -80,6 +81,11 @@
8081
'anonymous' => true,
8182
'http_basic' => true,
8283
),
84+
'with_user_checker' => array(
85+
'user_checker' => 'app.user_checker',
86+
'anonymous' => true,
87+
'http_basic' => true,
88+
),
8389
),
8490

8591
'access_control' => array(

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<switch-user />
5656
<x509 />
5757
<remote-user />
58+
<user-checker />
5859
<logout />
5960
<remember-me secret="TheSecret"/>
6061
</firewall>
@@ -64,6 +65,12 @@
6465
<http-basic />
6566
</firewall>
6667

68+
<firewall name="with_user_checker">
69+
<anonymous />
70+
<http-basic />
71+
<user-checker>app.user_checker</user-checker>
72+
</firewall>
73+
6774
<role id="ROLE_ADMIN">ROLE_USER</role>
6875
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
6976
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,20 @@ security:
5656
logout: true
5757
remember_me:
5858
secret: TheSecret
59+
user_checker: ~
60+
5961
host:
6062
pattern: /test
6163
host: foo\.example\.org
6264
methods: [GET,POST]
6365
anonymous: true
6466
http_basic: true
6567

68+
with_user_checker:
69+
anonymous: ~
70+
http_basic: ~
71+
user_checker: app.user_checker
72+
6673
role_hierarchy:
6774
ROLE_ADMIN: ROLE_USER
6875
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

0 commit comments

Comments
 (0)
0