From 5eacae179708cd27ee88ca9f253d640c4c120d47 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Mon, 6 Nov 2023 09:39:13 +0100 Subject: [PATCH] fix: fix after rebase Signed-off-by: Anatolii Bazko --- ...tractGithubPersonalAccessTokenFetcher.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java index 1086a20191..76ce31d4c7 100644 --- a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java +++ b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/AbstractGithubPersonalAccessTokenFetcher.java @@ -142,12 +142,7 @@ public abstract class AbstractGithubPersonalAccessTokenFetcher new PersonalAccessTokenParams( scmServerUrl, tokenName, tokenId, oAuthToken.getToken(), null)); if (valid.isEmpty()) { - throw new ScmCommunicationException( - "Unable to verify if current token is a valid GitHub token. Token's scm-url needs to be '" - + GithubApiClient.GITHUB_SAAS_ENDPOINT - + "' and was '" - + scmServerUrl - + "'"); + throw buildScmUnauthorizedException(cheSubject); } else if (!valid.get().first) { throw new ScmCommunicationException( "Current token doesn't have the necessary privileges. Please make sure Che app scopes are correct and containing at least: " @@ -161,11 +156,7 @@ public abstract class AbstractGithubPersonalAccessTokenFetcher tokenId, oAuthToken.getToken()); } catch (UnauthorizedException e) { - throw new ScmUnauthorizedException( - cheSubject.getUserName() + " is not authorized in " + providerName + " OAuth provider.", - providerName, - "2.0", - getLocalAuthenticateUrl()); + throw buildScmUnauthorizedException(cheSubject); } catch (NotFoundException nfe) { throw new UnknownScmProviderException(nfe.getMessage(), scmServerUrl); } catch (ServerException | ForbiddenException | BadRequestException | ConflictException e) { @@ -174,6 +165,17 @@ public abstract class AbstractGithubPersonalAccessTokenFetcher } } + private ScmUnauthorizedException buildScmUnauthorizedException(Subject cheSubject) { + return new ScmUnauthorizedException( + cheSubject.getUserName() + + " is not authorized in " + + this.providerName + + " OAuth provider.", + this.providerName, + "2.0", + getLocalAuthenticateUrl()); + } + @Override @Deprecated public Optional isValid(PersonalAccessToken personalAccessToken) {