Skip to content

Commit

Permalink
Merge pull request #8613 from RocketChat/hotifx/ldap-merge-users
Browse files Browse the repository at this point in the history
[FIX] LDAP not merging existent users && Wrong id link generation
  • Loading branch information
rodrigok committed Oct 25, 2017
1 parent 1e99e7b commit 16fde7b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/rocketchat-ldap/server/ldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export default class LDAP {
Object.keys(values).forEach((key) => {
const value = values[key];
if (!['thumbnailPhoto', 'jpegPhoto'].includes(key) && value instanceof Buffer) {
values[key] = value.toString();
values[key] = value.toString('binary');
}
});

Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-ldap/server/loginHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,11 @@ Accounts.registerLoginHandler('ldap', function(loginRequest) {
}

// Create new user
return addLdapUser(ldapUser, username, loginRequest.ldapPass);
const result = addLdapUser(ldapUser, username, loginRequest.ldapPass);

if (result instanceof Error) {
throw result;
}

return result;
});
15 changes: 8 additions & 7 deletions packages/rocketchat-ldap/server/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function getLdapUserUniqueID(ldapUser) {
if (Unique_Identifier_Field) {
Unique_Identifier_Field = {
attribute: Unique_Identifier_Field,
value: new Buffer(ldapUser[Unique_Identifier_Field]).toString('hex')
value: new Buffer(ldapUser[Unique_Identifier_Field], 'binary').toString('hex')
};
}
return Unique_Identifier_Field;
Expand Down Expand Up @@ -213,7 +213,7 @@ export function addLdapUser(ldapUser, username, password) {
userObject._id = Accounts.createUser(userObject);
} catch (error) {
logger.error('Error creating user', error);
throw error;
return error;
}

syncUserData(userObject, ldapUser);
Expand Down Expand Up @@ -257,10 +257,7 @@ export function importNewUsers(ldap) {
}

// Add user if it was not added before
const user = Meteor.users.findOne(userQuery);
if (!user) {
addLdapUser(ldapUser, username);
}
let user = Meteor.users.findOne(userQuery);

if (!user && username && RocketChat.settings.get('LDAP_Merge_Existing_Users') === true) {
const userQuery = {
Expand All @@ -269,12 +266,16 @@ export function importNewUsers(ldap) {

logger.debug('userQuery merge', userQuery);

const user = Meteor.users.findOne(userQuery);
user = Meteor.users.findOne(userQuery);
if (user) {
syncUserData(user, ldapUser);
}
}

if (!user) {
addLdapUser(ldapUser, username);
}

if (count % 100 === 0) {
logger.info('Import running. Users imported until now:', count);
}
Expand Down

0 comments on commit 16fde7b

Please sign in to comment.