8000 fabbot comments · symfony/symfony@91dc0c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91dc0c2

Browse files
committed
fabbot comments
1 parent 2c019ce commit 91dc0c2

File tree

7 files changed

+25
-35
lines changed

7 files changed

+25
-35
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1818
use Symfony\Component\Config\Definition\ConfigurationInterface;
1919
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
20-
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
21-
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
2220
use Symfony\Component\Security\Http\Authorization\NotFullFledgedEqualNormalLoginHandler;
2321
use Symfony\Component\Security\Http\Authorization\NotFullFledgedRedirectToStartAuthenticationHandler;
22+
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
23+
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
2424

2525
/**
2626
* SecurityExtension configuration structure.
@@ -219,11 +219,11 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
219219
->scalarNode('not_full_fledged_handler')
220220
->defaultValue(NotFullFledgedRedirectToStartAuthenticationHandler::class)
221221
->beforeNormalization()
222-
->ifTrue(fn ($v): bool => $v == 'redirect')
222+
->ifTrue(fn ($v): bool => 'redirect' == $v)
223223
->then(fn ($v) => NotFullFledgedRedirectToStartAuthenticationHandler::class)
224224
->end()
225225
->beforeNormalization()
226-
->ifTrue(fn ($v): bool => $v == 'equal')
226+
->ifTrue(fn ($v): bool => 'equal' == $v)
227227
->then(fn ($v) => NotFullFledgedEqualNormalLoginHandler::class)
228228
->end()
229229
->end()

src/Symfony/Bundle/SecurityBundle/Resources/config/security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
[], // listeners
224224
null, // switch_user
225225
null, // logout
226-
null, //not_full_fledged_handler
226+
null, // not_full_fledged_handler
227227
])
228228

229229
->set('security.logout_url_generator', LogoutUrlGenerator::class)

src/Symfony/Component/Security/Http/Authorization/NotFullFledgedEqualNormalLoginHandler.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Security\Http\Authorization;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpFoundation\Response;
1715
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1816
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
1917
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -25,29 +23,30 @@
2523
* NotFullFledgedHandler for considering NotFullFledged Login equal to Normal Login except if IS_AUTHENTICATED_FULLY is asked
2624
* If IS_AUTHENTICATED_FULLY is in access denied Exception Attrribute, user is redirect to
2725
* startAuthentication function in AuthenticationTrustResolver
28-
* Otherwise The original AccessDeniedException is passing to accessDeniedHandler or ErrorPage or Thrown
26+
* Otherwise The original AccessDeniedException is passing to accessDeniedHandler or ErrorPage or Thrown.
2927
*
3028
* @author Roman JOLY <eltharin18@outlook.fr>
3129
*/
3230
class NotFullFledgedEqualNormalLoginHandler implements NotFullFledgedHandlerInterface
3331
{
34-
public function handle( ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool
32+
public function handle(ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool
3533
{
36-
if( !$trustResolver->isAuthenticated($token)) {
34+
if (!$trustResolver->isAuthenticated($token)) {
3735
$this->reauthenticate($starAuthenticationCallback, $event, $token, $exception, $logger);
3836
}
3937

40-
foreach($exception->getAttributes() as $attribute) {
41-
if(in_array($attribute, [AuthenticatedVoter::IS_AUTHENTICATED_FULLY])) {
38+
foreach ($exception->getAttributes() as $attribute) {
39+
if (\in_array($attribute, [AuthenticatedVoter::IS_AUTHENTICATED_FULLY])) {
4240
$this->reauthenticate($starAuthenticationCallback, $event, $token, $exception, $logger);
41+
4342
return true;
4443
}
4544
}
4645

4746
return false;
4847
}
4948

50-
private function reauthenticate(callable $starAuthenticationCallback, ExceptionEvent $event, ?TokenInterface $token, AccessDeniedException $exception, ?LoggerInterface$logger): void
49+
private function reauthenticate(callable $starAuthenticationCallback, ExceptionEvent $event, ?TokenInterface $token, AccessDeniedException $exception, ?LoggerInterface $logger): void
5150
{
5251
$logger?->debug('Access denied, the user is not fully authenticated; redirecting to authentication entry point.', ['exception' => $exception]);
5352

src/Symfony/Component/Security/Http/Authorization/NotFullFledgedHandlerInterface.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Security\Http\Authorization;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpFoundation\Response;
1715
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1816
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
1917
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -30,11 +28,11 @@ interface NotFullFledgedHandlerInterface
3028
/**
3129
* Allow to manage NotFullFledged cases when ExceptionListener catch AccessDeniedException
3230
* This function can make checks and event / exception changes to change the Response
33-
* It returns a boolean for break or not after that or continue the ExceptionListener process to decorate Exception and their response
34-
*
35-
* @param $starAuthenticationCallback callable for call start function from
36-
*
37-
* @return boolean break handleAccessDeniedException function in ExceptionListener after handle
31+
* It returns a boolean for break or not after that or continue the ExceptionListener process to decorate Exception and their response.
32+
*
33+
* @param $starAuthenticationCallback callable for call start function from
34+
*
35+
* @return bool break handleAccessDeniedException function in ExceptionListener after handle
3836
*/
39-
public function handle( ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool;
37+
public function handle(ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool;
4038
}

src/Symfony/Component/Security/Http/Authorization/NotFullFledgedRedirectToStartAuthenticationHandler.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,22 @@
1212
namespace Symfony\Component\Security\Http\Authorization;
1313

1414
use Psr\Log\LoggerInterface;
15-
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpFoundation\Response;
1715
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1816
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
1917
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
20-
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2118
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
22-
2319
use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException;
2420

2521
/**
2622
* NotFullFledgedHandler for considering NotFullFledged Login has to be redirect to login page if AccessDeniedException is thrown
2723
* When an AccessDeniedException is thrown and user is not full fledged logged, he is redirected to login page with
28-
* start function from authenticationEntryPoint
24+
* start function from authenticationEntryPoint.
2925
*
3026
* @author Roman JOLY <eltharin18@outlook.fr>
3127
*/
3228
class NotFullFledgedRedirectToStartAuthenticationHandler implements NotFullFledgedHandlerInterface
3329
{
34-
public function handle( ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool
30+
public function handle(ExceptionEvent $event, AccessDeniedException $exception, AuthenticationTrustResolverInterface $trustResolver, ?TokenInterface $token, ?LoggerInterface $logger, callable $starAuthenticationCallback): bool
3531
{
3632
if (!$trustResolver->isFullFledged($token)) {
3733
$logger?->debug('Access denied, the user is not fully authenticated; redirecting to authentication entry point.', ['exception' => $exception]);

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ private function handleAccessDeniedException(ExceptionEvent $event, AccessDenied
127127
$event->setThrowable(new AccessDeniedHttpException($exception->getMessage(), $exception));
128128
$token = $this->tokenStorage->getToken();
129129

130-
if($this->notFullFledgedHandler?->handle($event, $exception,$this->authenticationTrustResolver, $token, $this->logger, function ($request, $exception) {return $this->startAuthentication($request, $exception);} ))
131-
{
130+
if ($this->notFullFledgedHandler?->handle($event, $exception, $this->authenticationTrustResolver, $token, $this->logger, function ($request, $exception) {return $this->startAuthentication($request, $exception); })) {
132131
return;
133132
}
134133

src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
2222
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2323
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
24-
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2524
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2625
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2726
use Symfony\Component\Security\Core\Exception\LogoutException;
2827
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
2928
use Symfony\Component\Security\Http\Authorization\NotFullFledgedHandlerInterface;
30-
use Symfony\Component\Security\Http\Authorization\NotFullFledgedEqualNormalLoginHandler;
3129
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
3230
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
3331
use Symfony\Component\Security\Http\HttpUtils;
@@ -158,7 +156,7 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustom
158156
$tokenStorage = $this->createMock(TokenStorageInterface::class);
159157
$tokenStorage->expects($this->once())->method('getToken')->willReturn($this->createMock(TokenInterface::class));
160158

161-
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false,false), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(true));
159+
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false, false), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(true));
162160
$listener->onKernelException($event);
163161

164162
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());
@@ -174,11 +172,11 @@ public function testAccessDeniedExceptionNotFullFledgedWithoutHandlerResponseAut
174172
$tokenStorage = $this->createMock(TokenStorageInterface::class);
175173
$tokenStorage->expects($this->once())->method('getToken')->willReturn($this->createMock(TokenInterface::class));
176174

177-
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false,true), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(false));
175+
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false, true), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(false));
178176
$listener->onKernelException($event);
179177

180178
$this->assertNull($event->getResponse());
181-
$this->assertEquals($eventException?->getMessage() ?? $exception->getMessage(),$event->getThrowable()->getMessage());
179+
$this->assertEquals($eventException?->getMessage() ?? $exception->getMessage(), $event->getThrowable()->getMessage());
182180
}
183181

184182
/**
@@ -191,7 +189,7 @@ public function testAccessDeniedExceptionNotFullFledgedWithHandlerResponseCustom
191189
$tokenStorage = $this->createMock(TokenStorageInterface::class);
192190
$tokenStorage->expects($this->once())->method('getToken')->willReturn($this->createMock(TokenInterface::class));
193191

194-
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false,true), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(true));
192+
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false, true), null, $this->createEntryPointWithoutStartCalled(), null, null, $this->createNotFullFledgedHandler(true));
195193
$listener->onKernelException($event);
196194

197195
$this->assertSame($eventException ?? $exception, $event->getThrowable()->getPrevious());

0 commit comments

Comments
 (0)
0