Skip to content

Commit 7537a03

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [FrameworkBundle][HttpKernel] Add the ability to enable the profiler using a parameter [FrameworkBundle] Trigger deprecations on stderr instead of using trigger_deprecation call Add PhpStanExtractor [Messenger] allow processing messages in batches [Console] Fix backslash escaping in bash completion Add missing validators translation add suggestions for debug:firewall, debug:form, debug:messenger, debug:router [SecurityBundle] Deprecate not configuring explicitly a provider for custom_authenticators when there is more than one registered provider [Inflector] Fix inflector for "zombies" [Config] Add some cache on SelfCheckingResourceChecker fix AJAX request unit spacing fix ErrorExcception in CacheWarmerAggregate Prevent FormLoginAuthenticator from responding to requests that should be handled by JsonLoginAuthenticator Fix wait duration for fixed window policy Add exact command used to trigger invocation to the completion debug log [Translation] correctly handle intl domains with TargetOperation Allow using param as connection atribute in `*.event_subscriber` and `*.event_listener` tags
2 parents 8fe3475 + 7b37c75 commit 7537a03

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Authenticator/FormLoginAuthenticator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function __construct(HttpUtils $httpUtils, UserProviderInterface $userPro
5959
'password_parameter' => '_password',
6060
'check_path' => '/login_check',
6161
'post_only' => true,
62+
'form_only' => false,
6263
'enable_csrf' => false,
6364
'csrf_parameter' => '_csrf_token',
6465
'csrf_token_id' => 'authenticate',
@@ -73,7 +74,8 @@ protected function getLoginUrl(Request $request): string
7374
public function supports(Request $request): bool
7475
{
7576
return ($this->options['post_only'] ? $request->isMethod('POST') : true)
76-
&& $this->httpUtils->checkRequestPath($request, $this->options['check_path']);
77+
&& $this->httpUtils->checkRequestPath($request, $this->options['check_path'])
78+
&& ($this->options['form_only'] ? 'form' === $request->getContentType() : true);
7779
}
7880

7981
public function authenticate(Request $request): Passport

Tests/Authenticator/FormLoginAuthenticatorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,27 @@ public function testUpgradePassword()
156156
$this->assertEquals('s$cr$t', $badge->getAndErasePlaintextPassword());
157157
}
158158

159+
/**
160+
* @dataProvider provideContentTypes()
161+
*/
162+
public function testSupportsFormOnly(string $contentType, bool $shouldSupport)
163+
{
164+
$request = new Request();
165+
$request->headers->set('CONTENT_TYPE', $contentType);
166+
$request->server->set('REQUEST_URI', '/login_check');
167+
$request->setMethod('POST');
168+
169+
$this->setUpAuthenticator(['form_only' => true]);
170+
171+
$this->assertSame($shouldSupport, $this->authenticator->supports($request));
172+
}
173+
174+
public function provideContentTypes()
175+
{
176+
yield ['application/json', false];
177+
yield ['application/x-www-form-urlencoded', true];
178+
}
179+
159180
private function setUpAuthenticator(array $options = [])
160181
{
161182
$this->authenticator = new FormLoginAuthenticator(new HttpUtils(), $this->userProvider, $this->successHandler, $this->failureHandler, $options);

0 commit comments

Comments
 (0)