I am trying to follow the zfc-rbac tutorial. I got stuck right away. I guess I need to create a service, but the tutorial has no hint about how to create one.
Thanks for your help.
module.config.php
---------------
'service_manager' => array(
'factories' => array(
'Zend\Authentication\AuthenticationService' => function($sm) {
// Create your authentication service!
}
),
),
'zfc_rbac' => [
'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW,
'guards' => [
'ZfcRbac\Guard\RouteGuard' => [
//ADMIN ACCOUNT GUARDS
'user' => ['admin-master'],
'user/login' => ['guest'],
'user/logout' => ['admin-master', 'merchant-worker', 'guest'],
'user/register' => ['admin-master', 'merchant-admin', 'guest'],
'user/change-password' => ['admin-master', 'merchant-worker'],
'user/forgot-password' => ['guest'],
//CUSTOMER ACCOUNT GUARDS
'customer' => ['customer'],
]
],
'identity_provider' => \RoleBasedUser\Service\AuthenticationService::class,
'role_provider' => [
'ZfcRbac\Role\ObjectRepositoryRoleProvider' => [
'object_manager' => 'doctrine.entitymanager.orm_default',
'class_name' => 'RoleBasedUser\Entity\HierarchicalRole',
'role_name_property' => 'name'
]
],
'redirect_strategy' => [
'redirect_when_connected' => true,
'redirect_to_route_connected' => 'home',
'redirect_to_route_disconnected' => 'user/login',
'append_previous_uri' => true,
'previous_uri_query_key' => 'redirectTo'
],
]
Module.php
-------
public function onBootstrap(EventInterface $e) {
$t = $e->getTarget();
$t->getEventManager()->attach(
$t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
);
}
Inside my controller, I have the following
AlbumController.php
-----------------
public function indexAction() {
if (!$this->authorizationService->isGranted('delete')) {
throw new UnauthorizedException();
}
return new ViewModel(array(
'myfetch' => $this->getAlbumTable()->fetchAll(),
)
);
}
The error message I have is:
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for RoleBasedUser\Service\AuthenticationService' in C:\Users\Sama\Documents\NetBeansProjects\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:550