8000 merged branch acasademont/tweak_userform_security_listener (PR #5824) · symfony/symfony@9681973 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9681973

Browse files
committed
merged branch acasademont/tweak_userform_security_listener (PR #5824)
This PR was merged into the master branch. Commits ------- 3e58893 [Security] Tweak UsernamePasswordFormAuthenticationListener Discussion ---------- [Security] Tweak UsernamePasswordFormAuthenticationListener Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/acasademont/symfony.png)](http://travis-ci.org/acasademont/symfony) Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - Improvements: - Do not check twice for the ```only_post``` condition. The condition in the ```attemptAuthentication``` method is useless as this method will never be called if the previous ```requiresAuthentication``` call returns false. - If the expected request is ```only_post```, check only the POST variables for the username and password parameters. Otherwise, query params and attributes are checked before. - Use POST instead of post for correctness
2 parents 1f1beb1 + 3e58893 commit 9681973

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(SecurityContextInterface $securityContext, Authentic
5555
*/
5656
protected function requiresAuthentication(Request $request)
5757
{
58-
if ($this->options['post_only'] && !$request->isMethod('post')) {
58+
if ($this->options['post_only'] && !$request->isMethod('POST')) {
5959
return false;
6060
}
6161

@@ -67,14 +67,6 @@ protected function requiresAuthentication(Request $request)
6767
*/
6868
protected function attemptAuthentication(Request $request)
6969
{
70-
if ($this->options['post_only'] && !$request->isMethod('post')) {
71-
if (null !== $this->logger) {
72-
$this->logger->debug(sprintf('Authentication method not supported: %s.', $request->getMethod()));
73-
}
74-
75-
return null;
76-
}
77-
7870
if (null !== $this->csrfProvider) {
7971
$csrfToken = $request->get($this->options['csrf_parameter'], null, true);
8072

@@ -83,8 +75,13 @@ protected function attemptAuthentication(Request $request)
8375
}
8476
}
8577

86-
$username = trim($request->get($this->options['username_parameter'], null, true));
87-
$password = $request->get($this->options['password_parameter'], null, true);
78+
if ($this->options['post_only']) {
79+
$username = trim($request->request->get($this->options['username_parameter'], null, true));
80+
$password = $request->request->get($this->options['password_parameter'], null, true);
81+
} else {
82+
$username = trim($request->get($this->options['username_parameter'], null, true));
83+
$password = $request->get($this->options['password_parameter'], null, true);
84+
}
8885

8986
$request->getSession()->set(SecurityContextInterface::LAST_USERNAME, $username);
9087

0 commit comments

Comments
 (0)
0