瀏覽代碼

Supprimer des deprecated

François Drouhard 3 年之前
父節點
當前提交
c47f5eece2
共有 5 個文件被更改,包括 26 次插入15 次删除
  1. 7 4
      config/packages/security.yaml
  2. 0 1
      config/services.yaml
  3. 14 5
      src/Entity/User.php
  4. 2 2
      src/Security/LoginFormAuthenticator.php
  5. 3 3
      src/Service/UserManager.php

+ 7 - 4
config/packages/security.yaml

@@ -1,6 +1,10 @@
 security:
-    encoders:
-        App\Entity\User: sha512
+    enable_authenticator_manager: true
+
+    password_hashers:
+        App\Entity\User:
+            algorithm: auto
+
     
     # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
 
@@ -10,7 +14,7 @@ security:
     # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
 
     providers:
-        main:
+        app_user_provider:
             entity:
                 class: App\Entity\User
                 property: username
@@ -21,7 +25,6 @@ security:
             security: false
 
         main:
-            anonymous: ~
             user_checker: App\Security\UserChecker
             guard:
                 authenticators:

+ 0 - 1
config/services.yaml

@@ -44,7 +44,6 @@ services:
     App\Service\FilmCreationListener:
         arguments:
             - '@App\Service\Mattermost'
-            - '@session'
         tags:
             - { name: doctrine.event_listener, event: postPersist }
 

+ 14 - 5
src/Entity/User.php

@@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
+use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
 
 /**
  * User
@@ -17,7 +18,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  * @UniqueEntity(fields="token", message="Erreur, token non unique")
  *
  */
-class User implements UserInterface
+class User implements UserInterface,PasswordAuthenticatedUserInterface
 {
     /**
      * @var int
@@ -172,11 +173,19 @@ class User implements UserInterface
     }
 
     /**
-     * Get username
-     *
-     * @return string
+     * @deprecated since Symfony 5.3, use getUserIdentifier instead
      */
     public function getUsername()
+    {
+        return (string) $this->username;
+    }
+
+    /**
+     * Get UserIdentifier
+     * 
+     * @Return string
+     */
+    public function getUserIdentifier()
     {
         return $this->username;
     }
@@ -265,7 +274,7 @@ class User implements UserInterface
      *
      * @return string
      */
-    public function getPassword()
+    public function getPassword() : ?string
     {
         return $this->password;
     }

+ 2 - 2
src/Security/LoginFormAuthenticator.php

@@ -6,8 +6,8 @@ use App\Entity\User;
 use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
-use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
 use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
 use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
@@ -28,7 +28,7 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
     private $csrfTokenManager;
     private $passwordEncoder;
 
-    public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordEncoderInterface $passwordEncoder)
+    public function __construct(EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, CsrfTokenManagerInterface $csrfTokenManager, UserPasswordHasherInterface $passwordEncoder)
     {
         $this->entityManager = $entityManager;
         $this->urlGenerator = $urlGenerator;

+ 3 - 3
src/Service/UserManager.php

@@ -4,7 +4,7 @@ namespace App\Service;
 
 use App\Entity\User;
 use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
+use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
 use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
 
 /**
@@ -19,7 +19,7 @@ class UserManager
      * UserManager constructor.
      * @param EntityManagerInterface $em
      */
-    public function __construct(EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, TokenGeneratorInterface $tokenGenerator)
+    public function __construct(EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, TokenGeneratorInterface $tokenGenerator)
     {
         $this->em = $em;
         $this->passwordEncoder = $passwordEncoder;
@@ -54,7 +54,7 @@ class UserManager
     }
     public function enregistrerUser (User $user)
     {
-        $encoded = $this->passwordEncoder->encodePassword($user, $user->getPassword());
+        $encoded = $this->passwordEncoder->hashPassword($user, $user->getPassword());
         $user->setPassword($encoded);
         $this->generateToken($user);
         $this->em->persist($user);