Permalink
Browse files

MDL-16168 auth/cas CAS crashes if no LDAP is set up

Fix was pending for master. Credit goes to Ivan Dackiewicz.
  • Loading branch information...
1 parent 4ad6128 commit ab8b1d15a514d1a47c579406491962e53bc15789 @iarenaza iarenaza committed Jun 8, 2011
Showing with 37 additions and 1 deletion.
  1. +36 −1 auth/cas/auth.php
  2. +1 −0 auth/cas/lang/en/auth_cas.php
View
37 auth/cas/auth.php
@@ -360,7 +360,7 @@ function process_config($config) {
* @return boolean result
*/
function iscreator($username) {
- if ((empty($this->config->attrcreators) && empty($this->config->groupecreators)) or empty($this->config->memberattribute)) {
+ if (empty($this->config->host_url) or (empty($this->config->attrcreators) && empty($this->config->groupecreators)) or empty($this->config->memberattribute)) {
return false;
}
@@ -405,4 +405,39 @@ function iscreator($username) {
return false;
}
+
+ /**
+ * Reads user information from LDAP and returns it as array()
+ *
+ * If no LDAP servers are configured, user information has to be
+ * provided via other methods (CSV file, manually, etc.). Return
+ * an empty array so existing user info is not lost. Otherwise,
+ * calls parent class method to get user info.
+ *
+ * @param string $username username
+ * @return mixed array with no magic quotes or false on error
+ */
+ function get_userinfo($username) {
+ if (empty($this->config->host_url)) {
+ return array();
+ }
+ return parent::get_userinfo($username);
+ }
+
+ /**
+ * Syncronizes users from LDAP server to moodle user table.
+ *
+ * If no LDAP servers are configured, simply return. Otherwise,
+ * call parent class method to do the work.
+ *
+ * @param bool $do_updates will do pull in data updates from LDAP if relevant
+ * @return nothing
+ */
+ function sync_users($do_updates=true) {
+ if (empty($this->config->host_url)) {
+ error_log('[AUTH CAS] '.get_string('noldapserver', 'auth_cas'));
+ return;
+ }
+ parent::sync_users($do_updates);
+ }
}
View
1 auth/cas/lang/en/auth_cas.php
@@ -61,4 +61,5 @@
$string['auth_cas_use_cas'] = 'Use CAS';
$string['auth_cas_version'] = 'Version of CAS';
$string['CASform'] = 'Authentication choice';
+$string['noldapserver'] = 'No LDAP server configured for CAS! Syncing disabled.';
$string['pluginname'] = 'CAS server (SSO)';

0 comments on commit ab8b1d1

Please sign in to comment.