My SecurityMiddleware :
class SecurityMiddleware {
public function __construct($app) {
$acl = $this->getAcl();
//get the handler
$arrHandler = $app->getActiveHandler();
//get the controller for this handler (strip off the Controller namespace if required)
$controller = str_replace('Controllers\\','',get_class($arrHandler[0]));
//is an Admin user allowed to view the current controller/method?
$allowed = $acl->isAllowed('Admin', $controller, $arrHandler[1]);
return $allowed;
}
private function getAcl() {
$acl = new AclList();
$acl->setDefaultAction(Acl::DENY);
$roles = [
'worker' => new Role('Worker'),
'admin' => new Role('Admin'),
'victim' => new Role('Victim')
];
foreach($roles as $role) $acl->addRole($role);
$acl->addInherit('Admin', 'Worker');
$adminResource = ['Admin' => ['Accounts', 'Workers', 'Payments', 'Notifications', 'MakePayment']];
foreach($adminResource as $controller => $methods)
$acl->addResource(new Resource($controller), $methods);
// Allows
foreach($acl->getRoles() as $role) {
if($role->getName() == 'Admin')
foreach($adminResource as $resource => $method)
$acl->allow($role->getName(), $resource, $method);
}
return $acl;
}
}
and in index.php
$app->before(new SecurityMiddleware($app));
On the output I get only a blank page