Authentication within JIRA Server Add On

You can run ‘local’ rest calls unauthenticated, so long as you ‘set’ the JiraAuthenticationContext to be the security context for the operation.

TrustedRequestFactory fRequestFactory; // constructor injected
JiraAuthenticationContext jac = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser currentUser = jac.getLoggedInUser();
try
{
String path="/rest/greenhopper/latest/rapidviews/list"
UserManager userManager= ComponentAccessor.getUserManager();
ApplicationUser runAsUser = userManager.getUserByName("admin");
jac.setLoggedInUser(runAsUser);
String baseUrl=ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);
String fullUrl=baseUrl+path;
TrustedRequest req = fRequestFactory.createTrustedRequest(MethodType.GET, fullUrl);
req.addTrustedTokenAuthentication(getHostname(baseUrl));
String asStr=req.execute();
}
finally
{
	jac.setLoggedInUser(currentUser);
}

I haven’t tested your particular URL, but it should work.

3 Likes