New in Symfony 5.3: Improvements for Security Users

Renamed User to InMemoryUser¶

        Contributed by 
        Robin Chalas 
        in #40443.

In Symfony applications, the memory user provider allows to create users (and define their credentials) in a configuration file which is loaded in memory, without using databases or any other persisting service. Although this user provider is only for prototypes or very small/special applications, it’s based on a class called User (the entire namespace is Symfony\Component\Security\Core\User\User). This confuses some newcomers, who think this is the main User class in Symfony security. That’s why in Symfony 5.3 we’ve renamed User to InMemoryUser and UserChecker to InMemoryUserChecker to better convey their purpose (in 5.3 the old names still work but they are deprecated and in Symfony 6.0 they will be removed): 1 2 3 4 5 # config/packages/security.yaml security: password_hashers:

  • Symfony\Component\Security\Core\User\User: bcrypt
  • Symfony\Component\Security\Core\User\InMemoryUser: bcrypt Renamed username to identifier¶

        Contributed by 
        Wouter De Jong
         in #40403.

Another source of confusion related to users is the concept of “username” which is used in the Symfony security. In many applications this username is not a traditional username, but an email or even some API token. That’s why in Symfony 5.3 we’ve decided to avoid this confusion and we’ve renamed “username” to “user identifier”. This might require some changes in your application code (in 5.3 the old names still work but they are deprecated and in Symfony 6.0 they will be removed): UserInterface::getUsername() is now UserInterface::getUserIdentifier() loadUserByUsername() is now loadUserByUserIdentifier(), both in user loaders and user providers UsernameNotFoundException is now UserNotFoundException Decoupled Passwords from Users¶

        Contributed by 
        Robin Chalas 
        in #40267.

The Symfony\Component\Security\Core\User\UserInterface is implemented by all the security users in Symfony applications. Sadly, this interface is a product of its time and it contains some methods that are no longer used in modern applications. The first unneeded method is getSalt(), which is no longer necessary when using modern password hashing algorithms (bcrypt, Argon2, etc.) This method has been moved to a new LegacyPasswordAuthenticatedUserInterface. The other method is getPassword() which is no longer needed in many password-less features, such as login links. This method has been moved to a new PasswordAuthenticatedUserInterface. In Symfony 5.3, UserInterface implements these two interfaces, so you don’t need to change anything in your code. In Symfony 6.0 that will be no longer the case and you’ll need to implement the new interfaces if you need those methods.

                Sponsor the Symfony project.

http://feedproxy.google.com/~r/symfony/blog/~3/rVtcrgKL4Mg/new-in-symfony-5-3-improvements-for-security-users

Établi 4y | 3 mai 2021 à 07:20:06


Connectez-vous pour ajouter un commentaire

Autres messages de ce groupe

Symfony 2024 Year in Review

This blog post highlights the key accomplishments of the Symfony project in 2024. We are grateful for your continuous support, which enabled the Symfony project to achieve a remarkable year.

Releases

7 janv. 2025 à 13:40:05 | Symfony
A Week of Symfony #940 (30 December 2024 - 5 January 2025)

This week, Symfony 6.4.17, 7.1.10 and 7.2.2 maintenance versions were released. In addition, we published more information about the upcoming SymfonyOnline January 2025 conference.

Symfony developmen

5 janv. 2025 à 10:30:12 | Symfony
SymfonyOnline January 2025: Join us in 2 weeks!

Get ready for the exciting SymfonyOnline January 2025, kicking off shortly on January 16-17! There’s still time to register and join the international online Symfony conference—along with pre-

2 janv. 2025 à 12:50:08 | Symfony
Symfony 6.4.17 released

Symfony 6.4.17 has just been released. Here is the list of the most important changes since 6.4.16:

bug #59304 [PropertyInfo] Remove @internal from PropertyReadInfo and PropertyWriteInfo (Dario G
31 déc. 2024 à 16:50:11 | Symfony
Symfony 7.1.10 released

Symfony 7.1.10 has just been released. Here is the list of the most important changes since 7.1.9:

bug #59304 [PropertyInfo] Remove @internal from PropertyReadInfo and PropertyWriteInfo (Dario Gu
31 déc. 2024 à 16:50:10 | Symfony
Symfony 7.2.2 released

Symfony 7.2.2 has just been released. Here is the list of the most important changes since 7.2.1:

bug #59304 [PropertyInfo] Remove @internal from PropertyReadInfo and PropertyWriteInfo (Dario Gua
31 déc. 2024 à 16:50:10 | Symfony
A Week of Symfony #939 (23-29 December 2024)

This week, we launched the new Twig playground, a tool that lets you test and experiment with Twig features in a safe, sandboxed environment. While Symfony development activity was lighter than usual

29 déc. 2024 à 11:30:09 | Symfony