fix(xo-server-auth-ldap/synchronizeGroups): fix adding users to groups (#5545)

Fixes xoa-support#3333
Introduced by 8cfaabedeb

`synchronizeGroups` (called without a user) tries to find XO users that belong
to LDAP groups and add them to those groups. In order to find those users, it
was using the `userIdAttribute` attribute instead of the
`membersMapping.userAttribute` attribute from the configuration.
This commit is contained in:
Pierre Donias
2021-02-04 11:45:59 +01:00
committed by GitHub
parent 8bb7803d23
commit be8c77af5a
2 changed files with 17 additions and 2 deletions

View File

@@ -11,6 +11,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [LDAP] "Synchronize LDAP groups" button: fix imported LDAP users not being correctly added or removed from groups in some cases (PR [#5545](https://github.com/vatesfr/xen-orchestra/pull/5545))
### Packages to release
> Packages will be released in the order they are here, therefore, they should
@@ -27,3 +29,5 @@
> - major: if the change breaks compatibility
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-server-auth-ldap patch

View File

@@ -418,8 +418,19 @@ class AuthLdap {
const xoGroupMembers = xoGroup.users === undefined ? [] : xoGroup.users.slice(0)
for (const ldapId of ldapGroupMembers) {
const xoUser = xoUsers.find(user => user.authProviders.ldap.id === ldapId)
for (const memberId of ldapGroupMembers) {
const {
searchEntries: [ldapUser],
} = await client.search(this._searchBase, {
scope: 'sub',
filter: `(${escape(membersMapping.userAttribute)}=${escape(memberId)})`,
sizeLimit: 1,
})
if (ldapUser === undefined) {
continue
}
const xoUser = xoUsers.find(user => user.authProviders.ldap.id === ldapUser[this._userIdAttribute])
if (xoUser === undefined) {
continue
}