MDL-16168 auth/cas CAS crashes if no LDAP is set up
authorIñaki Arenaza <iarenaza@mondragon.edu>
Wed, 8 Jun 2011 15:48:57 +0000 (17:48 +0200)
committerIñaki Arenaza <iarenaza@mondragon.edu>
Sun, 28 Aug 2011 13:31:14 +0000 (15:31 +0200)
Fix was pending for master. Credit goes to Ivan Dackiewicz.

auth/cas/auth.php
auth/cas/lang/en/auth_cas.php

index 5690c53..d66bdb8 100644 (file)
@@ -360,7 +360,7 @@ class auth_plugin_cas extends auth_plugin_ldap {
      * @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 @@ class auth_plugin_cas extends auth_plugin_ldap {
 
         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);
+    }
 }
index 319a505..3f5fe1e 100644 (file)
@@ -61,4 +61,5 @@ $string['auth_cas_text'] = 'Secure connection';
 $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)';