diff --git a/src/auth/AuthManager.ts b/src/auth/AuthManager.ts index a9dce8a..77fab8b 100644 --- a/src/auth/AuthManager.ts +++ b/src/auth/AuthManager.ts @@ -136,7 +136,17 @@ export class AuthManager { if (isLoggedIn) { if (this.serverType === ServerType.Sas9) { - await this.performCASSecurityCheck() + const casSecurityCheckResponse = await this.performCASSecurityCheck() + + if (isPublicAccessDenied(casSecurityCheckResponse.result)) { + isLoggedIn = false + + return { + isLoggedIn, + userName: this.userName || '', + errorMessage: 'Public access has been denied.' + } + } } this.loginCallback() @@ -151,7 +161,7 @@ export class AuthManager { private async performCASSecurityCheck() { const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check` - await this.requestClient.get( + return await this.requestClient.get( `/SASLogon/login?service=${casAuthenticationUrl}`, undefined ) @@ -361,3 +371,7 @@ const isLogInSuccess = (serverType: ServerType, response: any): boolean => { return /You have signed in/gm.test(response) } + +const isPublicAccessDenied = (response: any): boolean => { + return /Public access has been denied/gm.test(response) +} diff --git a/src/job-execution/WebJobExecutor.ts b/src/job-execution/WebJobExecutor.ts index fe52903..24af9a3 100644 --- a/src/job-execution/WebJobExecutor.ts +++ b/src/job-execution/WebJobExecutor.ts @@ -187,6 +187,12 @@ export class WebJobExecutor extends BaseJobExecutor { { result: jsonResponse, log: res.log }, extraResponseAttributes ) + + if (this.isPublicAccessDenied(jsonResponse)) + reject( + new ErrorResponse('Public access has been denied', responseObject) + ) + resolve(responseObject) }) .catch(async (e: Error) => { @@ -262,4 +268,8 @@ export class WebJobExecutor extends BaseJobExecutor { } return uri } + + private isPublicAccessDenied = (response: string): boolean => { + return /Public access has been denied/gm.test(response) + } } diff --git a/src/types/Login.ts b/src/types/Login.ts index 6239456..5b978bd 100644 --- a/src/types/Login.ts +++ b/src/types/Login.ts @@ -5,4 +5,5 @@ export interface LoginOptions { export interface LoginResult { isLoggedIn: boolean userName: string + errorMessage?: string }