ZF-Commons / zfc-rbac

Role-based access control module to provide additional features on top of Zend\Permissions\Rbac
BSD 3-Clause "New" or "Revised" License
181 stars 111 forks source link

Problem with 'ZfcRbac\Service\AuthorizationService' service #123

Closed parsadev closed 10 years ago

parsadev commented 10 years ago

Hi,

There is a problem when I'm calling 'ZfcRbac\Service\AuthorizationService' service:

ZfcRbac\Exception\RuntimeException

File:

/home/myapp/vendor/ZfcRbac/src/ZfcRbac/Service/AuthorizationService.php:114

Message:

ZfcRbac expects your identity to implement ZfcRbac\Identity\IdentityInterface, "string" given

Stack trace:

#0 /home/myapp/module/Application/src/Application/Controller/IndexController.php(15): ZfcRbac\Service\AuthorizationService->getIdentityRoles()
#1 /home/myapp/vendor/zf2/library/Zend/Mvc/Controller/AbstractActionController.php(83): Application\Controller\IndexController->indexAction()
#2 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#3 /home/myapp/vendor/zf2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#4 /home/myapp/vendor/zf2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#5 /home/myapp/vendor/zf2/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 /home/myapp/vendor/zf2/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#7 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#8 /home/myapp/vendor/zf2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#9 /home/myapp/vendor/zf2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 /home/myapp/vendor/zf2/library/Zend/Mvc/Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /home/myapp/public/index.php(29): Zend\Mvc\Application->run()
#12 {main}

IdentityProvider returns identity as a string, but ZfcRbac\Service\AuthorizationService expects returned identity implement IdentityInterface .

Regards, Parsa

bakura10 commented 10 years ago

Hi,

IdentityProvider is expected to return an object that return IdentityInterface (https://github.com/ZF-Commons/ZfcRbac/blob/master/src/ZfcRbac/Identity/IdentityProviderInterface.php#L29)

You must therefore make your User entity implement this interface.

parsadev commented 10 years ago

Hi,

Yes, your codes say it must implement IdentityInterface, but in the documentation there is no any reference to this, so I confused that it is because of mistake in the code layer or documentation is incomplete.

Thanks

bakura10 commented 10 years ago

You shoul follow the interface.

By the way please notice a new version is under the way, I'll ipdatz the documentation to outline that :).

Envoyé de mon iPhone

Le 15 déc. 2013 à 11:52, parsadev notifications@github.com a écrit :

Hi,

Yes, your codes say it must implement IdentityInterface, but in the documentation there is no any reference to this, so I confused that it is because of mistake in the code layer or documentation is incomplete.

Thanks

— Reply to this email directly or view it on GitHub.

rizaozden commented 10 years ago

hey, I'm getting this same message but how to implement this interface. Could you please redirect me to some positive direction.

Thanks.

danizord commented 10 years ago

@rizaozden You should implement IdentityInterface in your User entity as follows: https://github.com/ZF-Commons/zfc-rbac/blob/master/docs/07.%20Cookbook.md#using-zfcrbac-with-doctrine-orm