Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:05:02+00:00 2026-06-10T04:05:02+00:00

I have a Controller action (the Controller has $this->securityContext set to $this->get(‘security.context’) via JMSDiExtraBundle):

  • 0

I have a Controller action (the Controller has $this->securityContext set to $this->get('security.context') via JMSDiExtraBundle):

$user = $this->securityContext->getToken()->getUser();
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');

if ($this->securityContext->isGranted('ROLE_ADMIN') === false) {
    $myGroups = $groupRepo->findByLeader($user);
} else {
    $myGroups = $groupRepo->findAll();
}

When I log in to the dev environment and check the profiler, I can see that I have the ROLE_ADMIN role granted, but I still get the filtered list of Groups.

I have put some debugging code in my Controller, and Symfony’s RoleVoter.php. The string representation of the Token in my Controller ($this->securityContext->getToken()) and the one in RoleVoter.php are the same, but when I use $token->getRoles(), I get two different arrays.

My Users and Roles are stored in the database via the User and Role entities. Is this a bug that I found or am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:05:05+00:00Added an answer on June 10, 2026 at 4:05 am

    Finally got it. A dim idea hit my mind a minute ago. The problem was caused my own RoleHierarchyInterface implementation. My original idea was to copy Symfony’s own, but load it from the ORM instead of security.yml. But because of this, I had to totally rewrite the buildRoleMap() function. The diff is as follows:

     private function buildRoleMap()
     {
         $this->map = array();
         $roles = $this->roleRepo->findAll();
         foreach ($roles as $mainRole) {
             $main = $mainRole->getRole();
     -       $this->map[$main] = array();
     +       $this->map[$main] = array($main);
             foreach ($mainRole->getInheritedRoles() as $childRole) {
                 $this->map[$main][] = $childRole->getRole();
                 // TODO: This is one-level only. Get as deep as possible.
                 // BEWARE OF RECURSIVE NESTING!
                 foreach ($childRole->getInheritedRoles() as $grandchildRole) {
                     $this->map[$main][] = $grandchildRole->getRole();
                 }
             }
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have an MVC controller that has this Action Method: [HttpPost] public ActionResult SubmitAction()
i have a link <a id=DownloadLink href='controller/action' target=_blank>Download File</a> that has to open a
I have a controller named Content, which has an Index action, which is associated
If i have a Controller Action that may recieve both HTTP GET and HTTP
This is working, but how??? I have a controller action for a post: [AcceptVerbs(HttpVerbs.Post
I have a controller action in my project that has a situation where it
I have a Web API controller action which has a parameter of type CommandMessage.
So I have this controller called Cars, and it has: namespace MySite.Controllers { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.