Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen are user roles refreshed and how to force it?
    primarykey
    data
    text
    <p>First off, I'm not using FOSUserBundle and I can't because I'm porting a legacy system which has its own Model layer (no Doctrine/Mongo/whatsoever here) and other very custom behavior.</p> <p>I'm trying to connect my legacy role system with Symfony's so I can use native symfony security in controllers and views.</p> <p>My first attempt was to load and return all of the user's roles in the <code>getRoles()</code> method from the <code>Symfony\Component\Security\Core\User\UserInterface</code>. At first, it looked like that worked. But after taking a deeper look, I noticed that these roles are only refreshed when the user logs in. This means that if I grant or revoke roles from a user, he will have to log out and back in for the changes to take effect. However, if I revoke security roles from a user, I want that to be applied immediately, so that behavior isn't acceptable to me.</p> <p>What I want Symfony to do is to reload a user's roles on every request to make sure they're up-to-date. I have implemented a custom user provider and its <code>refreshUser(UserInterface $user)</code> method is being called on every request but the roles somehow aren't being refreshed.</p> <p>The code to load / refresh the user in my UserProvider looks something like this:</p> <pre><code>public function loadUserByUsername($username) { $user = UserModel::loadByUsername($username); // Loads a fresh user object including roles! if (!$user) { throw new UsernameNotFoundException("User not found"); } return $user; } </code></pre> <p>(<code>refreshUser</code> looks similar)</p> <p>Is there a way to make Symfony refresh user roles on each request?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload