8000 Integrate current firewall in profile · symfony/symfony@beb2180 · GitHub
[go: up one dir, main page]

Skip to content

Commit beb2180

Browse files
committed
Integrate current firewall in profile
Add firewall name to the toolbar
1 parent 89a2d83 commit beb2180

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpFoundation\ParameterBag;
1819
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
1920
use Symfony\Component\Security\Core\Role\RoleInterface;
2021
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
2122
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2223
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
23-
24+
use Symfony\Component\Security\Http\FirewallMapInterface;
25+
use Symfony\Bundle\SecurityBundle\Security\ContextAwareFirewallMapInterface;
2426
/**
2527
* SecurityDataCollector.
2628
*
@@ -32,21 +34,24 @@ class SecurityDataCollector extends DataCollector
3234
private $roleHierarchy;
3335
private $logoutUrlGenerator;
3436
private $accessDecisionManager;
37+
private $firewallMap;
3538

3639
/**
3740
* Constructor.
3841
*
39-
* @param TokenStorageInterface|null $tokenStorage
40-
* @param RoleHierarchyInterface|null $roleHierarchy
41-
* @param LogoutUrlGenerator|null $logoutUrlGenerator
42-
* @param AccessDecisionManagerInterface|null $accessDecisionManager
42+
* @param TokenStorageInterface|null $tokenStorage
43+
* @param RoleHierarchyInterface|null $roleHierarchy
44+
* @param LogoutUrlGenerator|null $logoutUrlGenerator
45+
* @param AccessDecisionManagerInterface|null $accessDecisionManager
46+
* @param ContextAwareFirewallMapInterface|null $firewallMap
4347
*/
44-
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null)
48+
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null)
4549
{
4650
$this->tokenStorage = $tokenStorage;
4751
$this->roleHierarchy = $roleHierarchy;
4852
$this->logoutUrlGenerator = $logoutUrlGenerator;
4953
$this->accessDecisionManager = $accessDecisionManager;
54+
$this->firewallMap = $firewallMap;
5055
}
5156

5257
/**
@@ -123,6 +128,31 @@ public function collect(Request $request, Response $response, \Exception $except
123128
$this->data['voter_strategy'] = 'unknown';
124129
$this->data['voters'] = array();
125130
}
131+
132+
// collect firewall context informations
133+
$this->data['firewall'] = array('name' => null, 'config' => array());
134+
if ($this->firewallMap instanceof ContextAwareFirewallMapInterface) {
135+
$firewallContext = $this->firewallMap->getContext($request);
136+
137+
if (null !== $firewallContext) {
138+
$config = $firewallContext->getConfig();
139+
$contextConfig = array();
140+
$contextConfig['request_matcher'] = $config->getRequestMatcher();
141+
$contextConfig['security'] = $config->hasSecurity();
142+
$contextConfig['context'] = $config->getContext();
143+
$contextConfig['entry_point'] = $config->getEntryPoint();
144+
$contextConfig['provider'] = $config->getProvider();
145+
$contextConfig['stateless'] = $config->isStateless();
146+
$contextConfig['access_denied_handler'] = $config->getAccessDeniedHandler();
147+
$contextConfig['access_denied_url'] = $config->getAccessDeniedUrl();
148+
$contextConfig['user_checker'] = $config->getUserChecker();
149+
150+
$this->data['firewall']['name'] = $config->getName();
151+
$this->data['firewall']['config'] = new ParameterBag($contextConfig);
152+
}
153+
} else {
154+
$this->data['firewall'] = array();
155+
}
126156
}
127157

128158
/**
@@ -236,6 +266,16 @@ public function getAccessDecisionLog()
236266
return $this->data['access_decision_log'];
237267
}
238268

269+
/**
270+
* Returns the configuration of the current firewall context.
271+
*
272+
* @return array
273+
*/
274+
public function getFirewall()
275+
{
276+
return $this->data['firewall'];
277+
}
278+
239279
/**
240280
* {@inheritdoc}
241281
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument type="service" id="security.role_hierarchy" />
1212
<argument type="service" id="security.logout_url_generator" />
1313
<argument type="service" id="security.access.decision_manager" />
14+
<argument type="service" id="security.firewall.map" />
1415
</service>
1516
</services>
1617
</container>

src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<span>{{ collector.tokenClass|abbr_class }}</span>
3434
</div>
3535
{% endif %}
36+
{% if collector.firewall|default([]) is not empty %}
37+
<div class="sf-toolbar-info-piece">
38+
<b>Firewall name</b>
39+
<span>{{ collector.firewall.name }}</span>
40+
</div>
41+
{% endif %}
3642
{% if collector.logoutUrl %}
3743
<div class="sf-toolbar-info-piece">
3844
<b>Actions</b>
@@ -120,6 +126,19 @@
120126
</div>
121127
{% endif %}
122128

129+
{% if collector.firewall|default([]) is not empty %}
130+
<h2>Security Firewall</h2>
131+
132+
<div class="metrics">
133+
<div class="metric">
134+
<span class="value">{{ collector.firewall.name|default('unknown') }}</span>
135+
<span class="label">Firewall Name</span>
136+
</div>
137+
</div>
138+
139+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.firewall.config, labels: ['Key', 'Value'] }, with_context = false) }}
140+
{% endif %}
141+
123142
{% if collector.voters|default([]) is not empty %}
124143
<h2>Security Voters <small>({{ collector.voters|length }})</small></h2>
125144

0 commit comments

Comments
 (0)
0