diff --git a/deploy-board/deploy_board/templates/clusters/base_images_events.html b/deploy-board/deploy_board/templates/clusters/base_images_events.html index 2a5a3afc89..0384b571b7 100644 --- a/deploy-board/deploy_board/templates/clusters/base_images_events.html +++ b/deploy-board/deploy_board/templates/clusters/base_images_events.html @@ -53,7 +53,7 @@
{{ stacktrace }} diff --git a/deploy-board/deploy_board/webapp/helpers/base_client.py b/deploy-board/deploy_board/webapp/helpers/base_client.py index c16e637af0..a99f39cf86 100644 --- a/deploy-board/deploy_board/webapp/helpers/base_client.py +++ b/deploy-board/deploy_board/webapp/helpers/base_client.py @@ -56,11 +56,10 @@ def api(path, token=None, params=None, data=None): if response.status_code == 401: raise FailedAuthenticationException( - "Oops! Teletraan was unable to authenticate you. Contact an environment ADMIN for " - "assistance. " + response.text) + f"Oops! Teletraan was unable to authenticate you. Please re-login. Server message: {response.json()['message']}") if response.status_code == 403: - raise NotAuthorizedException(f'{UNAUTHORIZED_ERROR_TEXT}: {response.text}') + raise NotAuthorizedException(f"{UNAUTHORIZED_ERROR_TEXT}. Server message: {response.json()['message']}") if response.status_code == 400 or response.status_code == 422: raise IllegalArgumentException(response.text) diff --git a/deploy-board/deploy_board/webapp/helpers/exceptions.py b/deploy-board/deploy_board/webapp/helpers/exceptions.py index 54325a9192..099c95b763 100644 --- a/deploy-board/deploy_board/webapp/helpers/exceptions.py +++ b/deploy-board/deploy_board/webapp/helpers/exceptions.py @@ -15,12 +15,6 @@ # -*- coding: utf-8 -*- """Backend server all exception """ - - -class FailedAuthenticationException(Exception): - pass - - class NotFoundException(Exception): pass @@ -35,6 +29,11 @@ class IllegalArgumentException(TeletraanException): def __init__(self, message: str) -> None: super().__init__(message, status=400) +class FailedAuthenticationException(TeletraanException): + def __init__(self, message: str) -> None: + super().__init__(message, status=401) + + class NotAuthorizedException(TeletraanException): def __init__(self, message: str) -> None: super().__init__(message, status=403) diff --git a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/CompositeAuthenticationFactory.java b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/CompositeAuthenticationFactory.java index bbacc9e91f..e7f1b8d29b 100644 --- a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/CompositeAuthenticationFactory.java +++ b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/CompositeAuthenticationFactory.java @@ -27,6 +27,7 @@ import io.dropwizard.auth.AuthFilter; import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.CachingAuthenticator; +import io.dropwizard.auth.JSONUnauthorizedHandler; import io.dropwizard.auth.chained.ChainedAuthFilter; import java.util.Arrays; import javax.ws.rs.container.ContainerRequestFilter; @@ -50,6 +51,7 @@ public ContainerRequestFilter create(TeletraanServiceContext context) throws Exc new EnvoyAuthFilter.Builder() .setAuthenticator(authenticator) .setAuthorizer(context.getAuthorizationFactory().create(context)) + .setUnauthorizedHandler(new JSONUnauthorizedHandler()) .buildAuthFilter(); return new ChainedAuthFilter( diff --git a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/TokenAuthenticationFactory.java b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/TokenAuthenticationFactory.java index 12678b46de..3503982709 100644 --- a/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/TokenAuthenticationFactory.java +++ b/deploy-service/teletraanservice/src/main/java/com/pinterest/teletraan/config/TokenAuthenticationFactory.java @@ -31,6 +31,7 @@ import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.Authorizer; import io.dropwizard.auth.CachingAuthenticator; +import io.dropwizard.auth.JSONUnauthorizedHandler; import io.dropwizard.auth.chained.ChainedAuthFilter; import io.dropwizard.auth.oauth.OAuthCredentialAuthFilter; import java.util.Arrays; @@ -115,6 +116,7 @@ AuthFilter > createScriptTokenAuthFi context.getAuthorizationFactory() .create(context, ServicePrincipal.class)) .setPrefix("token") + .setUnauthorizedHandler(new JSONUnauthorizedHandler()) .buildAuthFilter(); } @@ -135,6 +137,7 @@ AuthFilter createOauthTokenAuthFilter(TeletraanServiceCon context.getAuthorizationFactory() .create(context, UserPrincipal.class)) .setPrefix("token") + .setUnauthorizedHandler(new JSONUnauthorizedHandler()) .buildAuthFilter(); } @@ -152,6 +155,7 @@ AuthFilter createJwtTokenAuthFilter(TeletraanServiceConte (Authorizer ) context.getAuthorizationFactory() .create(context, UserPrincipal.class)) .setPrefix("Bearer") + .setUnauthorizedHandler(new JSONUnauthorizedHandler()) .buildAuthFilter(); } }