Permalink
Browse files

Initial rbac

  • Loading branch information...
1 parent 832a420 commit 6064cdc23bc8ebd3593319344d9a29e33e6e2088 pcarminatti committed Jan 18, 2013
Showing with 27 additions and 4 deletions.
  1. +12 −4 config/autoload/zfcrbac.global.php
  2. +15 −0 module/Application/Module.php
@@ -7,16 +7,24 @@
// array('controller' => 'Application\Controller\Index', 'actions' => 'index', 'roles' => 'guest')
//),
'ZfcRbac\Firewall\Route' => array(
- array('route' => 'profiles/add', 'roles' => 'member'),
- array('route' => 'admin/*', 'roles' => 'admin')
+ array('route' => 'zfcuser/login', 'roles' => 'anonymous'),
+ array('route' => 'zfcuser/logout', 'roles' => 'anonymous'),
+ array('route' => 'zfcuser/register', 'roles' => 'anonymous'),
+ array('route' => 'zfcuser', 'roles' => 'member'),
+ array('route' => 'home', 'roles' => 'member'),
+ array('route' => '/*', 'roles' => 'member'),
),
),
'providers' => array(
'ZfcRbac\Provider\Generic\Role\InMemory' => array(
- 'roles' => array('anonymous', 'member', 'admin')
+ 'roles' => array(
+ 'admin',
+ 'member' => array('admin'),
+ 'anonymous' => array('member'),
+ ),
),
'ZfcRbac\Provider\Generic\Permission\InMemory' => array(
- 'permissions' => array('admin' => array('admin'))
+ 'permissions' => array('admin' => array('admin'))
),
),
'identity_provider' => 'zfcuser_auth_service'
@@ -12,6 +12,21 @@ public function onBootstrap($e)
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
+
+ $eventManager->attach('dispatch.error', function($e) use ($eventManager) {
+ if ($e->isError() && $e->getError() == 'error-route-unauthorized') {
+ $roles = $e->getParam('identity')->getRoles();
+ if ($roles[0] == 'anonymous') {
+ $router = $e->getRouter();
+ $url = $router->assemble(array(), array('name' => 'zfcuser/login'));
+ $response = $e->getResponse();
+ $response->setStatusCode(302);
+ //redirect to login route...
+ $response->getHeaders()->addHeaderLine('Location', $url);
+ }
+ }
+ });
+
}
public function getConfig()

0 comments on commit 6064cdc

Please sign in to comment.