Skip to content

Commit 0cbb3bd

Browse files
cjgordonegulias
authored andcommitted
Symfony 3.x Compatibility: (#6)
* Symfony 3.x Compatibility: - Updated usage of table helper (deprecated in 3.x) in commands to Table class. - Updated references to security context (deprecated in 3.x) to token storage. - Updated readme, should only register bundle in dev and test environments where it is intended to be used. * Symfony 3: - Fixes issue with webdev toolbar when on anonymous access pages.
1 parent 20767c1 commit 0cbb3bd

File tree

9 files changed

+33
-24
lines changed

9 files changed

+33
-24
lines changed

Command/SecurityDebugAclObjectCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
1212
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
1313
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
14+
use Symfony\Component\Console\Helper\Table;
1415

1516
/**
1617
* ACL Objects debug command
@@ -91,7 +92,7 @@ function (&$v, $k) {
9192
$access = $acl->isGranted($masks, array($securityIdentity), false) ? 'Allow' : 'Deny';
9293
}
9394

94-
$table = $this->getHelperSet()->get('table');
95+
$table = new Table($output);
9596
$table->setHeaders(array('Mask', 'Grant', 'Deny'));
9697
$table->setRows($results);
9798
$table->render($output);

Command/SecurityDebugAclVotersCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1313
use Egulias\SecurityDebugCommandBundle\Security\Voter\VotersDebug;
1414
use Egulias\SecurityDebugCommandBundle\Security\Authorization\DecisionManagerDebug;
15+
use Symfony\Component\Console\Helper\Table;
1516

1617
/**
1718
* Voters debug command
@@ -87,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8788
);
8889

8990
$output->writeln($formattedLine);
90-
$table = $this->getHelperSet()->get('table');
91+
$table = new Table($output);
9192
$table->setHeaders(array('Class', 'Abstain', 'Grant', 'Deny'));
9293
$votes = $votersDebug->getVotersVote($token);
9394

Command/SecurityDebugFirewallsCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
1515
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1616
use Egulias\SecurityDebugCommandBundle\HttpKernel\SimpleHttpKernel;
17+
use Symfony\Component\Console\Helper\Table;
1718

1819
/**
1920
* @author Eduardo Gulias <[email protected]>
@@ -51,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5152
$session = $this->getContainer()->get('session');
5253
$session->setName('security.debug.console');
5354
$session->set('_security_' . $firewallProvider, serialize($token));
54-
$this->getContainer()->get('security.context')->setToken($token);
55+
$this->getContainer()->get('security.token_storage')->setToken($token);
5556

5657
$kernel = new SimpleHttpKernel();
5758
$request = Request::create($uri, 'GET', array(), array('security.debug.console' => true));
@@ -77,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7778
sprintf('Firewall <comment>%s</comment> listeners', $firewallProvider)
7879
);
7980
$output->writeln($formattedLine);
80-
$table = $this->getHelperSet()->get('table');
81+
$table = new Table($output);
8182
$table->setHeaders(array('Class', 'Stopped propagation'));
8283
$firewallContext = $map->getContext();
8384
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);

Command/SecurityDebugVotersCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1313
use Egulias\SecurityDebugCommandBundle\Security\Voter\VotersDebug;
1414
use Egulias\SecurityDebugCommandBundle\Security\Authorization\DecisionManagerDebug;
15+
use Symfony\Component\Console\Helper\Table;
1516

1617
/**
1718
* Voters debug command
@@ -71,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7172
);
7273

7374
$output->writeln($formattedLine);
74-
$table = $this->getHelperSet()->get('table');
75+
$table = new Table($output);
7576
$table->setHeaders(array('Class', 'Abstain', 'Grant', 'Deny'));
7677
$votes = $votersDebug->getVotersVote($token);
7778

DataCollector/FirewallCollector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
99
use Symfony\Component\HttpKernel\HttpKernelInterface;
1010
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
11-
use Symfony\Component\Security\Core\SecurityContextInterface;
11+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
1212

1313
/**
1414
* Class AccessDeniedListener
@@ -18,22 +18,22 @@ class FirewallCollector
1818
{
1919
const HAS_RESPONSE = SecurityDebugDataCollector::DENIED;
2020

21-
private $securityContext;
21+
private $tokenStorage;
2222
private $container;
2323

2424
public function __construct(
25-
SecurityContextInterface $securityContext,
25+
TokenStorage $tokenStorage,
2626
Container $container
2727
) {
28-
$this->securityContext = $securityContext;
28+
$this->tokenStorage = $tokenStorage;
2929
//Container dependency is a bad thing. This is to be refactored to a compiler pass
3030
//where all the firewall providers will be fetched
3131
$this->container = $container;
3232
}
3333

3434
public function collect(Request $request, \Exception $exception)
3535
{
36-
$token = $this->securityContext->getToken();
36+
$token = $this->tokenStorage->getToken();
3737
if (!method_exists($token, 'getProviderKey')) {
3838
return;
3939
}

DataCollector/VotersCollector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Egulias\SecurityDebugCommandBundle\DataCollector;
44

55
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
6-
use Symfony\Component\Security\Core\SecurityContextInterface;
6+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
77
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
88
use Egulias\SecurityDebugCommandBundle\Security\Voter\VotersDebug;
99

@@ -14,20 +14,20 @@
1414
class VotersCollector
1515
{
1616
private $accessDecisionManager;
17-
private $securityContext;
17+
private $tokenStorage;
1818

1919
public function __construct(
2020
AccessDecisionManagerInterface $decisionManager,
21-
SecurityContextInterface $securityContext
21+
TokenStorage $tokenStorage
2222
) {
2323
$this->accessDecisionManager = $decisionManager;
24-
$this->securityContext = $securityContext;
24+
$this->tokenStorage = $tokenStorage;
2525
}
2626

2727
public function collect()
2828
{
2929
$votersDebug = new VotersDebug($this->accessDecisionManager);
30-
$token = $this->securityContext->getToken();
30+
$token = $this->tokenStorage->getToken();
3131

3232
if (!$token || !$token->isAuthenticated()) {
3333
return;

EventListener/SecurityListenersDebugListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function onKernelException(GetResponseForExceptionEvent $event)
2929
if (!$event->getException() instanceof AccessDeniedException) {
3030
return;
3131
}
32+
33+
if (gettype($event->getRequest()->get('_controller')) == 'string') {
34+
return;
35+
}
36+
3237
$controller = $event->getRequest()->get('_controller');
3338
$controllerEvent = new FilterControllerEvent(
3439
$event->getKernel(),

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ $ php composer.phar update egulias/security-debug-command-bundle
8080
// app/AppKernel.php
8181
public function registerBundles()
8282
{
83-
return array(
84-
// ...
85-
new Egulias\SecurityDebugCommandBundle\EguliasSecurityDebugCommandBundle(),
86-
// ...
87-
);
83+
// ...
84+
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
85+
$bundle[] = Egulias\SecurityDebugCommandBundle\EguliasSecurityDebugCommandBundle();
86+
}
87+
// ...
8888
}
8989
```
9090
## Configure the user class

Resources/config/services.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
services:
22
egulias.voters_collector:
33
class: Egulias\SecurityDebugCommandBundle\DataCollector\VotersCollector
4-
arguments: [@security.access.decision_manager, @security.context]
4+
arguments: ["@security.access.decision_manager", "@security.token_storage"]
55
egulias.firewall_collector:
66
class: Egulias\SecurityDebugCommandBundle\DataCollector\FirewallCollector
7-
arguments: [@security.context, @service_container]
7+
arguments: ["@security.token_storage", "@service_container"]
88
egulias.security_listeners_debug:
99
class: Egulias\SecurityDebugCommandBundle\EventListener\SecurityListenersDebugListener
10-
arguments: [@sensio_framework_extra.security.listener, @data_collector.egulias_security_debug]
10+
arguments: ["@sensio_framework_extra.security.listener", "@data_collector.egulias_security_debug"]
1111
tags:
1212
- {name: kernel.event_listener, event: kernel.exception, priority: 128}
1313
data_collector.egulias_security_debug:
1414
class: Egulias\SecurityDebugCommandBundle\DataCollector\SecurityDebugDataCollector
15-
arguments: [@egulias.voters_collector, @egulias.firewall_collector]
15+
arguments: ["@egulias.voters_collector", "@egulias.firewall_collector"]
1616
tags:
1717
- { name: data_collector, template: "EguliasSecurityDebugCommandBundle:Collector:security_debug", id: "egulias_security_debug"}

0 commit comments

Comments
 (0)