/** * {@inheritdoc} */ public function refreshUser(UserInterface $user) { $class = get_class($user); if (!$this->supportsClass($class)) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class)); } return $this->userService->getUserByLogin($user->getUsername()); }
/** * @param string $username * @return \AppBundle\Entity\User|null */ public function loadUserByUsername($username) { try { $user = $this->userService->getUserByUsername($username); return $user; } catch (UserNotFoundException $e) { return null; } }
private function getExistingRoles() { $roleHierarchy = $this->userService->getsecurityRoles(); $roles = array_keys($roleHierarchy); $theRoles['not-defined'] = 'not-defined'; $theRoles['ROLE_USER'] = '******'; foreach ($roles as $role) { $theRoles[$role] = $role; } $theRoles['ROLE_API'] = 'ROLE_API'; return $theRoles; }
public function testGetUnknowdUser() { $mockRepo = $this->prophesize(UserRepository::class); $mockRepo->findOneBy(["usernameCanonical" => "user"])->willReturn(null)->shouldBeCalledTimes(1); $mockObjectManager = $this->prophesize(ObjectManager::class); $mockObjectManager->getRepository('AppBundle:User')->willReturn($mockRepo->reveal())->shouldBeCalledTimes(1); $mockRegistry = $this->prophesize(Registry::class); $mockRegistry->getManager()->willReturn($mockObjectManager->reveal())->shouldBeCalledTimes(1); $mockSession = $this->prophesize(Session::class); $mockTokenInterface = $this->prophesize(TokenStorageInterface::class); $userService = new UserService($mockRegistry->reveal(), $mockSession->reveal(), $mockTokenInterface->reveal(), null); $userService->getUser('user'); }