Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 how to disable default voter?

Tags:

symfony

I have five custom voters in my application and use strategy "consensus".

Sometimes my voters not work properly and after debugging I have found the reason.

The standard Symfony RoleHierarchyVoter always returns "1", therefore sum of "granted" results equals to sum of "deny" results. So, I need to disable this Voter, because I don't use RoleHierarchy.

1) How can I disable Voter in config?

2) Does it exist another solution for this issue?

Thanks a lot for any help!

UPDATED.

So, I have created own RoleHierarchyVoter which always return false. This Voter replace standard Voter, but I'm not sure this solution is true way. Maybe any other solutions?

like image 616
Sergio Ivanuzzo Avatar asked Oct 26 '15 13:10

Sergio Ivanuzzo


1 Answers

So, currently I have solved the problem by creating own RoleHierarchyVoter, which always return false.

Currently impossible to remove definition of standard RoleHierarchyVoter, because it's registered with priority TYPE_BEFORE_OPTIMIZATION and performed before my own compiler.

Btw, you can find in SecurityBundle/DependencyInjection/SecurityExtension.php next lines:

private function createRoleHierarchy($config, ContainerBuilder $container)
    {
        if (!isset($config['role_hierarchy'])) {
            $container->removeDefinition('security.access.role_hierarchy_voter');

            return;
        }

        $container->setParameter('security.role_hierarchy.roles', $config['role_hierarchy']);
        $container->removeDefinition('security.access.simple_role_voter');
    }

Even when I set role_hierarchy: ~, isset($config['role_hierarchy'] will return true.

This issue has reported as bug https://github.com/symfony/symfony/issues/16358

like image 81
Sergio Ivanuzzo Avatar answered Nov 09 '22 07:11

Sergio Ivanuzzo