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

Skip to content

Commit 9549901

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

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +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;
24+
use Symfony\Component\Security\Http\FirewallMapInterface;
25+
use Symfony\Bundle\SecurityBundle\Security\ContextAwareFirewallMapInterface;
2326

2427
/**
2528
* SecurityDataCollector.
@@ -32,21 +35,24 @@ class SecurityDataCollector extends DataCollector
3235
private $roleHierarchy;
3336
private $logoutUrlGenerator;
3437
private $accessDecisionManager;
38+
private $firewallMap;
3539

3640
/**
3741
* Constructor.
3842
*
39-
* @param TokenStorageInterface|null $tokenStorage
40-
* @param RoleHierarchyInterface|null $roleHierarchy
41-
* @param LogoutUrlGenerator|null $logoutUrlGenerator
42-
* @param AccessDecisionManagerInterface|null $accessDecisionManager
43+
* @param TokenStorageInterface|null $tokenStorage
44+
* @param RoleHierarchyInterface|null $roleHierarchy
45+
* @param LogoutUrlGenerator|null $logoutUrlGenerator
46+
* @param AccessDecisionManagerInterface|null $accessDecisionManager
47+
* @param ContextAwareFirewallMapInterface|null $firewallMap
4348
*/
44-
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null)
49+
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null)
4550
{
4651
$this->tokenStorage = $tokenStorage;
4752
$this->roleHierarchy = $roleHierarchy;
4853
$this->logoutUrlGenerator = $logoutUrlGenerator;
4954
$this->accessDecisionManager = $accessDecisionManager;
55+
$this->firewallMap = $firewallMap;
5056
}
5157

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

128159
/**
@@ -236,6 +267,16 @@ public function getAccessDecisionLog()
236267
return $this->data['access_decision_log'];
237268
}
238269

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

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