Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-pumas-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed Atlassian Crowd integration with Rocket.Chat not working
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/ldap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ API.v1.addRoute(
}

return API.v1.success({
message: 'Connection_success' as const,
message: 'LDAP_Connection_successful' as const,
});
},
},
Expand Down
99 changes: 68 additions & 31 deletions apps/meteor/app/crowd/server/crowd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,46 @@ export class CROWD {
this.crowdClient = new AtlassianCrowd(this.options);
}

async checkConnection() {
await this.crowdClient.ping();
async checkConnection(): Promise<void> {
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<Record<string, any>> {
return new Promise((resolve, reject) =>
this.crowdClient.user.find(crowdUsername, (err: any, userResponse: Record<string, any>) => {
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<Record<string, any> | undefined> {
return new Promise((resolve) =>
this.crowdClient.search('user', `email=" ${email} "`, (err: any, response: Record<string, any>) => {
if (err) {
resolve(undefined);
}
resolve(response);
}),
);
}

async authenticate(username: string, password: string) {
async authenticate(username: string, password: string): Promise<Record<string, any> | undefined> {
if (!username || !password) {
logger.error('No username or password');
return;
Expand Down Expand Up @@ -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<string, any> = 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<string, any>) => {
if (err) {
reject(err);
}
const user = res;
try {
const crowdUser: Record<string, any> = 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<string, any>, id: string) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -257,8 +286,15 @@ export class CROWD {
}

async updateUserCollection(crowdUser: Record<string, any>) {
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
Expand Down Expand Up @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/crowd/server/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Meteor.methods<ServerMethods>({
await crowd.checkConnection();

return {
message: 'Connection_success' as const,
message: 'Crowd_Connection_successful' as const,
params: [],
};
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/ar.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@
"Connection_Closed": "تم إغلاق الاتصال",
"Connection_Reset": "إعادة تعيين الاتصال",
"Connection_error": "خطأ في الاتصال",
"Connection_success": "اتصال LDAP ناجح",
"LDAP_Connection_successful": "اتصال LDAP ناجح",
"Connection_failed": "فشل اتصال LDAP",
"Connectivity_Services": "خدمات الاتصال",
"Consulting": "الاستشارات",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/ca.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/cs.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/da.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/es.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/fi.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/fr.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/hu.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/ja.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@
"Connection_Closed": "接続が閉じられました",
"Connection_Reset": "接続のリセット",
"Connection_error": "接続エラー",
"Connection_success": "LDAP接続に成功しました",
"LDAP_Connection_successful": "LDAP接続に成功しました",
"Connection_failed": "LDAP接続が失敗しました",
"Connectivity_Services": "接続サービス",
"Consulting": "コンサルティング",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/ko.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@
"Connect": "연결",
"Connection_Closed": "연결이 닫혔습니다.",
"Connection_Reset": "연결 재설정",
"Connection_success": "LDAP 연결 성공",
"LDAP_Connection_successful": "LDAP 연결 성공",
"Connectivity_Services": "연결 서비스",
"Consulting": "컨설팅",
"Contact": "연락처",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/nl.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/pl.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/ru.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Консалтинг",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/sv.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@
"Connection_Closed": "連接關閉",
"Connection_Reset": "連線重置",
"Connection_error": "連線錯誤",
"Connection_success": "LDAP 連接成功",
"LDAP_Connection_successful": "LDAP 連接成功",
"Connection_failed": "LDAP 連線失敗",
"Connectivity_Services": "連線的服務",
"Consulting": "諮詢",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/zh.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@
"Connect_SSL_TLS": "使用 SSL/TLS 连接",
"Connection_Closed": "连接关闭",
"Connection_Reset": "连接重置",
"Connection_success": "LDAP 连接成功",
"LDAP_Connection_successful": "LDAP 连接成功",
"Connectivity_Services": "连接性服务",
"Consulting": "咨询",
"Contact": "联系人",
Expand Down