From b723c904e674c79d171645d1b784777d54c84be3 Mon Sep 17 00:00:00 2001 From: Romain Date: Fri, 20 Jul 2018 16:54:07 +0200 Subject: [PATCH] Query multiple groups I add a loop inside the group_dn query. It is better if a user is in multiple groups. --- login-ldap.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/login-ldap.php b/login-ldap.php index 6578bf3..aac5b9f 100644 --- a/login-ldap.php +++ b/login-ldap.php @@ -172,18 +172,22 @@ public function userLoginAuthenticate(UserLoginEvent $event) // retrieves all extra groups for user $group_query = str_replace('[username]', $credentials['username'], $group_query); $group_query = str_replace('[dn]', $userdata['dn'], $group_query); + $query = $ldap->query($group_dn, $group_query); $groups = $query->execute()->toArray(); // retrieve current primary group for user $query = $ldap->query($group_dn, 'gidnumber=' . $this->getLDAPMappedItem('gidNumber', $ldap_data)); + $groups = array_merge($groups, $query->execute()->toArray()); foreach ($groups as $group) { $attributes = $group->getAttributes(); - $user_group = array_shift($attributes[$group_indentifier]); - $user_groups[] = $user_group; - + foreach ($attributes[$group_indentifier] as $one_group){ + $this->grav['log']->debug('One group : ' . serialize($one_group)); + $user_group = array_shift($attributes[$group_indentifier]); + $user_groups[] = $user_group; + } if ($this->config->get('plugins.login-ldap.store_ldap_data', false)) { $userdata['ldap']['groups'][] = $user_group; }