linusnorton/xFrame — pull request #4 by h1ppo (2012-04-02 21:57:54+00:00)
Title: ACL and plugin mechanism

I've refactored the entity manager to work as a plugin as well so there is a working example of plugins out of the box. Here's the details on using the ACL (it's quite long... will add to docs if you're happy with it). If the markdown doesn't work - blame github :P

Add the prefilter for the ACL to an action and set the resource for it
src/demo/controller/Index.php
```/**
* @Request("index")
* @Prefilter("\demo\request\prefilter\Authoriser")
* @CustomParam(name="resource", value="Public")
*/
public function run() { ...
```
Register your plugin which gives access to your logged in user
config/dev.ini
```PLUGIN[user]=\demo\plugin\DemoUser```

Create the plugin which returns the necessary details on the current user
src/demo/plugin/DemoUser.php
``` 1,
"role" => "UberAdmin",
);
}

}```

Add the prefilter to do the ACL logic and process the request
src/demo/request/prefilter/Authoriser.php
````
initAcl();

$resource = $request->resource;
$role = $this->dic->plugin->user['role'];

if ($this->acl->isAllowed($role, $resource)) {
return true;
} else {
// do some redirection here
return false;
}
}

private function initAcl() {
$this->acl = new Acl();
$this->acl->addResource('Public')
->addRole('Public')
->addRole('UberAdmin')
->denyAll()
->allow('UberAdmin', 'Public');
}

}
````