Today I encountered a tricky problem with Symfony. If you change properties like the name or the password of your session user the information will be updated in the session automatically. Unfortunately there is one difference: If you change your model in a way that your getRoles method returns a different array of roles these are not updated in the session by default.
Symfony will just use the old roles array until the next real authentication.

So here is the simply solution: Just unauthenticate the user and Symfony will try to authenticate it again with the given credentials. This way the new roles will be loaded into the session.

public function activateAccountAction() {
    $token = $this->get( 'security.context' )->getToken();
    $token->getUser()->setSomethingThatAffectsTheRoleArray( true );
    // flush document manager or sth like that
    $token->setAuthenticated( false );
}

Tags: , , , , ,

RELATED POSTS

COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">