Skip to content

Commit

Permalink
Merge pull request #8691 from RocketChat/hotfix/ldap-utf8
Browse files Browse the repository at this point in the history
[FIX] LDAP not respecting UTF8 characters & Sync Interval not working
  • Loading branch information
rodrigok committed Oct 28, 2017
2 parents ed35507 + fa034c2 commit e2c0fc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 13 additions & 5 deletions packages/rocketchat-ldap/server/ldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,19 @@ export default class LDAP {
}

extractLdapEntryData(entry) {
const values = entry.raw;
Object.keys(values).forEach((key) => {
const value = values[key];
if (!['thumbnailPhoto', 'jpegPhoto'].includes(key) && value instanceof Buffer) {
values[key] = value.toString('binary');
const values = {
_raw: entry.raw
};

Object.keys(values._raw).forEach((key) => {
const value = values._raw[key];

if (!['thumbnailPhoto', 'jpegPhoto'].includes(key)) {
if (value instanceof Buffer) {
values[key] = value.toString();
} else {
values[key] = value;
}
}
});

Expand Down
11 changes: 6 additions & 5 deletions packages/rocketchat-ldap/server/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export function getLdapUserUniqueID(ldapUser) {

if (Unique_Identifier_Field.length > 0) {
Unique_Identifier_Field = Unique_Identifier_Field.find((field) => {
return !_.isEmpty(ldapUser[field]);
return !_.isEmpty(ldapUser._raw[field]);
});
if (Unique_Identifier_Field) {
Unique_Identifier_Field = {
attribute: Unique_Identifier_Field,
value: new Buffer(ldapUser[Unique_Identifier_Field], 'binary').toString('hex')
value: ldapUser._raw[Unique_Identifier_Field].toString('hex')
};
}
return Unique_Identifier_Field;
Expand Down Expand Up @@ -151,7 +151,7 @@ export function syncUserData(user, ldapUser) {
}

if (user && user._id && RocketChat.settings.get('LDAP_Sync_User_Avatar') === true) {
const avatar = ldapUser.thumbnailPhoto || ldapUser.jpegPhoto;
const avatar = ldapUser._raw.thumbnailPhoto || ldapUser._raw.jpegPhoto;
if (avatar) {
logger.info('Syncing user avatar');

Expand Down Expand Up @@ -343,15 +343,16 @@ const addCronJob = _.debounce(Meteor.bindEnvironment(function addCronJobDebounce
return;
}

if (RocketChat.settings.get('LDAP_Sync_Interval')) {
if (RocketChat.settings.get('LDAP_Background_Sync_Interval')) {
logger.info('Enabling LDAP Background Sync');
SyncedCron.add({
name: jobName,
schedule: (parser) => parser.text(RocketChat.settings.get('LDAP_Sync_Interval')),
schedule: (parser) => parser.text(RocketChat.settings.get('LDAP_Background_Sync_Interval')),
job() {
sync();
}
});
SyncedCron.start();
}
}), 500);

Expand Down

0 comments on commit e2c0fc9

Please sign in to comment.