Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira plugin rest client: authentication in java

Aleksandra Bruun September 24, 2014

Hi!

I'm developing a JIRA plugin. I want to access data (issues, structures etc...) from JIRA from Java. I have tried to use Jersey Rest Client because it looks like JRJC does not support all the request I want to do (like request to the Structure Rest API etc..).

  1. How do I do authentication in Java with Jersey?
  2. Are there other options than using REST request? Is it possible to access issues and structures without using REST, ex directly through some Java API?

At the moment I have this, but I do not want to hardcode a username and password in java. I want to use the currently logged in user to access the data. If I remove the basic auth (second line) "client.addFilter(new HTTPBasicAuthFilter("admin", "admin"));" I am denied access (error 401). 

Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("admin", "admin"));
			 
WebResource webResource = client.resource(baseurl + url);
ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
if (response.getStatus() != 200) {
	return "Error: " + response.getStatus();
}
else{
	return response.getEntity(String.class);
}

Thanks!

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Pedro Cora
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 25, 2014

If using the HTTPBasicAuthFilter, you will have to send the user / password.

What you can do instead is to create an OAuth token and use it to login.

For more details, check the documentation with examples at https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication

Sam Huawey
Contributor
August 24, 2015

Hi, Pedro, I have almost the same question. The plugin that Maria writes works in the same process as Jira itself. So what's the need to authenticate rest client? The jira process is already authenticated. Is there any way to call Jira REST API from inside Jira without the need to authenticate again? Can we access some core http client info and use it to call REST?

TAGS
AUG Leaders

Atlassian Community Events