8000 [Security] Tweak UsernamePasswordFormAuthenticationListener by acasademont · Pull Request #5824 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Tweak UsernamePasswordFormAuthenticationListener #5824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(SecurityContextInterface $securityContext, Authentic
*/
protected function requiresAuthentication(Request $request)
{
if ($this->options['post_only'] && !$request->isMethod('post')) {
if ($this->options['post_only'] && !$request->isMethod('POST')) {
return false;
}

Expand All @@ -67,14 +67,6 @@ protected function requiresAuthentication(Request $request)
*/
protected function attemptAuthentication(Request $request)
{
if ($this->options['post_only'] && !$request->isMethod('post')) {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Authentication method not supported: %s.', $request->getMethod()));
}

return null;
}

if (null !== $this->csrfProvider) {
$csrfToken = $request->get($this->options['csrf_parameter'], null, true);

Expand All @@ -83,8 +75,13 @@ protected function attemptAuthentication(Request $request)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong but as said in the description of the PR, the attemptAuthentication method is called only if the requiresAuthentication does not return false. If this premise is correct, the post_only option is true and the request method is not POST, requiresAuthentication will return false and attemptAuthentication will not be called. Therefore, the condition you are asking is useless as it will be false all the time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this was introduced in #4524


$username = trim($request->get($this->options['username_parameter'], null, true));
$password = $request->get($this->options['password_parameter'], null, true);
if ($this->options['post_only']) {
$username = trim($request->request->get($this->options['username_parameter'], null, true));
$password = $request->request->get($this->options['password_parameter'], null, true);
} else {
$username = trim($request->get($this->options['username_parameter'], null, true));
$password = $request->get($this->options['password_parameter'], null, true);
}

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

Expand Down
0