diff --git a/.changeset/witty-pumas-pretend.md b/.changeset/witty-pumas-pretend.md new file mode 100644 index 0000000000000..53e1b45a15eab --- /dev/null +++ b/.changeset/witty-pumas-pretend.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixed Atlassian Crowd integration with Rocket.Chat not working diff --git a/apps/meteor/app/api/server/v1/ldap.ts b/apps/meteor/app/api/server/v1/ldap.ts index f0d3a52b504fb..9a057c9b0afc4 100644 --- a/apps/meteor/app/api/server/v1/ldap.ts +++ b/apps/meteor/app/api/server/v1/ldap.ts @@ -31,7 +31,7 @@ API.v1.addRoute( } return API.v1.success({ - message: 'Connection_success' as const, + message: 'LDAP_Connection_successful' as const, }); }, }, diff --git a/apps/meteor/app/crowd/server/crowd.ts b/apps/meteor/app/crowd/server/crowd.ts index b6b94f33e5668..e43c65c70f918 100644 --- a/apps/meteor/app/crowd/server/crowd.ts +++ b/apps/meteor/app/crowd/server/crowd.ts @@ -68,23 +68,46 @@ export class CROWD { this.crowdClient = new AtlassianCrowd(this.options); } - async checkConnection() { - await this.crowdClient.ping(); + async checkConnection(): Promise { + return new Promise((resolve, reject) => + this.crowdClient.ping((err: any) => { + if (err) { + reject(err); + } + resolve(); + }), + ); } - async fetchCrowdUser(crowdUsername: string) { - const userResponse = await this.crowdClient.user.find(crowdUsername); + async fetchCrowdUser(crowdUsername: string): Promise> { + return new Promise((resolve, reject) => + this.crowdClient.user.find(crowdUsername, (err: any, userResponse: Record) => { + if (err) { + reject(err); + } + resolve({ + displayname: userResponse['display-name'], + username: userResponse.name, + email: userResponse.email, + active: userResponse.active, + crowd_username: crowdUsername, + }); + }), + ); + } - return { - displayname: userResponse['display-name'], - username: userResponse.name, - email: userResponse.email, - active: userResponse.active, - crowd_username: crowdUsername, - }; + async searchForCrowdUserByMail(email?: string): Promise | undefined> { + return new Promise((resolve) => + this.crowdClient.search('user', `email=" ${email} "`, (err: any, response: Record) => { + if (err) { + resolve(undefined); + } + resolve(response); + }), + ); } - async authenticate(username: string, password: string) { + async authenticate(username: string, password: string): Promise | undefined> { if (!username || !password) { logger.error('No username or password'); return; @@ -134,24 +157,30 @@ export class CROWD { logger.debug('New user. User is not synced yet.'); } logger.debug('Going to crowd:', crowdUsername); - const auth = await this.crowdClient.user.authenticate(crowdUsername, password); - - if (!auth) { - return; - } - const crowdUser: Record = await this.fetchCrowdUser(crowdUsername); - - if (user && settings.get('CROWD_Allow_Custom_Username') === true) { - crowdUser.username = user.username; - } + return new Promise((resolve, reject) => + this.crowdClient.user.authenticate(crowdUsername, password, async (err: any, res: Record) => { + if (err) { + reject(err); + } + const user = res; + try { + const crowdUser: Record = await this.fetchCrowdUser(crowdUsername); + if (user && settings.get('CROWD_Allow_Custom_Username') === true) { + crowdUser.username = user.name; + } - if (user) { - crowdUser._id = user._id; - } - crowdUser.password = password; + if (user) { + crowdUser._id = user._id; + } + crowdUser.password = password; - return crowdUser; + resolve(crowdUser); + } catch (err) { + reject(err); + } + }), + ); } async syncDataToUser(crowdUser: Record, id: string) { @@ -219,7 +248,7 @@ export class CROWD { const email = user.emails?.[0].address; logger.info('Attempting to find for user by email', email); - const response = this.crowdClient.searchSync('user', `email=" ${email} "`); + const response = await this.searchForCrowdUserByMail(email); if (!response || response.users.length === 0) { logger.warn('Could not find user in CROWD with username or email:', crowdUsername, email); if (settings.get('CROWD_Remove_Orphaned_Users') === true) { @@ -257,8 +286,15 @@ export class CROWD { } async updateUserCollection(crowdUser: Record) { + const username = crowdUser.crowd_username || crowdUser.username; + const mail = crowdUser.email; + + // If id is not provided, user is linked by crowd_username or email address const userQuery = { - _id: crowdUser._id, + ...(crowdUser._id && { _id: crowdUser._id }), + ...(!crowdUser._id && { + $or: [{ crowd_username: username }, { 'emails.address': mail }], + }), }; // find our existing user if they exist @@ -321,16 +357,17 @@ Accounts.registerLoginHandler('crowd', async function (this: typeof Accounts, lo } if (!user) { - logger.debug(`User ${loginRequest.username} is not allowd to access Rocket.Chat`); + logger.debug(`User ${loginRequest.username} is not allowed to access Rocket.Chat`); return new Meteor.Error('not-authorized', 'User is not authorized by crowd'); } const result = await crowd.updateUserCollection(user); return result; - } catch (err) { + } catch (err: any) { logger.debug({ err }); logger.error('Crowd user not authenticated due to an error'); + throw new Meteor.Error('user-not-found', err.message); } }); diff --git a/apps/meteor/app/crowd/server/methods.ts b/apps/meteor/app/crowd/server/methods.ts index 758ebd1fcb3c7..a621e3c8d0273 100644 --- a/apps/meteor/app/crowd/server/methods.ts +++ b/apps/meteor/app/crowd/server/methods.ts @@ -38,7 +38,7 @@ Meteor.methods({ await crowd.checkConnection(); return { - message: 'Connection_success' as const, + message: 'Crowd_Connection_successful' as const, params: [], }; } catch (err) { diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json index 6060705de4d3e..b841354a8b0fe 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json @@ -925,7 +925,7 @@ "Connection_Closed": "تم إغلاق الاتصال", "Connection_Reset": "إعادة تعيين الاتصال", "Connection_error": "خطأ في الاتصال", - "Connection_success": "اتصال LDAP ناجح", + "LDAP_Connection_successful": "اتصال LDAP ناجح", "Connection_failed": "فشل اتصال LDAP", "Connectivity_Services": "خدمات الاتصال", "Consulting": "الاستشارات", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json index f61d28735fe62..f960770eb116f 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json @@ -920,7 +920,7 @@ "Connection_Closed": "Connexió tancada", "Connection_Reset": "Connexió restablerta", "Connection_error": "Error de connexió", - "Connection_success": "Connexió LDAP correcta", + "LDAP_Connection_successful": "Connexió LDAP correcta", "Connection_failed": "Error de connexió LDAP", "Connectivity_Services": "Serveis de connectivitat", "Consulting": "Consultant", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json index 1c5931521c919..ec0faf0829aa6 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json @@ -753,7 +753,7 @@ "Connect": "Připojit", "Connection_Closed": "Připojení bylo uzavřeno", "Connection_Reset": "Obnovit připojení", - "Connection_success": "LDAP připojení úspěšné", + "LDAP_Connection_successful": "LDAP připojení úspěšné", "Connectivity_Services": "Služby připojení", "Consulting": "Konzultace", "Contact": "Kontakt", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json index d9aaf3f0a0033..522a3776dcc9f 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json @@ -757,7 +757,7 @@ "Connect": "Forbind", "Connection_Closed": "Forbindelse lukket", "Connection_Reset": "Nulstilning af forbindelse", - "Connection_success": "LDAP-forbindelse lykkedes", + "LDAP_Connection_successful": "LDAP-forbindelse lykkedes", "Connectivity_Services": "Connectivity Services", "Consulting": "Rådgivning", "Contact": "Kontakt", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/de.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/de.i18n.json index 68c54237e99bd..e5241fe68e1bc 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/de.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/de.i18n.json @@ -1046,7 +1046,7 @@ "Connection_Closed": "Verbindung geschlossen", "Connection_Reset": "Verbindung zurücksetzen", "Connection_error": "Verbindungsfehler", - "Connection_success": "LDAP-Verbindung erfolgreich", + "LDAP_Connection_successful": "LDAP-Verbindung erfolgreich", "Connection_failed": "LDAP-Verbindung fehlgeschlagen", "Connectivity_Services": "Verbindungsdienste", "Consulting": "Beratung", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 7f465b9175acd..bf9610f634aa2 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1133,7 +1133,6 @@ "Connection_Closed": "Connection closed", "Connection_Reset": "Connection reset", "Connection_error": "Connection error", - "Connection_success": "LDAP Connection Successful", "Connection_failed": "LDAP Connection Failed", "Connectivity_Services": "Connectivity Services", "Consulting": "Consulting", @@ -1457,6 +1456,7 @@ "Created_by": "Created by", "CRM_Integration": "CRM Integration", "CROWD_Allow_Custom_Username": "Allow custom username in Rocket.Chat", + "Crowd_Connection_successful": "Crowd Connection Successful", "CROWD_Reject_Unauthorized": "Reject Unauthorized", "Crowd_Remove_Orphaned_Users": "Remove Orphaned Users", "Crowd_sync_interval_Description": "The interval between synchronizations. Example `every 24 hours` or `on the first day of the week`, more examples at [Cron Text Parser](http://bunkat.github.io/later/parsers.html#text)", @@ -2905,6 +2905,7 @@ "LDAP_Connection": "Connection", "LDAP_Connection_Authentication": "Authentication", "LDAP_Connection_Encryption": "Encryption", + "LDAP_Connection_successful": "LDAP Connection Successful", "LDAP_Connection_Timeouts": "Timeouts", "LDAP_UserSearch": "User Search", "LDAP_UserSearch_Filter": "Search Filter", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/es.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/es.i18n.json index 9e1fed728dcec..861ea5723b4a6 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/es.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/es.i18n.json @@ -931,7 +931,7 @@ "Connection_Closed": "Conexión cerrada", "Connection_Reset": "Conexión restablecida", "Connection_error": "Error de conexión", - "Connection_success": "Conexión LDAP correcta", + "LDAP_Connection_successful": "Conexión LDAP correcta", "Connection_failed": "Error de conexión LDAP", "Connectivity_Services": "Servicios de conectividad", "Consulting": "Consultoría", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/fi.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/fi.i18n.json index 6cc6bae167e66..629665260a4d4 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/fi.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/fi.i18n.json @@ -1067,7 +1067,7 @@ "Connection_Closed": "Yhteys katkaistu", "Connection_Reset": "Yhteyden nollaus", "Connection_error": "Yhteysvirhe", - "Connection_success": "LDAP-yhteys onnistui", + "LDAP_Connection_successful": "LDAP-yhteys onnistui", "Connection_failed": "LDAP-yhteys epäonnistui", "Connectivity_Services": "Yhteyspalvelut", "Consulting": "Konsultointi", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/fr.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/fr.i18n.json index f239fcc0fc742..c0c866af1b0aa 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/fr.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/fr.i18n.json @@ -928,7 +928,7 @@ "Connection_Closed": "Connexion fermée", "Connection_Reset": "Connexion réinitialisée", "Connection_error": "Erreur de connexion", - "Connection_success": "Connexion LDAP réussie", + "LDAP_Connection_successful": "Connexion LDAP réussie", "Connection_failed": "Échec de la connexion LDAP", "Connectivity_Services": "Services de connectivité", "Consulting": "Conseil", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/hu.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/hu.i18n.json index 0f9e12f8b5993..9149c72fdeecf 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/hu.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/hu.i18n.json @@ -1028,7 +1028,7 @@ "Connection_Closed": "Kapcsolat lezárva", "Connection_Reset": "Kapcsolat visszaállítva", "Connection_error": "Kapcsolódási hiba", - "Connection_success": "Az LDAP-kapcsolat sikeres", + "LDAP_Connection_successful": "Az LDAP-kapcsolat sikeres", "Connection_failed": "Az LDAP-kapcsolat sikertelen", "Connectivity_Services": "Kapcsolódási szolgáltatások", "Consulting": "Tanácsadás", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/ja.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/ja.i18n.json index 9487983bf9f79..81f51b667cd92 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/ja.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/ja.i18n.json @@ -915,7 +915,7 @@ "Connection_Closed": "接続が閉じられました", "Connection_Reset": "接続のリセット", "Connection_error": "接続エラー", - "Connection_success": "LDAP接続に成功しました", + "LDAP_Connection_successful": "LDAP接続に成功しました", "Connection_failed": "LDAP接続が失敗しました", "Connectivity_Services": "接続サービス", "Consulting": "コンサルティング", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/ko.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/ko.i18n.json index 0341f6388348a..6cd9d58a86922 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/ko.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/ko.i18n.json @@ -795,7 +795,7 @@ "Connect": "연결", "Connection_Closed": "연결이 닫혔습니다.", "Connection_Reset": "연결 재설정", - "Connection_success": "LDAP 연결 성공", + "LDAP_Connection_successful": "LDAP 연결 성공", "Connectivity_Services": "연결 서비스", "Consulting": "컨설팅", "Contact": "연락처", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/nl.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/nl.i18n.json index 23e356f28eeed..fd9833d157690 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/nl.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/nl.i18n.json @@ -923,7 +923,7 @@ "Connection_Closed": "Verbinding gesloten", "Connection_Reset": "Verbinding gereset", "Connection_error": "Verbindingsfout", - "Connection_success": "LDAP-verbinding geslaagd", + "LDAP_Connection_successful": "LDAP-verbinding geslaagd", "Connection_failed": "LDAP-verbinding mislukt", "Connectivity_Services": "Connectiviteitsdiensten", "Consulting": "Consultant", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/pl.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/pl.i18n.json index aa8ca813b4453..2ff9ceb1ab86f 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/pl.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/pl.i18n.json @@ -1007,7 +1007,7 @@ "Connection_Closed": "Połączenie zamknięte", "Connection_Reset": "Reset połączenia", "Connection_error": "Błąd połączenia", - "Connection_success": "Nawiązano połączenie z LDAP", + "LDAP_Connection_successful": "Nawiązano połączenie z LDAP", "Connection_failed": "Nie można nawiązać połączenia z LDAP", "Connectivity_Services": "Usługi łączności", "Consulting": "Doradztwo", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index 4daea7308d8af..260d3828c7963 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -965,7 +965,7 @@ "Connection_Closed": "Conexão fechada", "Connection_Reset": "Redefinição de conexão", "Connection_error": "Erro de conexão", - "Connection_success": "Conexão com LDAP bem-sucedida", + "LDAP_Connection_successful": "Conexão com LDAP bem-sucedida", "Connection_failed": "Falha na conexão com o LDAP", "Connectivity_Services": "Serviços de conectividade", "Consulting": "Consultoria", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/ru.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/ru.i18n.json index e3dc8d0a57919..c73e1fa58d20e 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/ru.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/ru.i18n.json @@ -1028,7 +1028,7 @@ "Connection_Closed": "Соединение закрыто", "Connection_Reset": "Сброс соединения", "Connection_error": "Ошибка подключения", - "Connection_success": "Подключение к LDAP успешное", + "LDAP_Connection_successful": "Подключение к LDAP успешное", "Connection_failed": "Сбой подключения LDAP", "Connectivity_Services": "Connectivity Services", "Consulting": "Консалтинг", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/sv.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/sv.i18n.json index 94964cee15d68..03d733f7eaea1 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/sv.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/sv.i18n.json @@ -1064,7 +1064,7 @@ "Connection_Closed": "Anslutningen är stängd", "Connection_Reset": "Anslutning återställd", "Connection_error": "Anslutningsfel", - "Connection_success": "LDAP-anslutningen har upprättats", + "LDAP_Connection_successful": "LDAP-anslutningen har upprättats", "Connection_failed": "LDAP-anslutningen kunde inte upprättas", "Connectivity_Services": "Anslutningstjänster", "Consulting": "Consulting", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/zh-TW.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/zh-TW.i18n.json index 8bbb614c560b9..d5e8e05f71fbf 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/zh-TW.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/zh-TW.i18n.json @@ -914,7 +914,7 @@ "Connection_Closed": "連接關閉", "Connection_Reset": "連線重置", "Connection_error": "連線錯誤", - "Connection_success": "LDAP 連接成功", + "LDAP_Connection_successful": "LDAP 連接成功", "Connection_failed": "LDAP 連線失敗", "Connectivity_Services": "連線的服務", "Consulting": "諮詢", diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/zh.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/zh.i18n.json index 7d4a50c8e3621..d2df7281184e1 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/zh.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/zh.i18n.json @@ -809,7 +809,7 @@ "Connect_SSL_TLS": "使用 SSL/TLS 连接", "Connection_Closed": "连接关闭", "Connection_Reset": "连接重置", - "Connection_success": "LDAP 连接成功", + "LDAP_Connection_successful": "LDAP 连接成功", "Connectivity_Services": "连接性服务", "Consulting": "咨询", "Contact": "联系人",