From ffd421bed6c6e23da2f99194378286abe71bae94 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 1 Sep 2021 18:01:13 +0530 Subject: [PATCH] cc: Remove authentication code related to standard environment --- .../cc/ui/src/components/Main.tsx | 72 +++++++++---------- .../cc/ui/src/components/pages/LoginPage.js | 11 ++- .../cc/ui/src/services/AuthService.js | 20 +----- 3 files changed, 43 insertions(+), 60 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/Main.tsx b/monkey/monkey_island/cc/ui/src/components/Main.tsx index 65ecfc6be..cfd04b39d 100644 --- a/monkey/monkey_island/cc/ui/src/components/Main.tsx +++ b/monkey/monkey_island/cc/ui/src/components/Main.tsx @@ -67,7 +67,6 @@ class AppComponent extends AuthComponent { loading: true, completedSteps: completedSteps, islandMode: undefined, - noAuthLoginAttempted: undefined }; this.interval = undefined; this.setMode(); @@ -77,45 +76,44 @@ class AppComponent extends AuthComponent { if (this.state.isLoggedIn === false) { return } - this.auth.loggedIn() - .then(res => { - if (this.state.isLoggedIn !== res) { - this.setState({ - isLoggedIn: res - }); - } - if (!res) { - this.auth.needsRegistration() - .then(result => { - this.setState({ - needsRegistration: result - }); - }) - } + let res = this.auth.loggedIn(); - if (res) { - this.setMode() - .then(() => { - if (this.state.islandMode === null) { - return - } - this.authFetch('/api') - .then(res => res.json()) - .then(res => { - let completedSteps = CompletedSteps.buildFromResponse(res.completed_steps); - // This check is used to prevent unnecessary re-rendering - if (_.isEqual(this.state.completedSteps, completedSteps)) { - return; - } - this.setState({completedSteps: completedSteps}); - this.showInfectionDoneNotification(); - }); - } - ) - - } + if (this.state.isLoggedIn !== res) { + this.setState({ + isLoggedIn: res }); + } + + if (!res) { + this.auth.needsRegistration() + .then(result => { + this.setState({ + needsRegistration: result + }); + }) + } + + if (res) { + this.setMode() + .then(() => { + if (this.state.islandMode === null) { + return + } + this.authFetch('/api') + .then(res => res.json()) + .then(res => { + let completedSteps = CompletedSteps.buildFromResponse(res.completed_steps); + // This check is used to prevent unnecessary re-rendering + if (_.isEqual(this.state.completedSteps, completedSteps)) { + return; + } + this.setState({completedSteps: completedSteps}); + this.showInfectionDoneNotification(); + }); + } + ) + } }; setMode = () => { diff --git a/monkey/monkey_island/cc/ui/src/components/pages/LoginPage.js b/monkey/monkey_island/cc/ui/src/components/pages/LoginPage.js index 961c1899c..0a281157f 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/LoginPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/LoginPage.js @@ -48,12 +48,11 @@ class LoginPageComponent extends React.Component { this.redirectToRegistration() } }) - this.auth.loggedIn() - .then(res => { - if (res) { - this.redirectToHome(); - } - }); + + if (this.auth.loggedIn()) { + this.redirectToHome(); + } + } render() { diff --git a/monkey/monkey_island/cc/ui/src/services/AuthService.js b/monkey/monkey_island/cc/ui/src/services/AuthService.js index d7d1b9c2f..11cf37044 100644 --- a/monkey/monkey_island/cc/ui/src/services/AuthService.js +++ b/monkey/monkey_island/cc/ui/src/services/AuthService.js @@ -1,8 +1,6 @@ import decode from 'jwt-decode'; export default class AuthService { - NO_AUTH_CREDS = '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()'; - SECONDS_BEFORE_JWT_EXPIRES = 20; AUTHENTICATION_API_ENDPOINT = '/api/auth'; REGISTRATION_API_ENDPOINT = '/api/registration'; @@ -16,7 +14,7 @@ export default class AuthService { }; jwtHeader = () => { - if (this._loggedIn()) { + if (this.loggedIn()) { return 'Bearer ' + this._getToken(); } }; @@ -68,7 +66,7 @@ export default class AuthService { 'Content-Type': 'application/json' }; - if (this._loggedIn()) { + if (this.loggedIn()) { headers['Authorization'] = 'Bearer ' + this._getToken(); } @@ -101,19 +99,7 @@ export default class AuthService { }) }; - async loggedIn() { - let token = this._getToken(); - if ((token === null) || (this._isTokenExpired(token))) { - await this.attemptNoAuthLogin(); - } - return this._loggedIn(); - } - - attemptNoAuthLogin() { - return this._login(this.NO_AUTH_CREDS, this.NO_AUTH_CREDS); - } - - _loggedIn() { + loggedIn() { const token = this._getToken(); return ((token !== null) && !this._isTokenExpired(token)); }