示例#1
0
 /**
  * Load the Person attributes from LDAP with the given username
  */
 public static function loadSettings(&$settingsController, &$params, &$response, $user)
 {
     if (empty(GO::config()->ldap_peopledn) || empty(GO::config()->ldap_person_fields)) {
         return true;
     }
     try {
         $person = \GO\Ldapauth\Model\Person::findByUsername($user->username);
         if ($person) {
             $response['data'] = array_merge($response['data'], $person->getAttributes());
             $response['data']['ldap_fields'] = $person->getExtraVars();
         }
     } catch (Exception $e) {
         //LDAP record not available
     }
 }
示例#2
0
 public function authenticate($username, $password)
 {
     if (empty(\GO::config()->ldap_peopledn)) {
         \GO::debug('LDAPAUTH: Aborting because the following required value is not set: $config["ldap_peopledn"]');
         return true;
     }
     $record = \GO\Ldapauth\Model\Person::findByUsername($username);
     if (!$record) {
         \GO::debug("LDAPAUTH: No LDAP entry found for " . $username);
         //return true here because this should not block normal authentication
         return true;
     }
     //$authenticated = $ldapConn->bind($record->getDn(), $password);
     if (!$record->authenticate($password)) {
         $str = "LOGIN FAILED for user: \"" . $username . "\" from IP: ";
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $str .= $_SERVER['REMOTE_ADDR'];
         } else {
             $str .= 'unknown';
         }
         \GO::infolog($str);
         return false;
     }
     \GO::debug("LDAPAUTH: LDAP authentication SUCCESS for " . $username);
     if (!empty(GO::config()->ldap_create_mailbox_domains)) {
         if (!GO::modules()->serverclient) {
             throw new Exception("The serverclient module must be installed and configured when using \$config['GO::config()->ldap_create_mailbox_domains']. See https://www.group-office.com/wiki/Mailserver#Optionally_install_the_serverclient");
         }
         $_POST['serverclient_domains'] = GO::config()->ldap_create_mailbox_domains;
     } else {
         GO::debug("LDAPAUTH: Found LDAP entry found for " . $username);
         //			GO::debug($record->getAttributes());
     }
     $user = $this->syncUserWithLdapRecord($record, $password);
     if (!$user) {
         return false;
     }
     try {
         $this->_checkEmailAccounts($user, $password);
     } catch (Exception $e) {
         //				GO::debug("LDAPAUTH: Failed to create or update e-mail account!\n\n".(string) $e);
         trigger_error("LDAPAUTH: Failed to create or update e-mail account for user " . $user->username . "\n\n" . $e->getMessage());
     }
 }