<p dir="auto">To check if all routes have been secured properly it would be really good to have the <code class="notranslate">router:debug</code> command accept a role as parameter to only show the routes available to that role.</p>
<p dir="auto">Hello,</p>
<p dir="auto">Do you know if it's possible to check if a ROLE can access to a route depending on the configuration of the firewall.</p>
<p dir="auto">I would like to create a controller to redirect to a route automatically but only if the user have a ROLE allowed to access the route.</p>
<p dir="auto">for example, if I have the following configuration:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" access_control:
        - { path: ^/secured/activities, roles: ROLE_CLIENT }
        - { path: ^/secured/client/user, roles: ROLE_ADMINISTRATOR }"><pre class="notranslate"> <span class="pl-ent">access_control</span>:
        - <span class="pl-s">{ path: ^/secured/activities, roles: ROLE_CLIENT }</span>
        - <span class="pl-s">{ path: ^/secured/client/user, roles: ROLE_ADMINISTRATOR }</span></pre></div>
<p dir="auto">From a controller I would like to be able to check like this:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$targetPath = $request-&gt;getSession()-&gt;get('_security.target_path');

if ($this-&gt;securityContext-&gt;isGrantedForRoute('ROLE_ADMINISTRATOR', $targetPath) {
    return new RedirectResponse($targetPath);
}"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>targetPath</span> = <span class="pl-s1"><span class="pl-c1">$</span>request</span>-&gt;<span class="pl-en">getSession</span>()-&gt;<span class="pl-en">get</span>(<span class="pl-s">'_security.target_path'</span>);

<span class="pl-k">if</span> (<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">securityContext</span>-&gt;<span class="pl-en">isGrantedForRoute</span>(<span class="pl-s">'ROLE_ADMINISTRATOR'</span>, <span class="pl-s1"><span class="pl-c1">$</span>targetPath</span>) {
    return <span class="pl-k">new</span> <span class="pl-v">RedirectResponse</span>(<span class="pl-s1"><span class="pl-c1">$</span>targetPath</span>);
}</pre></div>
<p dir="auto">isGrantedRoute doesn't exists, but it's just to show the thing I would like to do. I would like to be able to do that because, I have a login form and I would like to redirect on same the path the user was before he loose it's session, but depending on it's rights, we can't redirect on this path. I created an ExceptionListener like this: <a href="http://symfony.com/doc/master/cookbook/security/target_path.html" rel="nofollow">http://symfony.com/doc/master/cookbook/security/target_path.html</a> to set the last route in session.</p>
<p dir="auto">For example if the user connects with ROLE_ADMINISTRATOR, and access to /secured/client/user, wait 30 min, loose the session and reconnect with ROLE_CLIENT, we must not redirect him on /secured/client/user.</p>