symfony - Passing object to custom voter? -
i've been reading creating custom voters in symfony 2. according this page, possible pass object isgranted method of securitycontext, have done in own controller:
$page = new page(); if ( ! $securitycontext->isgranted('content_create', $page)) { throw new accessdeniedexception('fail'); }
it looks vote method should accepting it, however, when call get_class on $object parameter, instead of getting page entity, get:
symfony\component\httpfoundation\request
public function vote(tokeninterface $token, $object, array $attributes) { print_r(get_class($object)); die(); return voterinterface::access_abstain; }
my voter defined service in services.yml file:
content_security.access.my_voter: class: my\bundle\security\authorization\voter\myvoter arguments: ["@service_container"] public: false tags: - { name: security.voter }
where going wrong?
any advice appreciated.
thanks
every registered voters called when calls isgranted.
the fact framework (or bundle f.e) calls isgranted on request.
you have use supportsclass, supportsattribute, ... in order check if object 1 you're waiting for, , if not return voterinterface::abstain value.
take @ existing implementations (in framework (like rolevoter) or here: https://github.com/knplabs/knpradbundle/blob/develop/security/voter/isownervoter.php#l35-l45
Comments
Post a Comment