From f809a0652d1cd9e2204a32bfd9561c95b8b1574a Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 16 Jun 2006 20:06:11 +0000 Subject: [PATCH] Refactoring SecurityComponent callbacks git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3121 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/security.php | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index 60b603526..894487e30 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -135,7 +135,7 @@ class SecurityComponent extends Object { if (low($this->loginOptions['type']) == 'digest') { // Do digest authentication } else { - if (!(in_array($login[0], array_keys($this->loginUsers)) && $this->loginUsers[$login[0]] == $login[1])) { + if (!(in_array($login['username'], array_keys($this->loginUsers)) && $this->loginUsers[$login['username']] == $login['password'])) { $this->blackHole($controller, 'login'); } } @@ -172,8 +172,8 @@ class SecurityComponent extends Object { header('HTTP/1.0 404 Not Found'); } exit(); - } elseif (method_exists($controller, $this->blackHoleCallback)) { - return $controller->{$this->blackHoleCallback}($error); + } else { + return $this->__callback($controller, $this->blackHoleCallback, array($error)); } } /** @@ -225,8 +225,8 @@ class SecurityComponent extends Object { function loginCredentials($type = '') { if ($type == '' || low($type) == 'basic') { - $login = array(env('PHP_AUTH_USER'), env('PHP_AUTH_PW')); - if ($login[0] != null) { + $login = array('username' => env('PHP_AUTH_USER'), 'password' => env('PHP_AUTH_PW')); + if ($login['username'] != null) { return $login; } } @@ -317,6 +317,18 @@ class SecurityComponent extends Object { return null; } } +/** + * Private method + * + */ + function __callback(&$controller, $method, $params = array()) { + if (is_callable(array($controller, $method))) { + return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params); + } else { + // Debug::warning('Callback method ' . $method . ' in controller ' . get_class($controller) + return null; + } + } } ?> \ No newline at end of file