well, let's keep focus here. Authorization is highly dependent on the requirements of the application. Some applications may work well with authorization happening at the controller-level ( ~ isSecure()), while others may need it to happen at a lower (model-layer) or higher (frontcontroller) level. What they all have in common however, is that they rely on a authentication happening beforehand. This is fairly generic, and I suppose it could happen as an intercepting filter in the frontcontroller.
I suspect that putting together a general method of authorization is just not possible, or if it is, it will be very complex and thus overkill for most applications. I'd like to be proven wrong though.
In that case the View would probably need to call a method in the Controller or Model such as hasAccess(array('admin','artist'))
A way to handle authorization at the controller-level, could be through the applicationcontroller. By providing a Rule which validates against what-ever restrictions you may have (such as user belonging to a certain group), it could be solved with the code we already have. Eg :
PHP Code:
class SecureAction
{
function SecureAction(&$action, &$deniedAction) {
$this->controller =& new FlowController($action, $deniedAction);
$this->controller->addRule(new Rule_UserGroup(Array('admin', 'artist')));
}
function execute(&$context) {
$this->controller->execute($context);
}
}
class MySecureAction extends SecureAction
{
function MyAction () {
parent::SecureAction(new MyAction(), new 403Action());
}
}
(Could probably be simplified a bit, but you get the point, I suppose)
Bookmarks