Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LDAP Group filter doesn't work and throws "No Such Object" error on login #31377

Merged
merged 8 commits into from
Jan 12, 2024
5 changes: 5 additions & 0 deletions .changeset/wet-crabs-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed LDAP "Group filter" malfunction, which prevented LDAP users from logging in.
4 changes: 2 additions & 2 deletions apps/meteor/server/lib/ldap/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ export class LDAPConnection {

searchLogger.debug({ msg: 'Group filter LDAP:', filter: searchOptions.filter });

const result = await this.searchRaw(this.options.baseDN, searchOptions);
const result = await this.searchAndCount(this.options.baseDN, searchOptions);

if (!Array.isArray(result) || result.length === 0) {
if (result === 0) {
return false;
}
return true;
Expand Down
9 changes: 4 additions & 5 deletions apps/meteor/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export class LDAPManager {
}

const [ldapUser] = users;
if (!(await ldap.isUserAcceptedByGroupFilter(escapedUsername, ldapUser.dn))) {
throw new Error('User not found');
}

if (!(await ldap.authenticate(ldapUser.dn, password))) {
logger.debug(`Wrong password for ${escapedUsername}`);
throw new Error('Invalid user or wrong password');
Expand All @@ -212,11 +216,6 @@ export class LDAPManager {
authLogger.debug(`Bind successful but user ${ldapUser.dn} was not found via search`);
}
}

if (!(await ldap.isUserAcceptedByGroupFilter(escapedUsername, ldapUser.dn))) {
throw new Error('User not in a valid group');
}

return ldapUser;
} catch (error) {
logger.error(error);
Expand Down
Loading