From a584bc3a19a430216ed730295564520fcdfb6384 Mon Sep 17 00:00:00 2001 From: Thomas Karolski Date: Wed, 9 Mar 2022 10:00:03 +0000 Subject: [PATCH] [Comm.js] Return a session profile based on the x-remote-user header if set --- app/server/lib/Comm.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/server/lib/Comm.js b/app/server/lib/Comm.js index b841ad9d..d00d1a99 100644 --- a/app/server/lib/Comm.js +++ b/app/server/lib/Comm.js @@ -150,6 +150,21 @@ Comm.prototype._broadcastMessage = function(type, data, clients) { clients.forEach(client => client.sendMessage({type, data})); }; + +Comm.prototype._getSessionProfile = function(scopedSession, req) { + // apply x-remote-user header as a profile if the header was set + if (req.headers && req.headers['x-remote-user']) { + const userName = req.headers['x-remote-user'].toString(); + return Promise.resolve({ + "email": userName, + "name": userName, + }); + } + return scopedSession.getSessionProfile(); +} + + + /** * Sends a per-doc message to the given client. * @param {Object} client - The client object, as passed to all per-doc methods. @@ -236,7 +251,7 @@ Comm.prototype._onWebSocketConnection = async function(websocket, req) { // Delegate message handling to the client websocket.on('message', client.onMessage.bind(client)); - scopedSession.getSessionProfile() + this._getSessionProfile(scopedSession, req) .then((profile) => { log.debug(`Comm ${client}: sending clientConnect with ` + `${client._missedMessages.length} missed messages`);