Skip to content

Commit 1f03315

Browse files
committed
Merge branch 'wip_MDL-16168_HEAD_CAS_crash_if_no_LDAP' of https://github.com/iarenaza/moodle
2 parents 7795ad4 + ab8b1d1 commit 1f03315

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

auth/cas/auth.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function process_config($config) {
360360
* @return boolean result
361361
*/
362362
function iscreator($username) {
363-
if ((empty($this->config->attrcreators) && empty($this->config->groupecreators)) or empty($this->config->memberattribute)) {
363+
if (empty($this->config->host_url) or (empty($this->config->attrcreators) && empty($this->config->groupecreators)) or empty($this->config->memberattribute)) {
364364
return false;
365365
}
366366

@@ -405,4 +405,39 @@ function iscreator($username) {
405405

406406
return false;
407407
}
408+
409+
/**
410+
* Reads user information from LDAP and returns it as array()
411+
*
412+
* If no LDAP servers are configured, user information has to be
413+
* provided via other methods (CSV file, manually, etc.). Return
414+
* an empty array so existing user info is not lost. Otherwise,
415+
* calls parent class method to get user info.
416+
*
417+
* @param string $username username
418+
* @return mixed array with no magic quotes or false on error
419+
*/
420+
function get_userinfo($username) {
421+
if (empty($this->config->host_url)) {
422+
return array();
423+
}
424+
return parent::get_userinfo($username);
425+
}
426+
427+
/**
428+
* Syncronizes users from LDAP server to moodle user table.
429+
*
430+
* If no LDAP servers are configured, simply return. Otherwise,
431+
* call parent class method to do the work.
432+
*
433+
* @param bool $do_updates will do pull in data updates from LDAP if relevant
434+
* @return nothing
435+
*/
436+
function sync_users($do_updates=true) {
437+
if (empty($this->config->host_url)) {
438+
error_log('[AUTH CAS] '.get_string('noldapserver', 'auth_cas'));
439+
return;
440+
}
441+
parent::sync_users($do_updates);
442+
}
408443
}

auth/cas/lang/en/auth_cas.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@
6161
$string['auth_cas_use_cas'] = 'Use CAS';
6262
$string['auth_cas_version'] = 'Version of CAS';
6363
$string['CASform'] = 'Authentication choice';
64+
$string['noldapserver'] = 'No LDAP server configured for CAS! Syncing disabled.';
6465
$string['pluginname'] = 'CAS server (SSO)';

0 commit comments

Comments
 (0)