Crivaledaz / Mattermost-LDAP

This module provides an external LDAP authentication in Mattermost for the Team Edition (free).
MIT License
359 stars 71 forks source link

Complete name splitting #68

Closed xDFCx closed 3 years ago

xDFCx commented 4 years ago

Hello. I've noticed that after installing your plugin names in MM got screwed. Thats because of our style of CN field filling in AD. In Russia full name more naturally looks like "Surname Name Patronymic". So it gets into MM wrong - surname goes into first_name field and name&patronymic goes into last_name. So i wanted to make a little fix in php scripts to change the way complete name is splitted. Unfortunately, I could not find where it happens in sources - I'm not a developer. May be you could help me pointing the right place? Or even, may be this could appear in config file as an option - the "naming template" or something like that. Thanks in advance.

Crivaledaz commented 4 years ago

Hi,

Sorry for this late answer, I was very busy last weeks.

You are right, Mattermost-LDAP supposes your LDAP have an attribut containing user fullname and send it as it to Mattermost. In fact, Mattermost is expected a parameter name in the Oauth returned data. Mattermost retrieves the lastname and firstname by itself from this parameter. I suppose GitLab send the name to Mattermost in a specific format shared with Mattermost.

If you want to adapt the value of the name parameter, you should edit it before it is sent. This will take place in the oauth/resource.php file. You will find the LDAP name attribut in the variable data['cn']. If you want to retrieve others attributs from LDAP, for example the firstname and lastname separately, you need to edit the function getDataForMattermost() in the LDAP class.

The best would be to let user choose which LDAP attribut to use for lastname and which to use for firstname and after construct the name parameter in the expected Mattermost format from these two data. This could replace the current unique name setting in Mattermost-LDAP. Feel free to make a pull request for this :). Else, I put this feature on my ToDo list and I will implement it when I have more free time.

Thanks you for your feedback, I hope my answer will help you, else do not hesitate to come back to me.

Regards.

PS : I am not a developper either, actually I am a system and software integrator, so I assure you is easy to make a dirty patch to solve your issue :).

xDFCx commented 3 years ago

Well, I solved my problem adding

$arr_full = explode(' ', $cn[0]);
$cn[0] = $arr_full[1].' '. $arr_full[0];

in line 214 in LDAP.php. I know its ugly, but it works in my case. Thanks for help!