8000 bug #41139 [Security] [DataCollector] Remove allows anonymous informa… · symfony/symfony@e83c992 · GitHub
[go: up one dir, main page]

Skip to content

Commit e83c992

Browse files
committed
bug #41139 [Security] [DataCollector] Remove allows anonymous information in datacollector (ismail1432)
This PR was submitted for the 5.x branch but it was squashed and merged into the 5.2 branch instead. Discussion ---------- [Security] [DataCollector] Remove allows anonymous information in datacollector | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | yes/no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes/no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #40907 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> As mentioned In #40907 there is no longer anonymous users no longer in the new authentication system. This PR remove this information **if the new system is used** as it always a red cross With `enable_authenticator_manager` at `false` ![image](https://user-images.githubusercontent.com/13260307/117574692-34c8d900-b0d6-11eb-9bef-a6c9abdfad2f.png) With `enable_authenticator_manager` at `true` ![image](https://user-images.githubusercontent.com/13260307/117574619-f3382e00-b0d5-11eb-945a-3613425ccdbe.png) Commits ------- 92cd096 [Security] [DataCollector] Remove allows anonymous information in datacollector
2 parents 2e047c9 + 92cd096 commit e83c992

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class SecurityDataCollector extends DataCollector implements LateDataCollectorIn
4444
private $firewallMap;
4545
private $firewall;
4646
private $hasVarDumper;
47+
private $authenticatorManagerEnabled;
4748

48-
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null, TraceableFirewallListener $firewall = null)
49+
public function __construct(TokenStorageInterface $tokenStorage = null, RoleHierarchyInterface $roleHierarchy = null, LogoutUrlGenerator $logoutUrlGenerator = null, AccessDecisionManagerInterface $accessDecisionManager = null, FirewallMapInterface $firewallMap = null, TraceableFirewallListener $firewall = null, $authenticatorManagerEnabled = false)
4950
{
5051
$this->tokenStorage = $tokenStorage;
5152
$this->roleHierarchy = $roleHierarchy;
@@ -54,6 +55,7 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier
5455
$this->firewallMap = $firewallMap;
5556
$this->firewall = $firewall;
5657
$this->hasVarDumper = class_exists(ClassStub::class);
58+
$this->authenticatorManagerEnabled = $authenticatorManagerEnabled;
5759
}
5860

5961
/**
@@ -204,6 +206,8 @@ public function collect(Request $request, Response $response, \Throwable $except
204206
if ($this->firewall) {
205207
$this->data['listeners'] = $this->firewall->getWrappedListeners();
206208
}
209+
210+
$this->data['authenticator_manager_enabled'] = $this->authenticatorManagerEnabled;
207211
}
208212

209213
/**
@@ -389,4 +393,9 @@ public function getName()
389393
{
390394
return 'security';
391395
}
396+
397+
public function isAuthenticatorManagerEnabled(): bool
398+
{
399+
return $this->data['authenticator_manager_enabled'];
400+
}
392401
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public function load(array $configs, ContainerBuilder $container)
132132
$loader->load('collectors.php');
133133
$loader->load('guard.php');
134134

135+
$container->getDefinition('data_collector.security')->addArgument($this->authenticatorManagerEnabled);
136+
135137
if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
136138
$loader->load('security_debug.php');
137139
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@
159159
<span class="value">{{ include('@WebProfiler/Icon/' ~ (collector.firewall.stateless ? 'yes' : 'no') ~ '.svg') }}</span>
160160
<span class="label">Stateless</span>
161161
</div>
162+
{% if collector.authenticatorManagerEnabled == false %}
162163
<div class="metric">
163164
<span class="value">{{ include('@WebProfiler/Icon/' ~ (collector.firewall.allows_anonymous ? 'yes' : 'no') ~ '.svg') }}</span>
164165
<span class="label">Allows anonymous</span>
165166
</div>
167+
{% endif %}
166168
</div>
167169

168170
{% if collector.firewall.security_enabled %}

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function testCollectWhenAuthenticationTokenIsNull()
7171
$this->assertCount(0, $collector->getInheritedRoles());
7272
$this->assertEmpty($collector->getUser());
7373
$this->assertNull($collector->getFirewall());
74+
$this->assertFalse($collector->isAuthenticatorManagerEnabled());
7475
}
7576

7677
/** @dataProvider provideRoles */
@@ -93,6 +94,7 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm
9394
$this->assertSame($normalizedRoles, $collector->getRoles()->getValue(true));
9495
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getValue(true));
9596
$this->assertSame('hhamon', $collector->getUser());
97+
$this->assertFalse($collector->isAuthenticatorManagerEnabled());
9698
}
9799

98100
public function testCollectSwitchUserToken()
@@ -132,7 +134,7 @@ public function testGetFirewall()
132134
->with($request)
133135
->willReturn($firewallConfig);
134136

135-
$collector = new SecurityDataCollector(null, null, null, null, $firewallMap, new TraceableFirewallListener($firewallMap, new EventDispatcher(), new LogoutUrlGenerator()));
137+
$collector = new SecurityDataCollector(null, null, null, null, $firewallMap, new TraceableFirewallListener($firewallMap, new EventDispatcher(), new LogoutUrlGenerator()), true);
136138
$collector->collect($request, new Response());
137139
$collector->lateCollect();
138140
$collected = $collector->getFirewall();
@@ -149,6 +151,7 @@ public function testGetFirewall()
149151
$this->assertSame($firewallConfig->getAccessDeniedUrl(), $collected['access_denied_url']);
150152
$this->assertSame($firewallConfig->getUserChecker(), $collected['user_checker']);
151153
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getValue());
154+
$this->assertTrue($collector->isAuthenticatorManagerEnabled());
152155
}
153156

154157
public function testGetFirewallReturnsNull()

0 commit comments

Comments
 (0)
0