I use ZfcRbac with DoctrineORMModule in an application and actually the
method getRoles of my identity returns an array of strings, which is the
return expected by ZfcRbac.
So, this does not sounds like a bug in Zend\Permissions\Rbac.
Anyway, the Rbac component is undergoing some refactorings as you can
see in https://github.com/zendframework/zf2/pull/4265.
But later I'll check better your approach to think about some modification.
Cheers,
Em 07-05-2013 23:42, Steptom escreveu:
Hi !
I'm trying to use ZfcRbac module with DoctrineORMModule and I encounter some
problems.
My problem is that the isGranted() function doesn't work.
So, I'm looking for someone who has already play with these modules.
I have debugging step by step the program and the problem seems to be cause
by the following method in the Rbac class of Zend Framework 2 :
-------------------------------------------------
public function getRole($objectOrName)
{
if (!is_string($objectOrName) && !$objectOrName instanceof
RoleInterface) {
throw new Exception\InvalidArgumentException(
'Expected string or implement
\Zend\Permissions\Rbac\RoleInterface'
);
}
$it = new RecursiveIteratorIterator($this,
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($it as $leaf) {
if ((is_string($objectOrName) && $leaf->getName() ==
$objectOrName) || $leaf == $objectOrName) {
return $leaf;
}
}
throw new Exception\InvalidArgumentException(sprintf(
'No child with name "%s" could be found',
is_object($objectOrName) ? $objectOrName->getName() :
$objectOrName
));
}
-------------------------------------------------
The parameter passed to the getRole() function is the role entity instance.
So the test realize by this method is "$leaf == $objectOrName" but this test
is false because $leaf and $objectOrName refers to 2 differents objects.
My Role entity class implements \Zend\Permissions\Rbac\RoleInterface but the
ZF2 don't use the getName() method to realize its test... (if the test was
"$leaf->getName() == $objectOrName->getName()") it would be OK...
So my questions are :
- is there a bug in the Rbac class of Zf2 ?
- is there a bug in the ZfcRbac Module ?
- the getRoles function implemented by my identity class return an array of
role objet entity. Must it return either an array of string (the name of the
roles) ? (the documentation ZfcRbac is not clear on this subject)
I hope that the explanation of my problem is clear.
Don't hesitate to ask me if you need more precisions.
In advance, thanks for your answers.
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZfcRbac-with-DoctrineORMModule-problem-with-isGranted-method-tp4659951.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
Daniel Gimenes
github.com/danizord <http://github.com/danizord>
twitter.com/danizord <http://twitter.com/danizord>
fb.com/danizord <http://fb.com/danizord>