/** * {@inheritdoc} */ protected function getRedirectionUrl(UserInterface $user) { $rolesTab = $user->getRoles(); if (in_array('ROLE_ADMIN', $rolesTab, true) || in_array('ROLE_SUPER_ADMIN', $rolesTab, true)) { return $this->container->get('router')->generate('sonata_admin_dashboard'); } else { return $this->container->get('router')->generate('sonata_user_profile_show'); } }
/** * */ public function updateRoles(UserInterface $user) { $roles = $user->getRoles(); $roleRepository = $this->objectManager->getRepository('WeavingTheWebUserBundle:Role'); foreach ($roles as $role) { $roleName = (string) $role; $roleEntity = $roleRepository->findOneByRole($roleName); $user->removeRole($role); $user->addRole($roleEntity); } }
function it_load_user_by_username(SamlAuth $auth, UserInterface $user, UserManagerInterface $userManager) { $auth->getAttributes()->shouldBeCalled(); $auth->getUsername()->shouldBeCalled(); $auth->isAuthenticated()->shouldBeCalled(); $user->getUsername()->shouldBeCalled(); $user->getRoles()->shouldBeCalled(); $userManager->findUserByUsername(self::USERNAME)->shouldBeCalled(); $samlUser = new SamlUser('*****@*****.**', ['ROLE_USER'], []); $this->loadUserByUsername('*****@*****.**')->shouldBeLike($samlUser); }
protected function createToken($firewall, UserInterface $user) { return new UsernamePasswordToken($user, null, $firewall, $user->getRoles()); }
/** * add the symfony-login "manually". * * use the symfony token-storage for the generated UsernamePasswordToken * to access the (logged in) user later (e.g. to check for roles or permissions) * * the given $passwordHash must match the encrypted password in the user-object * * before and after the generation/setting of the token, the events "secotrust.user_login.before" * and "secotrust.user_login.after" are called, if some EventListeners are configured * * @param \FOS\UserBundle\Model\UserInterface $user * @param $passwordHash */ private function userLoginAction(\FOS\UserBundle\Model\UserInterface $user, $passwordHash) { // call the pre-login-event $event = new Event(); $this->dispatcher->dispatch('secotrust.user_login.before', $event); if ($user->getPassword() !== $passwordHash) { // stop the login-action, when the password doesn't match return; } $token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles()); $this->token_storage->setToken($token); // call the post-login-event $event = new Event(); $this->dispatcher->dispatch('secotrust.user_login.after', $event); }
/** * Authenticate a user with Symfony Security * * @param \FOS\UserBundle\Model\UserInterface $user */ protected function authenticateUser(UserInterface $user) { $providerKey = $this->container->getParameter('fos_user.firewall_name'); $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); $this->container->get('security.context')->setToken($token); }
/** * Authenticate a user with Symfony Security * * @param Boolean $reAuthenticate * @return null */ protected function authenticateUser(UserInterface $user, $reAuthenticate = false) { $providerKey = $this->container->getParameter('fos_user.provider_key'); $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles()); if (true === $reAuthenticate) { $token->setAuthenticated(false); } $this->container->get('security.context')->setToken($token); }