Example #1
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     if (!$this->cm->get('oro_sso.enable_google_sso')) {
         throw new \Exception('SSO is not enabled');
     }
     $username = $response->getUsername();
     if ($username === null) {
         throw new BadCredentialsException('Bad credentials');
     }
     if (!$this->isEmailEnabledForOauth($response->getEmail())) {
         throw new EmailDomainNotAllowedException('Bad credentials');
     }
     $user = $this->userManager->findUserBy([$this->getOAuthProperty($response) => $username]);
     if (!$user) {
         $user = $this->userManager->findUserByEmail($response->getEmail());
         if ($user) {
             $user->setGoogleId($username);
             $this->userManager->updateUser($user);
         }
     }
     if (!$user || !$user->isEnabled()) {
         throw new BadCredentialsException('Bad credentials');
     }
     return $user;
 }
Example #2
0
 /**
  * Set status as current
  *
  * @param User   $user
  * @param Status $status
  * @param bool   $reloadUser
  */
 public function setCurrentStatus(User $user, Status $status = null, $reloadUser = true)
 {
     $user->setCurrentStatus($status);
     $this->um->updateUser($user);
     if ($reloadUser) {
         $this->um->reloadUser($user);
     }
 }
 public function testUpdateUser()
 {
     $user = $this->getUser()->setUsername(self::TEST_NAME)->setEmail(self::TEST_EMAIL)->setPlainPassword('password');
     $this->om->expects($this->once())->method('persist')->with($this->equalTo($user));
     $this->om->expects($this->once())->method('flush');
     $this->repository->expects($this->once())->method('findOneBy')->with($this->equalTo(array('role' => User::ROLE_DEFAULT)))->will($this->returnValue(new Role(User::ROLE_DEFAULT)));
     $this->userManager->updateUser($user);
     $this->assertEquals(self::TEST_EMAIL, $user->getEmail());
 }
Example #4
0
 /**
  * @param User   $user
  * @param Status $status
  * @param bool   $updateCurrentStatus
  */
 protected function onSuccess(User $user, Status $status, $updateCurrentStatus)
 {
     $status->setUser($user);
     $this->em->persist($status);
     if ($updateCurrentStatus) {
         $user->setCurrentStatus($status);
         $this->um->updateUser($user);
         $this->um->reloadUser($user);
     }
     $this->em->flush();
 }
Example #5
0
 /**
  * Load default administrator
  *
  * @param ObjectManager $manager
  * @throws \RuntimeException
  */
 public function load(ObjectManager $manager)
 {
     $adminRole = $manager->getRepository('OroUserBundle:Role')->findOneBy(['role' => LoadRolesData::ROLE_ADMINISTRATOR]);
     if (!$adminRole) {
         throw new \RuntimeException('Administrator role should exist.');
     }
     if ($this->isUserWithRoleExist($manager, $adminRole)) {
         return;
     }
     $businessUnit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneBy(['name' => LoadOrganizationAndBusinessUnitData::MAIN_BUSINESS_UNIT]);
     $organization = $this->getReference('default_organization');
     $adminUser = $this->userManager->createUser();
     $adminUser->setUsername(self::DEFAULT_ADMIN_USERNAME)->setEmail(self::DEFAULT_ADMIN_EMAIL)->setEnabled(true)->setOwner($businessUnit)->setPlainPassword(md5(uniqid(mt_rand(), true)))->addRole($adminRole)->addBusinessUnit($businessUnit)->setOrganization($organization)->addOrganization($organization);
     $this->userManager->updateUser($adminUser);
 }
Example #6
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Expected Symfony\Component\Security\Core\Role\RoleInterface, \stdClass given
  */
 public function testNotSupportedRole()
 {
     $user = new User();
     $this->metadata->expects($this->once())->method('getAssociationTargetClass')->willReturn('\\stdClass');
     $this->om->expects($this->never())->method('persist')->with($this->equalTo($user));
     $this->om->expects($this->never())->method('flush');
     $repository = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\Repository\\UserApiRepository')->disableOriginalConstructor()->getMock();
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
     $this->userManager->updateUser($user);
 }
Example #7
0
 /**
  * Process form
  *
  * @param  User $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(User $entity)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $entity->setPlainPassword($this->form->get('password')->getData());
             $entity->setPasswordChangedAt(new \DateTime());
             try {
                 $this->mailerProcessor->sendChangePasswordEmail($entity);
             } catch (\Exception $e) {
                 $this->form->addError(new FormError($this->translator->trans('oro.email.handler.unable_to_send_email')));
                 $this->logger->error('Email sending failed.', ['exception' => $e]);
                 return false;
             }
             $this->userManager->updateUser($entity);
             return true;
         }
     }
     return false;
 }