From e3a9c8e9767382f62430515b9b84e295da7b929c Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 4 Jan 2012 19:19:24 +0000 Subject: [PATCH] Check interface support on auth backend before attempting calls --- source/lib/SihnonFramework/Auth.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/lib/SihnonFramework/Auth.class.php b/source/lib/SihnonFramework/Auth.class.php index 383168b..8af12bc 100644 --- a/source/lib/SihnonFramework/Auth.class.php +++ b/source/lib/SihnonFramework/Auth.class.php @@ -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); }