-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Security] [Bug] User switching is not available for pre-authenticated users #2172
Comments
Is your code snippet the problem or the solution? For quick reference, here is the file now: |
My code snippet is solution, but I'm not sure that everything will be OK with that patch. Why do we need to check that $token is instance of PreAuthenticatedToken only and verify a user name to skip authentication? |
@schmittjoh ping |
There is a fix, but it was never merged? What happened? |
Well, we are not sure it was a fix. teh guy submitting it closed the PR before it got reviewed, and without explaining why. |
I'm running into this same problem. I tried the code given by lisachenko and the submitted PR, but neither are working for me. Forgive my naive attempt to fix this, I'm certainly not an expert at the Security Component. One problem I've found is that the SwitchUserListener only uses UsernamePasswordToken tokens. This seems to mean the token never gets set in the securityContext in the PreAuthenticatedListener. If I change the SwitchUserListener to only produce PreAuthenticatedToken tokens the token at least shows up in the SecurityContext in the AbstractPreAuthenticatedListener handle function. At this point the problem is that the PreAuthenticatedToken generated by the SwitchUserListener isn't authenticated, so it doesn't get returned by this line of code and accepted by the system as the "real" token. Long story short, I think the problem is two fold, one being that SwitchUserListener only creates UsernamePasswordToken tokens and that AbstractPreAuthenticatedListener handler function doesn't handle existing tokens that aren't authenticated and don't match the user returned by getPreAuthenticatedData very well. |
+1 |
FYI - it does appear that @lisachenko solution works still, the lines are slightly different but as far as I can tell it looks like it is working. @stof you see any reason that his solution should not work? I can make an updated PR if you'd like. |
This is currently the oldest still open bug of Symfony 😄 |
I worked on it using your different comments but the new behaviour breaks an existing test. |
…able classes (1ed) This PR was merged into the 3.4 branch. Discussion ---------- [Routing] Fix loading multiple class annotations for invokable classes | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | - The support for full route definition for invokable controllers as class annotation was introduced by #2172, but that works with one route only, which is inconsistent with how `@Route` works at other places. This PR adds support for multiple class annotations for invokable controllers and fixes the inconsistency. <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 2a9c668 [Routing] Fix loading multiple class annotations for invokable classes
I have non-stateless authentication with x509 and want to enable user switching.
Expected that user switching should work.
Actual result: current user remains active
Bug detailed description:
Current user is authenticated with x509 certificate, so in the security context there is a PreAuthenticatedToken and session store it. Next step is to switch user. When user is switching then SwitchUserListener replaces existing PreAuthenticatedToken with UsernamePasswordToken and stores it in the security context and in the session, after that we have redirect to our page. We have valid token on the next request, however x509 authentication listener will be invoked again and it overrides existing UsernamePasswordToken.
How to fix that bug:
AbstractPreAuthenticatedListener class should not override existing authenticated tokens in the security context.
The text was updated successfully, but these errors were encountered: