Skip to content

Commit

Permalink
[Security] Tweak UsernamePasswordFormAuthenticationListener
Browse files Browse the repository at this point in the history
- Do not check twice for the only_post condition
- If the expected request is only_post, check only the post variables for the username and password parameters
  • Loading branch information
acasademont committed Oct 23, 2012
1 parent 188589c commit 3e58893
Showing 1 changed file with 8 additions and 11 deletions.
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)
}
}

$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 comments on commit 3e58893

Please sign in to comment.