A Zend Framework 2 module to easily integrate ZfcUser and ZfcRbac
Are your tired of doing tedious work of integrating ZfcUser and ZfcRbac again and again? Then, you are in the right place. This module comes to save us. This module, simply, gets roles of a user from the database and passes it to the ZfcRbac. You only need to focus on the domain logic of your application. No more repetive tasks.
SmartRedirectStrategy
"ujjwal/user-rbac": "0.1.*",
to your composer.json and run php composer.phar update
data/mysql.sql
config/application.config.php
vendor/ujjwal/user-rbac/config/user-rbac.global.php
to ./config/autoload/user-rbac.global.php
and change the values as you wishThis module registers an identity provider and provides some configuration to ZfcRbac. So, you don't need to create your own identity provider. See config/module.config.php
.
It gets a user's roles from the table user_role_linker
and passes the roles to ZfcRbac
. This module is best suited when you use ZfcRbac\Role\InMemoryRoleProvider
as role provider.
Check the options available in vendor/ujjwal/user-rbac/config/user-rbac.global.php
.
This module comes with a new strategy called SmartRedirectStrategy
. This simply redirects to ZfcUser
's login page or route, zfcuser/login
only when the user is unauthenticated. Otherwise, it shows a 403 error page!
public function onBootstrap(EventInterface $e)
{
$t = $e->getTarget();
$t->getEventManager()->attach(
$t->getServiceManager()->get('UserRbac\View\Strategy\SmartRedirectStrategy')
);
}
This module is only ideal for small and meduim web sites as a quick and easy way. For complicated use cases, it may not suit your need.