Skip to content

[Security] Fixed persistence of AuthenticationException #15557

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

Closed
wants to merge 1 commit into from

Conversation

rpg600
Copy link
Contributor

@rpg600 rpg600 commented Aug 14, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

During the refresh of an authenticated user the potential AuthenticationException is ignored, now it is persisted in session just like after an authentication failure.


if ($exception instanceof UsernameNotFoundException) {
$session->set(SecurityContextInterface::LAST_USERNAME, $exception->getUsername());
}
Copy link
Member

Choose a reason for hiding this comment

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

setting things in the session must not be done like this all the time:

  • the request may not have a Session in it, which triggers a fatal error in your code
  • if the firewall is configured as stateless, nothing should be set in the session even if there is a session

@rpg600 rpg600 changed the title Fixed persistence of AuthenticationException [Security] Fixed persistence of AuthenticationException Aug 14, 2015
@linaori
Copy link
Contributor

linaori commented Aug 15, 2015

@rpg600 This would only fix the case where the refresh cannot find the user anymore when a UsernameNotFoundException is thrown. Then you add the username which was not found in the session so it shows up in the login form.

I don't think this is what you intended to change. This will also alter the flow in the location where this method is called. Can you add tests to verify this is all working the way you want it to?

@rpg600
Copy link
Contributor Author

rpg600 commented Aug 15, 2015

@iltar This is exactly my use case, i faced this problem when i configured two providers having the same user class (but this is another issue) and i didn't know where it come from. It can be also useful for auth exceptions thrown by the user land.

@rpg600 rpg600 force-pushed the fix-auth-error branch 3 times, most recently from cc21c6c to d6aebb1 Compare August 31, 2015 13:25
@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

What about #12465 instead?

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Dec 6, 2016
@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

probably fixed by #21865

@fabpot fabpot closed this Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants