Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Add authentication success sensitive event to authentication provider manager (rebase #26050) #30955

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

Conversation

curry684
Copy link
Contributor

@curry684 curry684 commented Apr 7, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #26050 #18494
License MIT
Doc PR symfony/symfony-docs#11334

Rebased #26050 at EUFOSSA

Thanks @robfrawley for the excellent work!

@xabbuh xabbuh added this to the next milestone Apr 7, 2019
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Now, you can hate me ;)

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Contracts\EventDispatcher\Event;
Copy link
Member

Choose a reason for hiding this comment

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

should be reverted: BC break :)

private $authenticationToken;
private $authenticationProviderClassName;

public function __construct(TokenInterface $preAuthenticationToken, TokenInterface $authenticationToken, ?string $authenticationProviderClassName = null)
Copy link
Member

Choose a reason for hiding this comment

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

please remove the? as our CS is to consider the null default means the same (it does)

*
* @return string|null Either a credentials password/secret/auth_key is returned or null on extraction failure
*/
public function getAuthenticationTokenPassword(?\Closure $extractor = null): ?string
Copy link
Member

Choose a reason for hiding this comment

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

?


private function tryCoercibleCredentialsPasswordToString($credentials): ?string
{
return is_scalar($credentials) || method_exists($credentials, '__toString')
Copy link
Member

Choose a reason for hiding this comment

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

should be on one line as we usually prefer long line in similar cases

};
};

$createHasStrCastableClass = function (?string $return = null) {
Copy link
Member

Choose a reason for hiding this comment

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

? (same below)

@curry684
Copy link
Contributor Author

curry684 commented Apr 7, 2019

Get me my headset back and I'll sort the mess out again 😄

@javiereguiluz
Copy link
Member

Event names are usually very descriptive ... so I find this new event name (AUTHENTICATION_SUCCESS_SENSITIVE) really unfortunate. It doesn't tell me at all what's this about :( All security events are "sensitive".

@curry684
Copy link
Contributor Author

curry684 commented Apr 8, 2019

@javiereguiluz fair point but I don't really see an alternative. Technically it IS the authentication success event, just called a second time before we do eraseCredentials so it's a sensitive variant of the success event. We could do something like AUTHENTICATION_SUCCESS_WITH_TOKEN or something but that seems overly verbose and no longer readable.

I'll take any suggestions here...

@aschempp
Copy link
Contributor

aschempp commented Apr 8, 2019

Isn't Symfony getting rid of event names anyway? So the event name should simply be the event class name?
https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching

@curry684
Copy link
Contributor Author

curry684 commented Apr 8, 2019

@aschempp correct but it would be inconsistent right now to follow that convention for the new event, and major B/C breakage to adapt all the others. So in core that's a job for later on.

@fabpot
Copy link
Member

fabpot commented Apr 8, 2019

I agree that we cannot remove the old ones, but there is no need to create a new one. People will eventually remove usage of the current names, so the inconsistency is not a problem IMHO.

@curry684
Copy link
Contributor Author

curry684 commented Apr 8, 2019

Fair enough, and just thinking some more about the name => how about AuthenticationAcceptedEvent?

It conveys that we do not yet consider the Authentication a success (because if you throw inside the Accepted it will fail still) but that we can confirm we are about to, and as such this is the time to do last call on the token that was accepted before we clean it up.

@aschempp
Copy link
Contributor

aschempp commented Apr 8, 2019

Maybe AuthenticationCredentialsEvent as the event is only there to get the credentials?

@curry684
Copy link
Contributor Author

curry684 commented Apr 8, 2019

As credentials are part of the token it would then have to be AuthenticationTokenEvent, but generally in Events we follow (rightfully imo) the convention of naming it after what happens instead of what is communicated (the payload of the event). Hence my suggestion as the event is dispatched at the point where we have accepted the token as valid authentication.

@nicolas-grekas
Copy link
Member

Isn't Symfony getting rid of event names anyway?

I'm not sure we are: core should be much more explicit than what is allowed for not-core. E.g. autowiring is not a feature we use in core.

@nicolas-grekas
Copy link
Member

oh, but the new event should be listed in src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

@nicolas-grekas
Copy link
Member

Thinking a bit about this approach, I have a different one to propose, see #31139

@javiereguiluz
Copy link
Member

@wouterj do you think this proposal fits well with the latest changes you are proposing in the Security component or is it unrelated? Thanks!

@wouterj
Copy link
Member

wouterj commented Sep 20, 2019

It's a bit hard to follow, as the discussion was inside multiple PRs and issues (#26050, #31139, #31843, #18494), but as far as I can see this PR is no longer needed.

#31843 build another approach to rehash passwords that was merged into 4.3 (https://symfony.com/blog/new-in-symfony-4-3-native-password-encoder). As far as I can see, rehashing credentials was the only reason for this event to exists.

@chalasr
Copy link
Member

chalasr commented Sep 21, 2019

As said, password rehashing is now supported. I'm going to close here until another use case comes out. Thank you @robfrawley and @curry684

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.

10 participants