Beispiel #1
0
 /**
  * This is a option-less authentication. Either your login works or it doesn't.
  * Other apps implementing this interface may need to know what you're trying to do 
  * in order to make a decision; $pa_options is an associative array of User handler-specific
  * keys and values that can contain such information
  */
 public function authenticate(&$ps_username, $ps_password = "", $pa_options = null)
 {
     // if user doesn't exist, try creating it through the authentication backend, if the backend supports it
     if (strlen($ps_username) > 0 && !$this->load($ps_username)) {
         if (AuthenticationManager::supports(__CA_AUTH_ADAPTER_FEATURE_AUTOCREATE_USERS__)) {
             try {
                 $va_values = AuthenticationManager::getUserInfo($ps_username, $ps_password);
             } catch (Exception $e) {
                 $this->opo_log->log(array('CODE' => 'SYS', 'SOURCE' => 'ca_users/authenticate', 'MESSAGE' => _t('There was an error while trying to fetch information for a new user from the current authentication backend. The message was %1 : %2', get_class($e), $e->getMessage())));
                 return false;
             }
             if (!is_array($va_values) || sizeof($va_values) < 1) {
                 return false;
             }
             // @todo: check sanity on values from plugins before inserting them?
             foreach ($va_values as $vs_k => $vs_v) {
                 if (in_array($vs_k, array('roles', 'groups'))) {
                     continue;
                 }
                 $this->set($vs_k, $vs_v);
             }
             $vn_mode = $this->getMode();
             $this->setMode(ACCESS_WRITE);
             $this->insert();
             if (!$this->getPrimaryKey()) {
                 $this->setMode($vn_mode);
                 $this->opo_log->log(array('CODE' => 'SYS', 'SOURCE' => 'ca_users/authenticate', 'MESSAGE' => _t('User could not be created after getting info from authentication adapter. API message was: %1', join(" ", $this->getErrors()))));
                 return false;
             }
             if (is_array($va_values['groups']) && sizeof($va_values['groups']) > 0) {
                 $this->addToGroups($va_values['groups']);
             }
             if (is_array($va_values['roles']) && sizeof($va_values['roles']) > 0) {
                 $this->addRoles($va_values['roles']);
             }
             if (is_array($va_values['preferences']) && sizeof($va_values['preferences']) > 0) {
                 foreach ($va_values['preferences'] as $vs_pref => $vs_pref_val) {
                     $this->setPreference($vs_pref, $vs_pref_val);
                 }
             }
             $this->update();
             // restore mode
             $this->setMode($vn_mode);
         }
     }
     if (AuthenticationManager::authenticate($ps_username, $ps_password, $pa_options)) {
         $this->load($ps_username);
         return true;
     }
     // check ips
     if (!isset($pa_options["dont_check_ips"]) || !$pa_options["dont_check_ips"]) {
         if ($vn_user_id = $this->ipAuthenticate()) {
             if ($this->load($vn_user_id)) {
                 $ps_username = $this->get("user_name");
                 return 2;
             }
         }
     }
     return false;
 }