Fix Symfony deprecations

pull/3904/head
Julio Montoya 4 years ago
parent 7e4819be48
commit e6a5b36456
  1. 18
      config/packages/doctrine.yaml
  2. 8
      config/packages/prod/deprecations.yaml
  3. 6
      src/CoreBundle/Controller/ResetPasswordController.php
  4. 5
      src/CoreBundle/Entity/User.php
  5. 7
      src/CoreBundle/EventListener/CourseListener.php
  6. 7
      src/CoreBundle/EventListener/LegacyListener.php
  7. 11
      src/CoreBundle/Repository/Node/UserRepository.php
  8. 2
      src/CoreBundle/Resources/config/repositories.yml
  9. 9
      src/CoreBundle/Security/LoginFormAuthenticator.php

@ -18,25 +18,19 @@ doctrine:
uuid: Symfony\Bridge\Doctrine\Types\UuidType uuid: Symfony\Bridge\Doctrine\Types\UuidType
orm: orm:
auto_generate_proxy_classes: true auto_generate_proxy_classes: true
proxy_namespace: Proxies
proxy_dir: '%kernel.cache_dir%/doctrine/orm/Proxies'
metadata_cache_driver:
type: 'pool'
pool: 'doctrine.system_cache_pool'
query_cache_driver:
type: 'pool'
pool: 'doctrine.system_cache_pool'
result_cache_driver:
type: 'pool'
pool: 'doctrine.result_cache_pool'
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true auto_mapping: true
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
mappings: mappings:
gedmo_translatable: gedmo_translatable:
type: annotation type: annotation
prefix: ChamiloCore\Entity\Translation prefix: ChamiloCore\Entity\Translation
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity" dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity"
# dir: "%kernel.root_dir%/src/CoreBundle/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false is_bundle: false
gedmo_translator: gedmo_translator:

@ -0,0 +1,8 @@
# As of Symfony 5.1, deprecations are logged in the dedicated "deprecation" channel when it exists
#monolog:
# channels: [deprecation]
# handlers:
# deprecation:
# type: stream
# channels: [deprecation]
# path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"

@ -14,8 +14,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait; use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface; use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface; use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
@ -78,7 +78,7 @@ class ResetPasswordController extends AbstractController
* *
* @Route("/reset/{token}", name="app_reset_password") * @Route("/reset/{token}", name="app_reset_password")
*/ */
public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, string $token = null): Response public function reset(Request $request, UserPasswordHasherInterface $passwordHasher, string $token = null): Response
{ {
if ($token) { if ($token) {
// We store the token in session and remove it from the URL, to avoid the URL being // We store the token in session and remove it from the URL, to avoid the URL being
@ -113,7 +113,7 @@ class ResetPasswordController extends AbstractController
$this->resetPasswordHelper->removeResetRequest($token); $this->resetPasswordHelper->removeResetRequest($token);
// Encode the plain password, and set it. // Encode the plain password, and set it.
$encodedPassword = $passwordEncoder->encodePassword( $encodedPassword = $passwordHasher->encodePassword(
$user, $user,
$form->get('plainPassword')->getData() $form->get('plainPassword')->getData()
); );

@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity; use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface; use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\NilUuid; use Symfony\Component\Uid\NilUuid;
@ -60,7 +61,7 @@ use UserManager;
* @ORM\Entity * @ORM\Entity
* @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\UserListener"}) * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\UserListener"})
*/ */
class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface, PasswordAuthenticatedUserInterface
{ {
use TimestampableEntity; use TimestampableEntity;
@ -997,7 +998,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return $this; return $this;
} }
public function getPassword() public function getPassword(): ?string
{ {
return $this->password; return $this->password;
} }

@ -22,6 +22,7 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment; use Twig\Environment;
@ -35,10 +36,12 @@ class CourseListener
use ContainerAwareTrait; use ContainerAwareTrait;
private Environment $twig; private Environment $twig;
private AuthorizationCheckerInterface $authorizationChecker;
public function __construct(Environment $twig) public function __construct(Environment $twig, AuthorizationCheckerInterface $authorizationChecker)
{ {
$this->twig = $twig; $this->twig = $twig;
$this->authorizationChecker = $authorizationChecker;
} }
/** /**
@ -77,7 +80,7 @@ class CourseListener
// Check if URL has cid value. Using Symfony request. // Check if URL has cid value. Using Symfony request.
$courseId = (int) $request->get('cid'); $courseId = (int) $request->get('cid');
$checker = $container->get('security.authorization_checker'); $checker = $this->authorizationChecker;
/** @var EntityManager $em */ /** @var EntityManager $em */
$em = $container->get('doctrine')->getManager(); $em = $container->get('doctrine')->getManager();

@ -14,6 +14,7 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment; use Twig\Environment;
@ -26,10 +27,12 @@ class LegacyListener
use ContainerAwareTrait; use ContainerAwareTrait;
private Environment $twig; private Environment $twig;
private TokenStorageInterface $tokenStorage;
public function __construct(Environment $twig) public function __construct(Environment $twig, TokenStorageInterface $tokenStorage)
{ {
$this->twig = $twig; $this->twig = $twig;
$this->tokenStorage = $tokenStorage;
} }
public function onKernelRequest(RequestEvent $event): void public function onKernelRequest(RequestEvent $event): void
@ -69,7 +72,7 @@ class LegacyListener
} }
$twig = $this->twig; $twig = $this->twig;
$token = $container->get('security.token_storage')->getToken(); $token = $this->tokenStorage->getToken();
$userObject = null; $userObject = null;
if (null !== $token) { if (null !== $token) {

@ -57,6 +57,7 @@ use Doctrine\Persistence\ManagerRegistry;
use Exception; use Exception;
use SocialManager; use SocialManager;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
@ -68,22 +69,22 @@ use Symfony\Component\Serializer\Serializer;
class UserRepository extends ResourceRepository implements UserLoaderInterface, PasswordUpgraderInterface class UserRepository extends ResourceRepository implements UserLoaderInterface, PasswordUpgraderInterface
{ {
protected ?UserPasswordEncoderInterface $encoder = null; protected ?UserPasswordHasherInterface $hasher = null;
public function __construct(ManagerRegistry $registry) public function __construct(ManagerRegistry $registry)
{ {
parent::__construct($registry, User::class); parent::__construct($registry, User::class);
} }
public function setEncoder(UserPasswordEncoderInterface $encoder): void public function setHasher(UserPasswordHasherInterface $hasher): void
{ {
$this->encoder = $encoder; $this->hasher = $hasher;
} }
public function loadUserByUsername(string $username): ?User public function loadUserByIdentifier(string $identifier): ?User
{ {
return $this->findOneBy([ return $this->findOneBy([
'username' => $username, 'username' => $identifier,
]); ]);
} }

@ -28,7 +28,7 @@ services:
# User repository # User repository
Chamilo\CoreBundle\Repository\Node\UserRepository: Chamilo\CoreBundle\Repository\Node\UserRepository:
calls: calls:
- setEncoder: ['@security.user_password_encoder.generic'] - setHasher: ['@security.user_password_hasher']
- setAuthorizationChecker: ['@security.authorization_checker'] - setAuthorizationChecker: ['@security.authorization_checker']
- setRouter: ['@router'] - setRouter: ['@router']
- setSlugify: ['@cocur_slugify'] - setSlugify: ['@cocur_slugify']

@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@ -40,7 +41,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw
public SerializerInterface $serializer; public SerializerInterface $serializer;
public RouterInterface $router; public RouterInterface $router;
private UserPasswordEncoderInterface $passwordEncoder; private UserPasswordHasherInterface $passwordHasher;
private UserRepository $userRepository; private UserRepository $userRepository;
private CsrfTokenManagerInterface $csrfTokenManager; private CsrfTokenManagerInterface $csrfTokenManager;
private UrlGeneratorInterface $urlGenerator; private UrlGeneratorInterface $urlGenerator;
@ -49,7 +50,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw
//EntityManagerInterface $entityManager, //EntityManagerInterface $entityManager,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
RouterInterface $router, RouterInterface $router,
UserPasswordEncoderInterface $passwordEncoder, UserPasswordHasherInterface $passwordHasher,
//FormFactoryInterface $formFactory, //FormFactoryInterface $formFactory,
//HookFactory $hookFactory, //HookFactory $hookFactory,
UserRepository $userRepository, UserRepository $userRepository,
@ -57,7 +58,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw
SerializerInterface $serializer SerializerInterface $serializer
) { ) {
$this->router = $router; $this->router = $router;
$this->passwordEncoder = $passwordEncoder; $this->passwordHasher = $passwordHasher;
//$this->formFactory = $formFactory; //$this->formFactory = $formFactory;
//$this->hookFactory = $hookFactory; //$this->hookFactory = $hookFactory;
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
@ -133,7 +134,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw
{ {
error_log('login form'); error_log('login form');
return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); return $this->passwordHasher->isPasswordValid($user, $credentials['password']);
/*$hook = $this->hookFactory->build(CheckLoginCredentialsHook::class); /*$hook = $this->hookFactory->build(CheckLoginCredentialsHook::class);
if (empty($hook)) { if (empty($hook)) {

Loading…
Cancel
Save