You are here

public function LdapGroupManager::groupIsMember in Lightweight Directory Access Protocol (LDAP) 8.4

Is a user a member of group?

Parameters

string $group_dn: Group DN in mixed case.

string $username: A Drupal username.

Return value

bool Whether the user belongs to the group.

File

ldap_servers/src/LdapGroupManager.php, line 346

Class

LdapGroupManager
LDAP Group Manager.

Namespace

Drupal\ldap_servers

Code

public function groupIsMember(string $group_dn, string $username) : bool {
  if ($this
    ->checkAvailability()) {
    $group_dns = $this
      ->groupMembershipsFromUser($username);
    if (!empty($group_dns)) {

      // While list of group dns is going to be in correct mixed case,
      // $group_dn may not since it may be derived from user entered values so
      // make sure in_array() is case insensitive.
      $lower_cased_group_dns = array_keys(array_change_key_case(array_flip($group_dns), CASE_LOWER));
      if (in_array(mb_strtolower($group_dn), $lower_cased_group_dns, TRUE)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}