// *********************************************************************** // restart the session for Mahara @session_start(); if (!$SESSION->get('wantsurl')) { $SESSION->set('wantsurl', preg_replace('/\\&login$/', '', $wantsurl)); } // now start the hunt for the associated authinstance for the organisation attached to the saml_attributes global $instance; $instance = auth_saml_find_authinstance($saml_attributes); // if we don't have an auth instance then this is a serious failure if (!$instance) { throw new UserNotFoundException(get_string('errorbadinstitution', 'auth.saml')); } // stash the existing logged in user - if we have one $current_user = $USER; $is_loggedin = $USER->is_logged_in(); // check the instance and do a test login $can_login = false; try { $auth = new AuthSaml($instance->id); $can_login = $auth->request_user_authorise($saml_attributes); } catch (AccessDeniedException $e) { throw new UserNotFoundException(get_string('errnosamluser', 'auth.saml')); } catch (XmlrpcClientException $e) { throw new AccessDeniedException($e->getMessage()); } catch (AuthInstanceException $e) { throw new AccessDeniedException(get_string('errormissinguserattributes1', 'auth.saml', get_config('sitename'))); } // if we can login with SAML - then let them go if ($can_login) { // they are logged in, so they dont need to be here
$USER->logout(); } else { if (!defined('INSTALLER')) { redirect('/admin/upgrade.php'); } } } // The installer does its own auth_setup checking, because some upgrades may // break logging in and so need to allow no logins. // Command-line scripts obviously have no logged-in user. if (!defined('INSTALLER') && !defined('CLI') && !defined('CRON')) { auth_setup(); } $siteclosed = $siteclosedforupgrade || get_config('siteclosedbyadmin'); if ($siteclosed && !$USER->admin) { if ($USER->is_logged_in()) { $USER->logout(); } if (!defined('HOME') && !defined('INSTALLER')) { redirect(); } } // check to see if we're installed... if (!get_config('installed')) { ensure_install_sanity(); $scriptfilename = str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']); if (!defined('CLI') && false === strpos($scriptfilename, 'admin/index.php') && false === strpos($scriptfilename, 'admin/upgrade.php') && false === strpos($scriptfilename, 'admin/upgrade.json.php') && false === strpos($scriptfilename, 'admin/cli/install.php') && false === strpos($scriptfilename, 'admin/cli/upgrade.php')) { redirect('/admin/index.php'); } } if (defined('JSON') && !defined('NOSESSKEY')) {