|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // Designed to be redirected from moodle/login/index.php 00004 00005 require('../../config.php'); 00006 00007 $PAGE->set_url('/auth/shibboleth/index.php'); 00008 00009 if (isloggedin() && !isguestuser()) { // Nothing to do 00010 if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) { 00011 $urltogo = $SESSION->wantsurl; 00012 unset($SESSION->wantsurl); 00013 00014 } else { 00015 $urltogo = $CFG->wwwroot.'/'; 00016 unset($SESSION->wantsurl); 00017 } 00018 00019 redirect($urltogo); 00020 00021 } 00022 00023 $pluginconfig = get_config('auth/shibboleth'); 00024 $shibbolethauth = get_auth_plugin('shibboleth'); 00025 00026 // Check whether Shibboleth is configured properly 00027 if (empty($pluginconfig->user_attribute)) { 00028 print_error('shib_not_set_up_error', 'auth'); 00029 } 00030 00032 if (!empty($_SERVER[$pluginconfig->user_attribute])) { // Shibboleth auto-login 00033 $frm->username = strtolower($_SERVER[$pluginconfig->user_attribute]); 00034 $frm->password = substr(base64_encode($_SERVER[$pluginconfig->user_attribute]),0,8); 00035 // The random password consists of the first 8 letters of the base 64 encoded user ID 00036 // This password is never used unless the user account is converted to manual 00037 00039 00040 if ($shibbolethauth->user_login($frm->username, $frm->password)) { 00041 00042 $user = authenticate_user_login($frm->username, $frm->password); 00043 enrol_check_plugins($user); 00044 session_set_user($user); 00045 00046 $USER->loggedin = true; 00047 $USER->site = $CFG->wwwroot; // for added security, store the site in the 00048 00049 update_user_login_times(); 00050 00051 // Don't show previous shibboleth username on login page 00052 00053 set_login_session_preferences(); 00054 00055 unset($SESSION->lang); 00056 $SESSION->justloggedin = true; 00057 00058 add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $USER->id, 0, $USER->id); 00059 00060 if (user_not_fully_set_up($USER)) { 00061 $urltogo = $CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&course='.SITEID; 00062 // We don't delete $SESSION->wantsurl yet, so we get there later 00063 00064 } else if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) { 00065 $urltogo = $SESSION->wantsurl; 00066 unset($SESSION->wantsurl); 00067 00068 } else { 00069 $urltogo = $CFG->wwwroot.'/'; 00070 unset($SESSION->wantsurl); 00071 } 00072 00074 if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) { 00075 if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') { 00076 $urltogo = $CFG->wwwroot.'/my/'; 00077 } 00078 } 00079 00080 redirect($urltogo); 00081 00082 exit; 00083 } 00084 00085 else { 00086 // For some weird reason the Shibboleth user couldn't be authenticated 00087 } 00088 } 00089 00090 // If we can find any (user independent) Shibboleth attributes but no user 00091 // attributes we probably didn't receive any user attributes 00092 elseif (!empty($_SERVER['HTTP_SHIB_APPLICATION_ID']) || !empty($_SERVER['Shib-Application-ID'])) { 00093 print_error('shib_no_attributes_error', 'auth' , '', '\''.$pluginconfig->user_attribute.'\', \''.$pluginconfig->field_map_firstname.'\', \''.$pluginconfig->field_map_lastname.'\' and \''.$pluginconfig->field_map_email.'\''); 00094 } else { 00095 print_error('shib_not_set_up_error', 'auth'); 00096 } 00097 00098