1
votes

I'm using SonataAdmin with sonata.admin.security.handler.role (so I don't use ACLs here).

I'm trying to restrict access to an object with a custom voter.

service

security.access.company_voter:
    class:      Application\...\Voter\CompanyVoter
    public:     false
    tags:
       - { name: security.voter }

voter Application...\Voter\CompanyVoter.php

#...
public function vote(TokenInterface $token, $object, array $attributes) 
{
    get_class($object);
}
#...

But I'm always getting an instance of Application\...\Voter\CompanyVoter instead of the expected object to restrict.

What can be the reason ?

Are you telling me that Sonata does not pass the object to isGranted() when using the role security handler ?

1
Quite related but this one is about SonataAdmin. The other is asked more globally. - Pierre de LESPINAY
so a voter object gets inserted basically into it's own vote method? ... that sounds pretty strange to me :D Where do you try to check your object and how exactly ? can you give some details about that? - Nicolai Fröhlich
Basically each time SonataAdmin fires is_granted(). Specifically I need to restrict the access to user edition. - Pierre de LESPINAY
This question might somehow be related. stackoverflow.com/questions/17706428/… ... the guy asking receives an instance of Symfony\Component\HttpFoundation\Request instead of his object's FQCN. Did you manage to solve this issue meanwhile? - Nicolai Fröhlich

1 Answers

2
votes

After hours of searching, I noticed that the object received is always NULL (get_class(NULL) returns the current class).

After days of seeking, It turns out that, as opposed to the ACL handler, the default implementation of the Role handler doesn't pass the current object to isGranted()

I had then to extend it.

See a nice monologue in my github issue for more detail.