Skip to content
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

Closed
lisachenko opened this issue Sep 14, 2011 · 11 comments
Closed

Comments

@lisachenko
Copy link

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.

    // AbstractPreAuthenticatedListener:64-68
    if (null !== $token = $this->securityContext->getToken()) {
        if ($token->isAuthenticated()) {
            return;
        }
    }
@ericclemmons
Copy link
Contributor

Is your code snippet the problem or the solution?

For quick reference, here is the file now:

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php#L65

@lisachenko
Copy link
Author

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?

@stof
Copy link
Member

stof commented Apr 4, 2012

@schmittjoh ping

@ghost
Copy link

ghost commented Sep 14, 2014

There is a fix, but it was never merged? What happened?

@stof
Copy link
Member

stof commented Sep 25, 2014

Well, we are not sure it was a fix. teh guy submitting it closed the PR before it got reviewed, and without explaining why.

@dlancea
Copy link

dlancea commented Oct 29, 2014

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.

@daum
Copy link
Contributor

daum commented May 13, 2015

+1

@daum
Copy link
Contributor

daum commented May 13, 2015

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.

@ghost
Copy link

ghost commented Dec 24, 2015

This is currently the oldest still open bug of Symfony 😄
@daum Do you like to investigate it?

@pasdeloup
Copy link
Contributor

I worked on it using your different comments but the new behaviour breaks an existing test.
Feedbacks about my solution are welcome.

@pasdeloup
Copy link
Contributor

According to both @stof and @fabpot this issue should not be fixed and closed.
I submitted a PR for documentation about it #6673

@fabpot fabpot closed this as completed Jun 22, 2016
fabpot added a commit that referenced this issue Apr 17, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants