No user available in CommonTaskType or PreparationTaskType?

I am developing a Task plugin (one that implements CommonTaskType and PreparationTaskType) and I’m doing calls to Jira via the jiraRemoteIssueManager.getJiraApplicationLink(jiraProjectKey, project) and then call jiraRestService.doRestCallViaApplink(…). I am doing this between a local Bamboo Data Center instance and a local Jira Server instance.

The error I am getting when doing the doRestCallViaApplink(…) call is “Jira: You do not have an authorized access token for the remote resource”

Bamboo is using the same users as the local Jira server (I setup the Jira User Directory in Bamboo). All access tokens are available in both Jira and Bamboo when I look at the user profiles. Application link seems all good.
Also, both local Jira and Bamboo use the HTTP protocol (not HTTPS).
When I switch the Application link to OAuth (impersonated) the error is different: It returns a different error (not missing credentials, but an error from JIRA itself), saying “Field ‘fixVersion’ does not exist or this field cannot be viewed by anonymous users.”

I suspect it’s because there is no user available or passed in to the method doRestCallViaApplink(…). To test this, I imported the BambooAuthenticationContext in my task and called both bambooAuthenticationContext.getUser(); → resulted in a null value. and bambooAuthenticationContext.getUserNameFromSecurityContext();.-> resulted in ‘SYSTEM’

What could be the problem for getting the error “You do not have an authorized access token for the remote resource”?

1 Like

Update: Since the user is not available in the TaskContext, I decided to change the design of my plugin and not do any Jira Application Link calls from within the Task. I moved the jira application link call to UI component where it works fine. It makes sense that the user is not available in a TaskContext because a task can be triggered from multiple different sources and not only from a user manually triggering it.