diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 1f56560b80..55d00a6723 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -18,25 +18,19 @@ doctrine: uuid: Symfony\Bridge\Doctrine\Types\UuidType orm: 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 auto_mapping: true + query_cache_driver: + type: pool + pool: doctrine.system_cache_pool + result_cache_driver: + type: pool + pool: doctrine.result_cache_pool mappings: gedmo_translatable: type: annotation prefix: ChamiloCore\Entity\Translation 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 is_bundle: false gedmo_translator: diff --git a/config/packages/prod/deprecations.yaml b/config/packages/prod/deprecations.yaml new file mode 100644 index 0000000000..920a06197b --- /dev/null +++ b/config/packages/prod/deprecations.yaml @@ -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" diff --git a/src/CoreBundle/Controller/ResetPasswordController.php b/src/CoreBundle/Controller/ResetPasswordController.php index f7ee33a442..53e2a49444 100644 --- a/src/CoreBundle/Controller/ResetPasswordController.php +++ b/src/CoreBundle/Controller/ResetPasswordController.php @@ -14,8 +14,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Address; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait; use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface; use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface; @@ -78,7 +78,7 @@ class ResetPasswordController extends AbstractController * * @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) { // 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); // Encode the plain password, and set it. - $encodedPassword = $passwordEncoder->encodePassword( + $encodedPassword = $passwordHasher->encodePassword( $user, $form->get('plainPassword')->getData() ); diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 98c9004280..1389e8110a 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\EquatableInterface; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Uid\NilUuid; @@ -60,7 +61,7 @@ use UserManager; * @ORM\Entity * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\UserListener"}) */ -class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface +class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface, PasswordAuthenticatedUserInterface { use TimestampableEntity; @@ -997,7 +998,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso return $this; } - public function getPassword() + public function getPassword(): ?string { return $this->password; } diff --git a/src/CoreBundle/EventListener/CourseListener.php b/src/CoreBundle/EventListener/CourseListener.php index b421884a55..5fa6affff7 100644 --- a/src/CoreBundle/EventListener/CourseListener.php +++ b/src/CoreBundle/EventListener/CourseListener.php @@ -22,6 +22,7 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; 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\User\UserInterface; use Twig\Environment; @@ -35,10 +36,12 @@ class CourseListener use ContainerAwareTrait; private Environment $twig; + private AuthorizationCheckerInterface $authorizationChecker; - public function __construct(Environment $twig) + public function __construct(Environment $twig, AuthorizationCheckerInterface $authorizationChecker) { $this->twig = $twig; + $this->authorizationChecker = $authorizationChecker; } /** @@ -77,7 +80,7 @@ class CourseListener // Check if URL has cid value. Using Symfony request. $courseId = (int) $request->get('cid'); - $checker = $container->get('security.authorization_checker'); + $checker = $this->authorizationChecker; /** @var EntityManager $em */ $em = $container->get('doctrine')->getManager(); diff --git a/src/CoreBundle/EventListener/LegacyListener.php b/src/CoreBundle/EventListener/LegacyListener.php index 013af2b8fd..bdfe69f21a 100644 --- a/src/CoreBundle/EventListener/LegacyListener.php +++ b/src/CoreBundle/EventListener/LegacyListener.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\User\UserInterface; use Twig\Environment; @@ -26,10 +27,12 @@ class LegacyListener use ContainerAwareTrait; private Environment $twig; + private TokenStorageInterface $tokenStorage; - public function __construct(Environment $twig) + public function __construct(Environment $twig, TokenStorageInterface $tokenStorage) { $this->twig = $twig; + $this->tokenStorage = $tokenStorage; } public function onKernelRequest(RequestEvent $event): void @@ -69,7 +72,7 @@ class LegacyListener } $twig = $this->twig; - $token = $container->get('security.token_storage')->getToken(); + $token = $this->tokenStorage->getToken(); $userObject = null; if (null !== $token) { diff --git a/src/CoreBundle/Repository/Node/UserRepository.php b/src/CoreBundle/Repository/Node/UserRepository.php index cd8654c225..3a02532f6b 100644 --- a/src/CoreBundle/Repository/Node/UserRepository.php +++ b/src/CoreBundle/Repository/Node/UserRepository.php @@ -57,6 +57,7 @@ use Doctrine\Persistence\ManagerRegistry; use Exception; use SocialManager; 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\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; @@ -68,22 +69,22 @@ use Symfony\Component\Serializer\Serializer; class UserRepository extends ResourceRepository implements UserLoaderInterface, PasswordUpgraderInterface { - protected ?UserPasswordEncoderInterface $encoder = null; + protected ?UserPasswordHasherInterface $hasher = null; public function __construct(ManagerRegistry $registry) { 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([ - 'username' => $username, + 'username' => $identifier, ]); } diff --git a/src/CoreBundle/Resources/config/repositories.yml b/src/CoreBundle/Resources/config/repositories.yml index d874b63b9c..542e679521 100644 --- a/src/CoreBundle/Resources/config/repositories.yml +++ b/src/CoreBundle/Resources/config/repositories.yml @@ -28,7 +28,7 @@ services: # User repository Chamilo\CoreBundle\Repository\Node\UserRepository: calls: - - setEncoder: ['@security.user_password_encoder.generic'] + - setHasher: ['@security.user_password_hasher'] - setAuthorizationChecker: ['@security.authorization_checker'] - setRouter: ['@router'] - setSlugify: ['@cocur_slugify'] diff --git a/src/CoreBundle/Security/LoginFormAuthenticator.php b/src/CoreBundle/Security/LoginFormAuthenticator.php index 2d16875abc..345d4c47b2 100644 --- a/src/CoreBundle/Security/LoginFormAuthenticator.php +++ b/src/CoreBundle/Security/LoginFormAuthenticator.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -40,7 +41,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw public SerializerInterface $serializer; public RouterInterface $router; - private UserPasswordEncoderInterface $passwordEncoder; + private UserPasswordHasherInterface $passwordHasher; private UserRepository $userRepository; private CsrfTokenManagerInterface $csrfTokenManager; private UrlGeneratorInterface $urlGenerator; @@ -49,7 +50,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw //EntityManagerInterface $entityManager, UrlGeneratorInterface $urlGenerator, RouterInterface $router, - UserPasswordEncoderInterface $passwordEncoder, + UserPasswordHasherInterface $passwordHasher, //FormFactoryInterface $formFactory, //HookFactory $hookFactory, UserRepository $userRepository, @@ -57,7 +58,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw SerializerInterface $serializer ) { $this->router = $router; - $this->passwordEncoder = $passwordEncoder; + $this->passwordHasher = $passwordHasher; //$this->formFactory = $formFactory; //$this->hookFactory = $hookFactory; $this->userRepository = $userRepository; @@ -133,7 +134,7 @@ class LoginFormAuthenticator extends AbstractGuardAuthenticator implements Passw { error_log('login form'); - return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); + return $this->passwordHasher->isPasswordValid($user, $credentials['password']); /*$hook = $this->hookFactory->build(CheckLoginCredentialsHook::class); if (empty($hook)) {