-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fixed auth provider authenticate() cannot return void #24644
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
Conversation
@@ -26,12 +26,15 @@ public function testSupports() | |||
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); | |||
} | |||
|
|||
/** | |||
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should also use @expectedExceptionMessage
to be sure it is the right one being thrown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added.
@@ -38,7 +38,7 @@ public function __construct($key) | |||
public function authenticate(TokenInterface $token) | |||
{ | |||
if (!$this->supports($token)) { | |||
return; | |||
throw new BadCredentialsException('The token is not supported by this authentication provider.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use AuthenticationException
, not BadCredentialsException
, as it is not a case of bad credentials (it is a case of a bug in the supports
implementation or in the calling code ignoring supports
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
Update: Use |
@glye if you want to have the PR appearing as merged rather than closed, I suggest you to squash your fixup commit yourselves. |
The AuthenticationManagerInterface requires that authenticate() must return a TokenInterface, never null. Several authentication providers are violating this. Changed to throw exception instead.
8eabff8
to
6e18b56
Compare
Right! Squashed. |
Thank you @glye. |
…n void (glye) This PR was merged into the 2.7 branch. Discussion ---------- [Security] Fixed auth provider authenticate() cannot return void | Q | A | ------------- | --- | Branch? | 2.7 and up | Bug fix? | yes | New feature? | no | BC breaks? | no (arguably) | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The `AuthenticationManagerInterface` [requires](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Security/Core/Authentication/AuthenticationManagerInterface.php#L30) that `authenticate()` must return a TokenInterface, never null. Several authentication providers are violating this. Changed to throw exception instead. See discussion in earlier PR #24585 which was changing the docblock rather than the implementations. Commits ------- 6e18b56 [Security] Fixed auth provider authenticate() cannot return void
The
AuthenticationManagerInterface
requires thatauthenticate()
must return a TokenInterface, never null. Several authentication providers are violating this. Changed to throw exception instead.See discussion in earlier PR #24585 which was changing the docblock rather than the implementations.