title: Dynamic roles in symfony
body: <p>I have been trying to assign dynamic roles to users in my application. I tried to use an event listener to do that, but it just added the dynamic role for that one http request.</p>
  
  <p>This is the function in my custom event listener that adds the role.</p>
  
  <pre><code>public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) {
  
      $user = $this-&gt;security-&gt;getToken()-&gt;getUser();
  
      $role = new Role;
      $role-&gt;setId('ROLE_NEW');
      $user-&gt;addRole($role);
  }
  </code></pre>
  
  <p>But I am not sure if this is even possible to do with event listeners. I just need to find a nice way how to add the roles for the whole time the user is logged. I would appreciate any help and suggestions.</p>