You are here

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

Get all members of a group.

Currently not in use.

@todo Split return functionality or throw an error.

Parameters

string $group_dn: Group DN as LDAP DN.

Return value

array Array of group members (could be users or groups).

1 call to LdapGroupManager::groupAllMembers()
LdapGroupManager::groupRemoveGroup in ldap_servers/src/LdapGroupManager.php
Remove a group entry.

File

ldap_servers/src/LdapGroupManager.php, line 260

Class

LdapGroupManager
LDAP Group Manager.

Namespace

Drupal\ldap_servers

Code

public function groupAllMembers(string $group_dn) : array {
  $members = [];
  if (!$this
    ->checkAvailability() || !$this
    ->groupGroupEntryMembershipsConfigured()) {
    return $members;
  }
  $attributes = [
    $this->server
      ->get('grp_memb_attr'),
    'cn',
    'objectclass',
  ];
  $group_entry = $this
    ->checkDnExistsIncludeData($group_dn, $attributes);
  if (!$group_entry) {
    return $members;
  }

  // If attributes weren't returned, don't give false empty group.
  if (empty($group_entry
    ->getAttribute('cn', FALSE)) || empty($group_entry
    ->getAttribute($this->server
    ->get('grp_memb_attr'), FALSE))) {

    // If no attribute returned, no members.
    return $members;
  }
  $members = $group_entry
    ->getAttribute($this->server
    ->get('grp_memb_attr'), FALSE);
  $this
    ->groupMembersRecursive([
    $group_entry,
  ], $members, [], 0, self::LDAP_QUERY_RECURSION_LIMIT);

  // Remove the DN of the source group.
  $source_dn_key = array_search($group_dn, $members, TRUE);
  if ($source_dn_key !== FALSE) {
    unset($members[$source_dn_key]);
  }
  return $members;
}