From 6be4a68d5390195048a7a85c5471d67b1ec5c004 Mon Sep 17 00:00:00 2001 From: "Jamie V." Date: Thu, 22 Aug 2024 14:03:00 -0700 Subject: [PATCH] [Security] Remove Identity Plugin (#191) --- src/AMMOSPlugins.js | 7 +-- src/identity/LoginService.js | 92 --------------------------------- src/identity/close.html | 18 ------- src/identity/plugin.js | 20 ------- src/services/mcws/MCWSClient.js | 25 +-------- 5 files changed, 2 insertions(+), 160 deletions(-) delete mode 100644 src/identity/LoginService.js delete mode 100644 src/identity/close.html delete mode 100644 src/identity/plugin.js diff --git a/src/AMMOSPlugins.js b/src/AMMOSPlugins.js index 0d440e1..eac0b73 100644 --- a/src/AMMOSPlugins.js +++ b/src/AMMOSPlugins.js @@ -6,7 +6,6 @@ define([ './taxonomy/plugin', './time/plugin', 'services/time/vistaTime', - './identity/plugin', './historical/plugin', './realtime/plugin', './link/plugin', @@ -41,7 +40,6 @@ define([ TaxonomyPlugin, TimePlugin, getVistaTime, - IdentityPlugin, HistoricalTelemetryPlugin, RealtimeTelemetryPlugin, LinkPlugin, @@ -92,10 +90,7 @@ define([ }); openmct.install(RealtimeIndicatorPlugin.default(vistaTime)); - const identityPlugin = new IdentityPlugin(options); - openmct.install(identityPlugin); - - mcwsClient.default.configure(options, identityPlugin.login); + mcwsClient.default.configure(options); openmct.install(MultipleHistoricalSessions.default(options.tablePerformanceOptions)); openmct.install(RealtimeSessions.default()); diff --git a/src/identity/LoginService.js b/src/identity/LoginService.js deleted file mode 100644 index 0fae4a9..0000000 --- a/src/identity/LoginService.js +++ /dev/null @@ -1,92 +0,0 @@ -/*global define*/ -define( - [], - function () { - - - /** - * LoginService provides a simple interface for logging in a user. - * - * @param camUrl the url to use for logging in a user. - */ - function LoginService(camUrl) { - this.camUrl = camUrl; - this.overlay = undefined; - this.whenLoggedIn = undefined; - window.addEventListener('message', this.onMessage.bind(this)); - } - - /** - * @private - */ - LoginService.prototype.onMessage = function (event) { - var message = event.data; - if (message.name === 'login:complete') { - this.completeLogin(); - } - }; - - /** - * Return the login url, with a parameter to redirect to a local url - * after the login completes. - * @private - */ - LoginService.prototype.getLoginUrl = function () { - return this.camUrl + "?goto=" + - encodeURIComponent( - window.location.origin + - window.location.pathname + - 'src/identity/close.html' - ); - }; - - /** - * @private - */ - LoginService.prototype.show = function () { - this.overlay = document.createElement('div'); - this.overlay.classList.add('u-contents'); - - const iframe = document.createElement('iframe'); - iframe.classList.add('c-login-overlay'); - iframe.src = this.getLoginUrl(); - - this.overlay.appendChild(iframe); - document.body.appendChild(this.overlay); - }; - - /** - * Signal login as complete, dismiss the visible dialog, and resolve - * the login promise. - * @private - */ - LoginService.prototype.completeLogin = function () { - this.overlay.remove(); - this.resolve(); - delete this.overlay; - delete this.resolve; - delete this.reject; - }; - - /** - * Log in a user. Displays a login dialog in an iFrame. - * - * @returns Promise a promise that is resolved when a user is logged in, - * or rejected if they choose not to log in. - */ - LoginService.prototype.login = function () { - if (this.whenLoggedIn) { - return this.whenLoggedIn; - } - this.show(); - this.whenLoggedIn = new Promise(function(resolve, reject) { - this.resolve = resolve; - this.reject = reject; - }.bind(this)) - return this.whenLoggedIn; - }; - - return LoginService; - - } -); diff --git a/src/identity/close.html b/src/identity/close.html deleted file mode 100644 index fba17ec..0000000 --- a/src/identity/close.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - Login Completed - - - - - Log in successful, please wait... - - diff --git a/src/identity/plugin.js b/src/identity/plugin.js deleted file mode 100644 index 250d9a6..0000000 --- a/src/identity/plugin.js +++ /dev/null @@ -1,20 +0,0 @@ -define([ - './LoginService' -], function ( - LoginService -) { - - function IdentityPlugin(options) { - - return function install(openmct) { - if (options.proxyUrl) { - options.camUrl = options.proxyUrl + 'cam/UI/Login'; - } - var loginService = new LoginService(options.camUrl); - install.login = loginService.login.bind(loginService); - } - } - - return IdentityPlugin; - -}); diff --git a/src/services/mcws/MCWSClient.js b/src/services/mcws/MCWSClient.js index 614a449..67a9312 100644 --- a/src/services/mcws/MCWSClient.js +++ b/src/services/mcws/MCWSClient.js @@ -5,9 +5,8 @@ class MCWSClient { this._updatePending = this._updatePending.bind(this); } - configure(config, login) { + configure(config) { this.config = config; - this.login = login; } proxyRequest(options) { @@ -86,21 +85,6 @@ class MCWSClient { return this.proxyRequest(options); }; - isCamResponse(response) { - const contentType = response?.headers?.['content-type']; - - return contentType?.includes('text/html'); - } - - getResponseType(response) { - // TODO: more nuanced response handling should be done here - if (this.isCamResponse(response)) { - return 'cam'; - } else { - return 'unhandled'; - } - } - async authorizedRequest(options) { let response; const url = options.url; @@ -108,13 +92,6 @@ class MCWSClient { try { response = await this.baseRequest(url, options); - const responseType = this.getResponseType(response); - - if (responseType === 'cam') { - await this.login(); - - response = await this.baseRequest(url, options); - } } catch(error) { return Promise.reject(error); }