Fixed LDAP group sync using wrong user filter

LDAP group sync was trying to find users based on the external_auth_id
which is not garunteed to match the username entered so somtimes
the search for a user would fail.

This passes the username to the group sync.
Picked up by @yoyokko in #959.
This commit is contained in:
Dan Brown 2018-08-19 15:24:42 +01:00
parent 01260d95f3
commit d2a9b312e9
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 4 additions and 3 deletions

View File

@ -103,7 +103,7 @@ class LoginController extends Controller
// Sync LDAP groups if required
if ($this->ldapService->shouldSyncGroups()) {
$this->ldapService->syncGroups($user);
$this->ldapService->syncGroups($user, $request->get($this->username()));
}
$path = session()->pull('url.intended', '/');

View File

@ -299,11 +299,12 @@ class LdapService
/**
* Sync the LDAP groups to the user roles for the current user
* @param \BookStack\User $user
* @param string $username
* @throws LdapException
*/
public function syncGroups(User $user)
public function syncGroups(User $user, string $username)
{
$userLdapGroups = $this->getUserGroups($user->external_auth_id);
$userLdapGroups = $this->getUserGroups($username);
// Get the ids for the roles from the names
$ldapGroupsAsRoles = $this->matchLdapGroupsToSystemsRoles($userLdapGroups);