diff --git a/auth/cas/auth.php b/auth/cas/auth.php index 5eb84340d748c..42fc486ef5ccf 100644 --- a/auth/cas/auth.php +++ b/auth/cas/auth.php @@ -130,21 +130,10 @@ function loginpage_hook() { } $authCAS = optional_param('authCAS', '', PARAM_RAW); - if ($authCAS == 'NOCAS') { + if ($authCAS != 'CAS') { return; } - // Show authentication form for multi-authentication. - // Test pgtIou parameter for proxy mode (https connection in background from CAS server to the php server). - if ($authCAS != 'CAS' && !isset($_GET['pgtIou'])) { - $PAGE->set_url('/login/index.php'); - $PAGE->navbar->add($CASform); - $PAGE->set_title("$site->fullname: $CASform"); - $PAGE->set_heading($site->fullname); - echo $OUTPUT->header(); - include($CFG->dirroot.'/auth/cas/cas_form.html'); - echo $OUTPUT->footer(); - exit(); - } + } // Connection to CAS server @@ -363,4 +352,25 @@ public function postlogout_hook($user) { phpCAS::logoutWithRedirectService($backurl); } } + + /** + * Return a list of identity providers to display on the login page. + * + * @param string|moodle_url $wantsurl The requested URL. + * @return array List of arrays with keys url, iconurl and name. + */ + public function loginpage_idp_list($wantsurl) { + global $CFG; + $config = get_config('auth_cas'); + $params = ["authCAS" => "CAS"]; + $url = new moodle_url(get_login_url(), $params); + $iconurl = moodle_url::make_pluginfile_url(context_system::instance()->id, + 'auth_cas', + 'logo', + null, + '/', + $config->auth_logo); + $result[] = ['url' => $url, 'iconurl' => $iconurl, 'name' => $config->auth_name]; + return $result; + } } diff --git a/auth/cas/lang/en/auth_cas.php b/auth/cas/lang/en/auth_cas.php index a7c36624df42d..5d84f23ca3f67 100644 --- a/auth/cas/lang/en/auth_cas.php +++ b/auth/cas/lang/en/auth_cas.php @@ -24,6 +24,10 @@ $string['accesCAS'] = 'CAS users'; $string['accesNOCAS'] = 'other users'; +$string['auth_cas_auth_name'] = 'Authentication method name'; +$string['auth_cas_auth_name_description'] = 'Provide a name for the CAS authentication method that is familiar to your users.'; +$string['auth_cas_auth_logo'] = 'Authentication method logo'; +$string['auth_cas_auth_logo_description'] = 'Provide a logo for the CAS authentication method that is familiar to your users.'; $string['auth_cas_auth_user_create'] = 'Create users externally'; $string['auth_cas_baseuri'] = 'URI of the server (nothing if no baseUri)
For example, if the CAS server responds to host.domaine.fr/CAS/ then
cas_baseuri = CAS/'; $string['auth_cas_baseuri_key'] = 'Base URI'; diff --git a/auth/cas/lib.php b/auth/cas/lib.php new file mode 100644 index 0000000000000..124a354c97053 --- /dev/null +++ b/auth/cas/lib.php @@ -0,0 +1,75 @@ +. + +/** + * Authentication Plugin: CAS Authentication + * + * Authentication using CAS (Central Authentication Server). + * + * @package auth_cas + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + + +defined('MOODLE_INTERNAL') || die; + +/** + * Serves the logo file settings. + * + + * @param stdClass $course course object + * @param stdClass $cm course module object + * @param stdClass $context context object + * @param string $filearea file area + * @param array $args extra arguments + * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving + * @return bool false if file not found, does not return if found - justsend the file + */ +function auth_cas_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { + if ($context->contextlevel != CONTEXT_SYSTEM) { + return false; + } + + if ($filearea !== 'logo' ) { + return false; + } + + $itemid = 0; + // Use the itemid to retrieve any relevant data records and perform any security checks to see if the + // user really does have access to the file in question. + + // Extract the filename / filepath from the $args array. + $filename = array_pop($args); // The last item in the $args array. + if (!$args) { + $filepath = '/'; // $args is empty => the path is '/' + } else { + $filepath = '/'.implode('/', $args).'/'; // $args contains elements of the filepath + } + + // Retrieve the file from the Files API. + $fs = get_file_storage(); + $file = $fs->get_file($context->id, 'auth_cas', $filearea, $itemid, $filepath, $filename); + if (!$file) { + return false; // The file does not exist. + } + + // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering. + // From Moodle 2.3, use send_stored_file instead. + send_stored_file($file, null, 0, $forcedownload, $options); +} diff --git a/auth/cas/settings.php b/auth/cas/settings.php index 2bd743417b0b2..991f9d38a4941 100644 --- a/auth/cas/settings.php +++ b/auth/cas/settings.php @@ -45,6 +45,18 @@ $settings->add(new admin_setting_heading('auth_cas/casserversettings', new lang_string('auth_cas_server_settings', 'auth_cas'), '')); + // Authentication method name. + $settings->add(new admin_setting_configtext('auth_cas/auth_name', + get_string('auth_cas_auth_name', 'auth_cas'), + get_string('auth_cas_auth_name_description', 'auth_cas'), '', PARAM_RAW_TRIMMED)); + + // Authentication method logo. + $opts = array('accepted_types' => array('.png', '.jpg', '.gif', '.webp', '.tiff', '.svg')); + $settings->add(new admin_setting_configstoredfile('auth_cas/auth_logo', + get_string('auth_cas_auth_logo', 'auth_cas'), + get_string('auth_cas_auth_logo_description', 'auth_cas'), 'logo', 0, $opts)); + + // Hostname. $settings->add(new admin_setting_configtext('auth_cas/hostname', get_string('auth_cas_hostname_key', 'auth_cas'),