You are here

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

Get list of groups that a user is a member of using the memberOf attribute.

Parameters

\Symfony\Component\Ldap\Entry $ldap_entry: A Drupal user entity, an LDAP entry array of a user or a username.

Return value

array Array of group dns in mixed case or FALSE on error.

See also

groupMembershipsFromUser()

1 call to LdapGroupManager::groupUserMembershipsFromUserAttr()
LdapGroupManager::groupMembershipsFromUser in ldap_servers/src/LdapGroupManager.php
Get list of all groups that a user is a member of.

File

ldap_servers/src/LdapGroupManager.php, line 508

Class

LdapGroupManager
LDAP Group Manager.

Namespace

Drupal\ldap_servers

Code

public function groupUserMembershipsFromUserAttr(Entry $ldap_entry) : array {
  if (!$this
    ->checkAvailability() || !$this->server
    ->isGroupUserMembershipAttributeInUse()) {
    return [];
  }
  $group_attribute = $this->server
    ->getGroupUserMembershipAttribute();
  if (!$ldap_entry
    ->hasAttribute($group_attribute, FALSE)) {
    return [];
  }
  $level = 0;
  $all_group_dns = [];
  $members_group_dns = $ldap_entry
    ->getAttribute($group_attribute, FALSE);
  $orFilters = [];
  foreach ($members_group_dns as $member_group_dn) {
    $all_group_dns[] = $member_group_dn;
    if ($this->server
      ->get('grp_nested')) {
      if ($this->server
        ->get('grp_memb_attr_match_user_attr') === 'dn') {
        $member_value = $member_group_dn;
      }
      else {
        $member_value = $this
          ->getFirstRdnValueFromDn($member_group_dn);
      }
      $orFilters[] = $this->server
        ->get('grp_memb_attr') . '=' . $this
        ->ldapEscapeDn($member_value);
    }
  }
  if ($this->server
    ->get('grp_nested') && count($orFilters)) {
    $all_group_dns = $this
      ->getNestedGroupDnFilters($all_group_dns, $orFilters, $level);
  }
  return $all_group_dns;
}