10000 [Security] [Firewall] Bug fixed in SimplePreAuthenticationListener when createToken() not return TokenInterface object by ad3n · Pull Request #11414 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] [Firewall] Bug fixed in SimplePreAuthenticationListener when createToken() not return TokenInterface object #11414

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 11 commits into from

Conversation

ad3n
Copy link
@ad3n ad3n commented Jul 18, 2014
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #11490
License MIT
Doc PR

@ad3n ad3n changed the title Bug fixed in SimplePreAuthenticationListener when createToken() not return TokenInterface object [Security] [Firewall] Bug fixed in SimplePreAuthenticationListener when createToken() not return TokenInterface object Jul 18, 2014
@ad3n
Copy link
Author
ad3n commented Jul 18, 2014

http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#only-authenticating-for-certain-urls

I can't use this case because createToken() must return TokenInteface object

@@ -3,3 +3,4 @@ composer.lock
composer.phar
autoload.php
/vendor/
/nbproject/private/
Copy link
Member

Choose a reason for hiding this comment

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

This must be ignored locally instead, because they are specific to your development environment, not to Symfony (and you should ignore all your netbeans files, not only the private ones. We don't want the other netbeans files in the repo either): https://help.github.com/articles/ignoring-files

Copy link
Author

Choose a reason for hiding this comment

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

@stof 👍 thanks for the response... i will push again

@@ -3,3 +3,4 @@ composer.lock
composer.phar
autoload.php
/vendor/
/nbproject/
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a global ignore file to ignore IDE specific files

Copy link
Member

Choose a reason for hiding this comment

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

@yguedidi I said it should be ignored locally, not in Symfony

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I know, that's why I said to use a global .gitignore file
EDIT: Or you mean a .gitignore file in /nbproject ?

}
$this->securityContext->setToken(null);

return;
Copy link
Member

Choose a reason for hiding this comment

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

you are still modifying the behavior of the code when adding this return statement here.

the code if ($this->simpleAuthenticator instanceof AuthenticationSuccessHandlerInterface) { below cannot be reached anymore while it was previously

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the token on security context is always set to null.

Copy link
Author

Choose a reason for hiding this comment

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

@jakzal : 👍 thanks for correction, i update my code

@stof : i will improve my code also

@weaverryan
Copy link
Member

I've also realized this "oddity". I wasn't sure if it was a bug, but I realized that it's very inflexible currently (and yes, I think the example he linked to is therefore wrong in the docs). I really like the idea of being able to return nothing from createToken and have it just skip authentication on this request.

@ad3n ad3n added the Security label Jul 19, 2014
@ad3n
Copy link
Author
ad3n commented Jul 21, 2014

sorry for the late response :-) and i'm sorry for my stupid code

@peterrehm
Copy link
Contributor

ping @jakzal @stof

Can you have a look at that fix? If it gets merged #11490 and symfony/symfony-docs#3815 can be closed.

@cirovargas
Copy link

watching

@fabpot
Copy link
Member
fabpot commented Sep 16, 2014

Returning an anonymous token is the way to go and it is the most "consistent" way.

But, as the goal of the Simple* classes is to actually make things easier for the developer, I tend to think allowingnull here might be a good option. So, technically, this is not a bug fix but rather an "enhancement" of the current situation. That said, I'm always a bit reluctant to have 2 ways of doing the same thing.

Moreover, if we only merge this into master (aka 2.6), the documentation will have to describe both ways: using an anonymous token before 2.6, and null as of 2.6 as this is the easiest thing to do.

So, my proposal is to allow returning null for all Symfony versions. Does it sound good to everyone?

@fabpot
Copy link
Member
fabpot commented Sep 16, 2014

By the way, this PR cannot work as is because when a Token is null, the following code will fail:

         if ($this->simpleAuthenticator instanceof AuthenticationSuccessHandlerInterface) {
             $response = $this->simpleAuthenticator->onAuthenticationSuccess($request, $token);

@weaverryan
Copy link
Member

I agree with merging this into all versions - allowing null suddenly isn't a BC break as returning null currently causes an error.

About the code Fabien just posted, I think we should change the if logic in the try statement so that if createToken returns null, we just return from the function immediately:

$token = $this->simpleAuthenticator->createToken($request, $this->providerKey);

// allow null to be returned to skip authentication
if ($token === null) {
    return;
}

$token = $this->authenticationManager->authenticate($token);
$this->securityContext->setToken($token);

This also removes a line in the current PR that sets the token to null that I don't think should be there.

Thanks!

@fabpot
Copy link
Member
6D40 fabpot commented Sep 23, 2014

I've finished this PR in #12002 and based it on 2.4. Thanks @ihsanudin for your work on this PR.

@fabpot fabpot closed this Sep 23, 2014
fabpot added a commit that referenced this pull request Sep 24, 2014
…Listener when createToken() not return TokenInterface object (adenkejawen, fabpot)

This PR was merged into the 2.4 branch.

Discussion
----------

[Security] [Firewall] Bug fixed in SimplePreAuthenticationListener when createToken() not return TokenInterface object

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #11490, #11414
| License       | MIT
| Doc PR        |

This is a follow-up for #11414 on the right branch.

Commits
-------

faa8e98 fixed bug
e85cb7f added the possibility to return null from SimplePreAuthenticationListener
@ad3n ad3n deleted the security_bug_fixed branch November 7, 2014 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants
0