Exemplo n.º 1
0
 /**
  * Updates a user password if a plain password is set
  *
  * @param OroUserInterface $user
  */
 public function updatePassword(OroUserInterface $user)
 {
     $password = $user->getPlainPassword();
     if (0 !== strlen($password)) {
         $encoder = $this->getEncoder($user);
         $user->setPassword($encoder->encodePassword($password, $user->getSalt()));
         $user->eraseCredentials();
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function assertRoles(UserInterface $user)
 {
     if (count($user->getRoles()) === 0) {
         $metadata = $this->getStorageManager()->getClassMetadata(ClassUtils::getClass($user));
         $roleClassName = $metadata->getAssociationTargetClass('roles');
         if (!is_a($roleClassName, 'Symfony\\Component\\Security\\Core\\Role\\RoleInterface', true)) {
             throw new \RuntimeException(sprintf('Expected Symfony\\Component\\Security\\Core\\Role\\RoleInterface, %s given', $roleClassName));
         }
         /** @var RoleInterface $role */
         $role = $this->getStorageManager()->getRepository($roleClassName)->findOneBy(['role' => User::ROLE_DEFAULT]);
         if (!$role) {
             throw new \RuntimeException('Default user role not found');
         }
         $user->addRole($role);
     }
 }
Exemplo n.º 3
0
 /**
  * We need to make sure to have at least one role.
  *
  * @param UserInterface $user
  * @throws \RuntimeException
  */
 protected function assertRoles(UserInterface $user)
 {
     if (count($user->getRoles()) === 0) {
         throw new \RuntimeException('User has not default role');
     }
 }