Example #1
0
 /**
  * Executes remote command.
  *
  * <p>Note: <i>'need for authorization'</i> check based on command execution fail message, so this
  * check can fail when i.e. git version updated, for more information see {@link
  * #isOperationNeedAuth(String)}
  *
  * @param command remote command which should be executed
  * @throws GitException when error occurs while {@code command} execution is going except of
  *     unauthorized error
  * @throws UnauthorizedException when it is not possible to execute {@code command} with existing
  *     credentials
  */
 private void executeRemoteCommand(RemoteOperationCommand<?> command)
     throws GitException, UnauthorizedException {
   try {
     command.execute();
   } catch (GitException gitEx) {
     if (!isOperationNeedAuth(gitEx.getMessage())) {
       throw gitEx;
     }
     ProviderInfo info = credentialsLoader.getProviderInfo(command.getRemoteUri());
     if (info != null) {
       boolean isAuthenticated =
           credentialsLoader.getUserCredential(command.getRemoteUri()) != null;
       throw new UnauthorizedException(
           gitEx.getMessage(),
           ErrorCodes.UNAUTHORIZED_GIT_OPERATION,
           ImmutableMap.of(
               PROVIDER_NAME,
               info.getProviderName(),
               AUTHENTICATE_URL,
               info.getAuthenticateUrl(),
               "authenticated",
               Boolean.toString(isAuthenticated)));
     }
     throw new UnauthorizedException(gitEx.getMessage(), ErrorCodes.UNAUTHORIZED_GIT_OPERATION);
   }
 }
 /**
  * Executes remote command.
  *
  * <p>Note: <i>'need for authorization'</i> check based on command execution fail message, so this
  * check can fail when i.e. git version updated, for more information see {@link
  * #isOperationNeedAuth(String)}
  *
  * @param command remote command which should be executed
  * @throws GitException when error occurs while {@code command} execution is going except of
  *     unauthorized error
  * @throws UnauthorizedException when it is not possible to execute {@code command} with existing
  *     credentials
  */
 private void executeRemoteCommand(RemoteOperationCommand<?> command)
     throws GitException, UnauthorizedException {
   try {
     command.execute();
   } catch (GitException gitEx) {
     if (!isOperationNeedAuth(gitEx.getMessage())) {
       throw gitEx;
     }
     throw new UnauthorizedException(gitEx.getMessage());
   }
 }