Check interface support on auth backend before attempting calls

This commit is contained in:
2012-01-04 19:19:24 +00:00
parent bfa23a9973
commit e3a9c8e976

View File

@@ -80,16 +80,28 @@ class SihnonFramework_Auth {
*/
public function addUser($username, $password) {
if ( ! is_subclass_of($this->backend, 'SihnonFramework_Auth_IUpdateable')) {
throw new SihnonFramework_Exception_NotImplemented();
}
return $this->backend->addUser($username, $password);
}
public function removeUser() {
if ( ! is_subclass_of($this->backend, 'SihnonFramework_Auth_IUpdateable')) {
throw new SihnonFramework_Exception_NotImplemented();
}
$this->backend->removeUser($this->user);
$this->user = null;
$this->authenticated = false;
}
public function changePassword($new_password) {
if ( ! is_subclass_of($this->backend, 'SihnonFramework_Auth_IUpdateable')) {
throw new SihnonFramework_Exception_NotImplemented();
}
$this->backend->changePassword($this->user, $new_password);
}
@@ -102,6 +114,10 @@ class SihnonFramework_Auth {
return false;
}
if ( ! is_subclass_of($this->backend, 'SihnonFramework_Auth_IPermissionable')) {
throw new SihnonFramework_Exception_NotImplemented();
}
return $this->backend->isAdministrator($this->user);
}
@@ -114,6 +130,10 @@ class SihnonFramework_Auth {
return false;
}
if ( ! is_subclass_of($this->backend, 'SihnonFramework_Auth_IFinelyPermissionable')) {
throw new SihnonFramework_Exception_NotImplemented();
}
return $this->backend->hasPermission($this->user, $permission);
}