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

[NEW] Allow ldap mapping of customFields #7614

Merged

Conversation

goiaba
Copy link
Contributor

@goiaba goiaba commented Jul 31, 2017

Extending ldap mapping functionality to also allow custom fields synchronization.

@RocketChat/core

Closes #4332

Example:

ldapdatafieldmap

Extending ldap mapping functionality to also allow customFields synchronization.
@engelgabriel engelgabriel modified the milestone: 0.59.0 Aug 23, 2017
@rodrigok
Copy link
Member

@goiaba can you fix the conflict?

@goiaba
Copy link
Contributor Author

goiaba commented Aug 23, 2017

@rodrigok done.

const tmpLdapField = RocketChat.templateVarHandler(ldapField, ldapUser.object);
const userFieldValue = _.reduce(userField.split('.'), (acc, el) => acc[el], user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when a subfield is undefined? Like customFields.name.first and name is undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception! :$ I'll fix it.

Copy link
Contributor Author

@goiaba goiaba Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigok I see you've already merged this into develop branch, but I think you were right regarding this part of the code. An exception would be thrown and it would not be properly handled. You were faster than me, I didn't have enough time to push the changes before your merge. I'd recommend replacing this:

const userFieldValue = _.reduce(userField.split('.'), (acc, el) => acc[el], user);

by this (or something more elegant...):

let userFieldValue;

try {
	userFieldValue = _.reduce(userField.split('.'), (acc, el) => acc[el], user);
	if (!userFieldValue) {
		throw new Error();
	}
} catch (err) {
	logger.debug(`user attribute does not exist: ${ userField }`);
	return;
}

What do you think @rodrigok?

userData.name = tmpLdapField;
logger.debug(`user.name changed to: ${ tmpLdapField }`);
if (tmpLdapField && userFieldValue !== tmpLdapField) {
userData[userField] = tmpLdapField;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A field containing . will generate an exception in MongoDB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigok Didn't get this one. Is it possible to have a field containing .? Wouldn't MongoDB interpret it as a nested field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goiaba Is not possible to have a field containing ., since you are creating an object like:

{
  "name.first": "Rodrigo"
}

and it should be

{
  name: {
    first: 'rodrigo'
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigok

In my tests, if the variable userData contains the object { name: 'value1', 'customFields.secao-descricao': 'value2','customFields.secao-sigla': 'value3' }, the object stored in the users collection, inside a user document is "customFields" : { "secao-sigla" : "value3", "secao-descricao" : "value2" }. No exceptions occur.

We have other examples in the same code (sync.js), in the line 123, for instance: userData['services.ldap.id'] = uniqueId.value;.

Maybe I still didn't understand what you're trying to show me. :-(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @goiaba , I was totally wrong 😞

@rodrigok rodrigok merged commit 48af41d into RocketChat:develop Aug 24, 2017
@goiaba
Copy link
Contributor Author

goiaba commented Aug 25, 2017

@rodrigok This code is buggy! It doesn't work if the customFields do not already exist (causing an exception that prevents user's login). My bad! I already fixed the problem and can open a new PR later. May I create a new PR to revert the merge?

@magicbelette
Copy link
Contributor

Any news ?

Can't use ldap mapping with custom fileds with version 0.59.0 :
{"displayName":"name", "mail":"email", "departmentNumber":"customFields.dept"}

departmentNumber is correctly set in my ldap entry

Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: Exception while invoking method 'login' TypeError: Cannot read property 'dept' of undefined
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_ldap.js:1159:17
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at Array.reduce (native)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at Function._.reduce._.foldl._.inject (packages/underscore.js:173:28)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_ldap.js:1158:29
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at packages/underscore.js:159:29
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at _.each._.forEach (packages/underscore.js:147:22)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at Function._.map._.collect (packages/underscore.js:158:5)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at getDataToSyncUserData (/var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_ldap.js:1120:5)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at syncUserData (/var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_ldap.js:1200:17)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object].<anonymous> (/var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_ldap.js:748:3)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/accounts-base.js:925:30
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at tryLoginMethod (/var/www/Rocket.Chat-0.59.0/programs/server/packages/accounts-base.js:753:14)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at AccountsServer.Ap._runLoginHandlers (/var/www/Rocket.Chat-0.59.0/programs/server/packages/accounts-base.js:924:18)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at AccountsServer.Accounts._runLoginHandlers (/var/www/Rocket.Chat-0.59.0/programs/server/packages/rocketchat_lib.js:1951:33)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object].methods.login (/var/www/Rocket.Chat-0.59.0/programs/server/packages/accounts-base.js:982:27)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object].methodMap.(anonymous function) (packages/rocketchat_monitoring.js:2731:30)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at maybeAuditArgumentChecks (/var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:1857:12)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:903:20
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object].EVp.withValue (packages/meteor.js:1134:15)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:902:47
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object].EVp.withValue (packages/meteor.js:1134:15)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:901:46
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at [object Object]._.extend.protocol_handlers.method (/var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:874:21)
Oct 19 13:36:15 rc03 nodejs-rocketchat0[18531]: at /var/www/Rocket.Chat-0.59.0/programs/server/packages/ddp-server.js:753:85

@maxdwit
Copy link

maxdwit commented Nov 29, 2017

@magicbelette Maybe I missed this setting within the LDAP administration screen
I'am using 0.59.1+0.59.3 and can't see where I would put this.
I guess it must go in this field LDAP Sync/Import, where "{"cn":"name", "mail":"email"}" is defined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants