From 60bb7fa545bea583669d5a41b60f75847488c46c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 26 Feb 2007 03:55:57 +0000 Subject: [PATCH] r1420: More work on the authentication system: - Added the authmethod setting to allow the admin to choose what authentication system to use - In init.php, we now use the authentication API to validate the cookies - Added Authentication::fetchBugdarUser() and fixed a small parse error --- admin/setting.php | 12 +++++ includes/auth/auth.php | 12 ++++- includes/auth/auth_default.php | 94 ++++++++++++++++++++++++++++++++++ includes/init.php | 31 ++++------- 4 files changed, 128 insertions(+), 21 deletions(-) create mode 100644 includes/auth/auth_default.php diff --git a/admin/setting.php b/admin/setting.php index 4ed533d..92cd6c0 100755 --- a/admin/setting.php +++ b/admin/setting.php @@ -82,6 +82,18 @@ if ($_REQUEST['do'] == 'modify') $admin->table_start(); $admin->table_head(_('General Options')); + // authmethod + $admin->row_span(_('Authentication Method'), 'thead'); + $methods = $funct->scandir('./includes/auth/'); + foreach ($methods[''] AS $path) + { + if (preg_match('#auth_(.*)\.php#', $path, $matches)) + { + $admin->list_item(ucwords(str_replace('_', ' ', $matches[1])), $matches[1], ($matches[1] == $bugsys->options['authmethod'])); + } + } + $admin->row_list(_('The authentication class to use to validate cookie data and longins. You may need to edit the actual file for certain authentication systems.'), 'setting[authmethod]'); + // allownewreg $admin->row_span(_('Allow New Registrations'), 'thead'); $admin->row_yesno(_('If this is set to yes, then new users will be allowed to register.'), 'setting[allownewreg]', $bugsys->options['allownewreg']); diff --git a/includes/auth/auth.php b/includes/auth/auth.php index 42691a6..ec2499f 100644 --- a/includes/auth/auth.php +++ b/includes/auth/auth.php @@ -79,6 +79,16 @@ class Authentication $this->_setupDatabase(); } + // ################################################################### + /** + * Returns the information array for the Bugdar user. This must be + * called after an authentication method. + */ + function fetchBugdarUser() + { + return $this->bugdarUser; + } + // ################################################################### /** * Sets up the database to authenticate against. You can create a new @@ -193,7 +203,7 @@ class Authentication } else { - $this->authUser = null + $this->authUser = null; return false; } } diff --git a/includes/auth/auth_default.php b/includes/auth/auth_default.php new file mode 100644 index 0000000..bf83ea4 --- /dev/null +++ b/includes/auth/auth_default.php @@ -0,0 +1,94 @@ +authDb =& $this->db; + } + + // ################################################################### + function _fetchCookieUniqueId() + { + return $this->registry->input_clean(COOKIE_PREFIX . 'userid', TYPE_UINT); + } + + // ################################################################### + function _fetchCookiePassword() + { + return $this->registry->in[COOKIE_PREFIX . 'authkey']; + } + + // ################################################################### + function _fetchUserUsingCookies() + { + return $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $this->_fetchCookieUniqueId()); + } + + // ################################################################### + function _verifyCookieData() + { + return ($this->authUser['authkey'] == $this->_fetchCookiePassword()); + } + + // ################################################################### + function _setCookies() + { + $this->registry->funct->cookie(COOKIE_PREFIX . 'userid', $this->authUser['userid']); + $this->registry->funct->cookie(COOKIE_PREFIX . 'authkey', $this->authUser['authkey']); + } + + // ################################################################### + function _clearCookies() + { + $this->registry->funct->cookie(COOKIE_PREFIX . 'userid'); + $this->registry->funct->cookie(COOKIE_PREFIX . 'authkey'); + } + + // ################################################################### + function _fetchBugdarUserFromAuthUser() + { + return $this->authUser; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/init.php b/includes/init.php index 45418b8..abb1cac 100755 --- a/includes/init.php +++ b/includes/init.php @@ -101,30 +101,21 @@ $bugsys->setAppVersion($bugsys->options['trackerversion']); // ################################################################### // load userinfo -$userid = $bugsys->input_clean(COOKIE_PREFIX . 'userid', TYPE_UINT); -if ($userid) +require_once('./includes/auth/auth_' . $bugsys->options['authmethod'] . '.php'); + +$authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $bugsys->options['authmethod']))); +$bugsys->auth = $auth = new $authClass(); + +if ($auth->authenticateCookies()) { - $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid"); - if (is_array($userinfo) AND $bugsys->in[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey']) - { - $userinfo['permissions'] = (int)$bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['permissions']; - $userinfo['displaytitle'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle']; - $bugsys->userinfo = $userinfo; - $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']); - $funct->cookie(COOKIE_PREFIX . 'userid', $bugsys->userinfo['userid']); - $funct->cookie(COOKIE_PREFIX . 'authkey', $bugsys->userinfo['authkey']); - } - else - { - $userinfo = null; - } + $bugsys->userinfo = $auth->fetchBugdarUser(); + $bugsys->userinfo['permissions'] = (int)$bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['permissions']; + $bugsys->userinfo['displaytitle'] = $bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle']; + $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']); } - -if (!$userinfo) +else { - $funct->cookie(COOKIE_PREFIX . 'userid'); - $funct->cookie(COOKIE_PREFIX . 'authkey'); $bugsys->userinfo = fetch_guest_user(); } -- 2.43.5