You are here

public function SimpleLdapUserController::load in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_user/SimpleLdapUserController.class.php \SimpleLdapUserController::load()

Verifies that the user exists in the LDAP directory.

Overrides DrupalDefaultEntityController::load

File

simple_ldap_user/SimpleLdapUserController.class.php, line 32
SimpleLdapUserController class.

Class

SimpleLdapUserController
Controller class for LDAP users.

Code

public function load($ids = array(), $conditions = array()) {
  $users = parent::load($ids, $conditions);

  // Validate users against LDAP directory.
  foreach ($users as $uid => $drupal_user) {

    // Do not validate user/1, anonymous users, or blocked users.
    if ($uid == 1 || $uid == 0 || $drupal_user->status == 0) {
      continue;
    }

    // Try to load the user from LDAP.
    $ldap_user = SimpleLdapUser::singleton($drupal_user->name);

    // Check to see if the user should be kept.
    $result = array_filter(module_invoke_all('simple_ldap_user_should_delete_user', $drupal_user, $ldap_user));
    foreach ($result as $res) {
      if ($res === TRUE) {
        $this
          ->delete_single($drupal_user);
        $users[$uid] = NULL;
        continue;
      }
    }
    if (!$ldap_user->exists) {

      // Block the user if it does not exist in LDAP.
      $this
        ->blockUser($drupal_user);
    }

    // Active Directory uses a bitmask to specify certain flags on an account,
    // including whether it is enabled. http://support.microsoft.com/kb/305144
    if ($ldap_user->server->type == 'Active Directory') {
      if (isset($ldap_user->useraccountcontrol[0]) && (int) $ldap_user->useraccountcontrol[0] & 2) {
        $this
          ->blockUser($drupal_user);
      }
    }
  }
  return $users;
}