public HttpCredentials getCredentials()

in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/AuthTypeAwareSettings.java [86:130]


  public HttpCredentials getCredentials(@NotNull SProject project, @Nullable VcsRoot root, @NotNull Map<String, String> params) throws PublisherException {
    final HttpCredentials credentials = super.getCredentials(project, root, params);
    if (credentials != null) {
      return credentials;
    }

    final String authType = getAuthType(params);
    switch (authType) {
      case Constants.PASSWORD:
        final String username = getUsername(params);
        if (StringUtil.isEmptyOrSpaces(username)) {
          throw new PublisherException("authentication type is set to password, but username is not configured");
        }
        final String password = getPassword(params);
        if (StringUtil.isEmptyOrSpaces(password)) {
          throw new PublisherException("authentication type is set to password, but password is not configured");
        }
        return getUsernamePasswordCredentials(username, password);

      case Constants.AUTH_TYPE_STORED_TOKEN:
        if (root == null) {
          throw new PublisherException("unable to determine VCS root, authentication via access token is not possible");
        }
        final String tokenId = params.get(Constants.TOKEN_ID);
        if (StringUtil.isEmptyOrSpaces(tokenId)) {
          throw new PublisherException("authentication type is set to access token, but no token id is configured");
        }

        final OAuthToken token = myOAuthTokensStorage.getToken(project, tokenId, true, true);
        if (token == null) {
          throw new PublisherException("The configured authentication with the " + tokenId + " ID is missing or invalid.");
        }

        return getStoredTokenCredentials(tokenId, token, root, project);

      case Constants.AUTH_TYPE_VCS:
        return getVcsRootCredentials(root, project);

      case Constants.AUTH_TYPE_ACCESS_TOKEN:
        return getAccessTokenCredentials(params);

      default:
        throw new PublisherException("unsupported authentication type " + authType);
    }
  }