From 1210dae10589515d6f3824c75639342c5e1d52dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Oct 2015 14:51:41 +0200 Subject: remove old implementation for login/register/recover --- .../Encoder/WallabagPasswordEncoder.php | 87 --------------------- .../Provider/WallabagAuthenticationProvider.php | 89 ---------------------- .../Validator/WallabagUserPasswordValidator.php | 51 ------------- 3 files changed, 227 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php delete mode 100644 src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php delete mode 100644 src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php (limited to 'src/Wallabag/CoreBundle/Security') diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php b/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php deleted file mode 100644 index 98b4e86b..00000000 --- a/src/Wallabag/CoreBundle/Security/Authentication/Encoder/WallabagPasswordEncoder.php +++ /dev/null @@ -1,87 +0,0 @@ -algorithm = $algorithm; - $this->encodeHashAsBase64 = $encodeHashAsBase64; - $this->iterations = $iterations; - } - - public function setUsername($username) - { - $this->username = $username; - } - - /** - * {@inheritdoc} - */ - public function encodePassword($raw, $salt) - { - if ($this->isPasswordTooLong($raw)) { - throw new BadCredentialsException('Invalid password.'); - } - - if (!in_array($this->algorithm, hash_algos(), true)) { - throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm)); - } - - $salted = $this->mergePasswordAndSalt($raw, $salt); - $digest = hash($this->algorithm, $salted, true); - - // "stretch" hash - for ($i = 1; $i < $this->iterations; ++$i) { - $digest = hash($this->algorithm, $digest.$salted, true); - } - - return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest); - } - - /** - * {@inheritdoc} - * - * We inject the username inside the salted password - */ - protected function mergePasswordAndSalt($password, $salt) - { - if (null === $this->username) { - throw new \LogicException('We can not check the password without a username.'); - } - - if (empty($salt)) { - return $password; - } - - return $password.$this->username.$salt; - } - - /** - * {@inheritdoc} - */ - public function isPasswordValid($encoded, $raw, $salt) - { - return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt)); - } -} diff --git a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php b/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php deleted file mode 100644 index cf3cb051..00000000 --- a/src/Wallabag/CoreBundle/Security/Authentication/Provider/WallabagAuthenticationProvider.php +++ /dev/null @@ -1,89 +0,0 @@ -encoderFactory = $encoderFactory; - $this->userProvider = $userProvider; - } - - /** - * {@inheritdoc} - */ - protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token) - { - $currentUser = $token->getUser(); - if ($currentUser instanceof UserInterface) { - if ($currentUser->getPassword() !== $user->getPassword()) { - throw new BadCredentialsException('The credentials were changed from another session.'); - } - } else { - if ('' === ($presentedPassword = $token->getCredentials())) { - throw new BadCredentialsException('The presented password cannot be empty.'); - } - - // give username, it's used to hash the password - $encoder = $this->encoderFactory->getEncoder($user); - $encoder->setUsername($user->getUsername()); - - if (!$encoder->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { - throw new BadCredentialsException('The presented password is invalid.'); - } - } - } - - /** - * {@inheritdoc} - */ - protected function retrieveUser($username, UsernamePasswordToken $token) - { - $user = $token->getUser(); - if ($user instanceof UserInterface) { - return $user; - } - - try { - $user = $this->userProvider->loadUserByUsername($username); - - if (!$user instanceof UserInterface) { - throw new AuthenticationServiceException('The user provider must return a UserInterface object.'); - } - - return $user; - } catch (UsernameNotFoundException $notFound) { - $notFound->setUsername($username); - throw $notFound; - } catch (\Exception $repositoryProblem) { - $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem); - $ex->setToken($token); - throw $ex; - } - } -} diff --git a/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php b/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php deleted file mode 100644 index 52062773..00000000 --- a/src/Wallabag/CoreBundle/Security/Validator/WallabagUserPasswordValidator.php +++ /dev/null @@ -1,51 +0,0 @@ -tokenStorage = $tokenStorage; - $this->encoderFactory = $encoderFactory; - } - - /** - * {@inheritdoc} - */ - public function validate($password, Constraint $constraint) - { - if (!$constraint instanceof UserPassword) { - throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); - } - - $user = $this->tokenStorage->getToken()->getUser(); - - if (!$user instanceof UserInterface) { - throw new ConstraintDefinitionException('The User object must implement the UserInterface interface.'); - } - - // give username, it's used to hash the password - $encoder = $this->encoderFactory->getEncoder($user); - $encoder->setUsername($user->getUsername()); - - if (!$encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt())) { - $this->context->addViolation($constraint->message); - } - } -} -- cgit v1.2.3