-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Rename UserInterface::getUsername() to getUserIdentifier() #40403
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
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.
Looks good! Thank you for this, Wouter.
Given that DebugClassLoader
will automatically trigger a deprecation notice thanks to the added @method
phpdoc, I'm fine with the proposed BC layer and the additional notices it introduces.
Regarding tests, we should keep some legacy ones using the deprecated method to make sure everything keeps working.
src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php
Outdated
Show resolved
Hide resolved
Thanks Robin!
Oh, that's nice. The powers of the
Yes, sure thing. I've basically been find&replacing |
...ony/Bundle/SecurityBundle/Tests/Functional/Bundle/GuardedBundle/AuthenticationController.php
Show resolved
Hide resolved
I guess we will need to rename |
e800acc
to
1c7b338
Compare
*/ | ||
public function getMessageKey() | ||
{ | ||
return 'Username could not be found.'; |
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.
How would we consider BC on this public error message? I think we cannot change it?
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.
No, it's not BC break. We can change it, but (not a blocker) that invalidates all translations (so, we need updates on translations as well).
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.
that also break things if a project was customizing the translation messages in their own messages, as they won't be overriding the translation being used anymore.
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.
After @stof's comment, I think it's best to keep the message unchanged.
Also, User identifier could not be found
is a much to technical error message to have as a default user-friendly message imho. I think most applications that care already updated this to say e.g. "E-mailaddress could not be found", so "Username" seems a good default for the others.
8a13540
to
cc659eb
Compare
For reference, I consider this PR to be "feature complete". However, we do need to have more tests to make sure all authentication providers/listeners can work with both the old and new names. I'll add these over the next few days. |
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.
Huge work!
src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Tests/Exception/UsernameNotFoundExceptionTest.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/EventListener/UserProviderListener.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/User/UserProviderInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Tests/Processor/SwitchUserTokenProcessorTest.php
Outdated
Show resolved
Hide resolved
a0a9bfe
to
279f410
Compare
279f410
to
e3c8b30
Compare
I think this PR is ready. However, 2 comments are left unresolved (open discussion), and the travis high builds are failing (I guess I need to submit another PR for 5.2 to change all tests to fix them?). appveyor builds have a timeout, they were green before. |
The merge of the User rename makes a lot of conflicts here, sorry about that :( |
@wouterj Do you have time to rebase this PR? |
e3c8b30
to
835cb92
Compare
Rebased. I believe the deps=high builds will be fixed when #40609 is merged (other failures are unrelated). I'll rebase this PR again when that PR is merged up to 5.x. |
…terface classes in the tests (wouterj) This PR was merged into the 5.2 branch. Discussion ---------- [Security] Use concrete UserInterface and UserProviderInterface classes in the tests | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | n/a Fixes failing deps=high builds in #40403 Commits ------- 89d9de2 Use concrete user related classes in the tests
835cb92
to
08dcf39
Compare
(Hopefully last) rebase needed |
08dcf39
to
33bee77
Compare
If we ignore psalm (which we should in this PR), we're finally green. Thanks for your help @chalasr! |
33bee77
to
8afd7a3
Compare
Thank you @wouterj. |
…shlow) This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [make:user] implement getUserIdentifier if required handle `getUsername()` -> `getUserIdentifier()` in Symfony 5.3 symfony/symfony#40403 Commits ------- 1d83924 [make:user] implement getUserIdentifier if required
* | ||
* @return string The username | ||
*/ | ||
public function getUsername(); |
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.
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.
See #41493
…of '{user_identifier}' in LDAP configuration (EXT - THERAGE Kevin) This PR was merged into the 6.2 branch. Discussion ---------- [Ldap] Deprecate '{username}' parameter use in favour of '{user_identifier}' in LDAP configuration | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | This PR aims to fix a missing forward compatibility as done in src/Symfony/Component/Ldap/Security/LdapUserProvider.php at line 80 when authenticating with LDAP and using the following configuration : ```yaml security: // ... firewalls:œ // ... main: form_login_ldap: // ... query_string: '(whatever={user_identifier})' dn_string: 'uid={user_identifier},dc=example,dc=com' ``` instead of : ```yaml security: // ... firewalls: // ... main: form_login_ldap: // ... query_string: '(whatever={username})' dn_string: 'uid={username},dc=example,dc=com' ``` maybe related to : #40403 Commits ------- 6dd1221 [Ldap] Deprecate '{username}' parameter use in favour of '{user_identifier}' in LDAP configuration
…ute from the XSD (MatTheCat) This PR was merged into the 6.4 branch. Discussion ---------- [SecurityBundle] Remove unused memory users’ `name` attribute from the XSD | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT The related config has been deprecated in #40403 and removed in #41613. Commits ------- 656f498 [SecurityBundle] Remove unused memory users’ `name` attribute from the XSD
This continues the great work by @chalasr in #40267 and rounds up the
UserInterface
cleanup.The
getUsername()
has been a point of confusion for many years. In today's applications, many domains no longer have a username, but instead rely on a user's email address or the like. Even more, this username has to be unique for all Security functionality to work correctly - so it's more confusing in complex applications relying on e.g. "username+company" to be unique.This PR proposes to rename the method to
getUserIdentifier()
, to more clearly indicate the goal of the method (note: I'm open for any other suggestion).For BC, the
getUsername()
method is deprecated in 5.3 andgetUserIdentifier()
will be added to theUserInterface
in 6.0. PHPdocs are used to improve type-hinting for 5.3 & 5.4. Both authentication managers (the legacy and experimental one) check the authenticated user object and trigger a deprecation ifgetUserIdentifier()
is not implemented.getUsername()
in the application code.Consistent with these changes, I've also done the same BC change for
TokenInterface::getUsername()
.PersistentTokenInterface::getUsername()
UserProviderInterface::loadUserByUsername()
&UsernameNotFoundException
UserLoaderInterface::loadUserByUsername()
I'm very much looking forward for feedback and help for this important, but BC-heavy, rename. 😃