Last active
August 29, 2015 14:04
-
-
Save tobalsan/d355ade3c0a6ba555d6a to your computer and use it in GitHub Desktop.
Symfony2: Manage user roles and authentication state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$token = $this->get('security.context')->getToken(); | |
// do things that change user's roles | |
$token->setAuthenticated(false); | |
/* OR */ | |
// Add new role | |
$user->addRole('ROLE_NEW'); | |
// persist the user and it's new role to database | |
// ... | |
// Generate new token with new roles | |
$token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken( | |
$user, | |
null, | |
'main', | |
$user->getRoles() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment