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

Pass user context of plugin to rest service

Graeme Mitchell August 5, 2013

I have a custom rest service plugin on my jira instance, and I also have table panel plugin.

The table panel calls the rest service, processes the JSON response and presents the data in the table panel. This works.

The trouble is that I want to pass the user context of the user logged into Jira (viewing the table table panel) over to the rest service that is called by it.

I know that on the table panel you get the user passed in as "remoteUser":-

public List getActions(Issue issue, User remoteUser) 
    {

I can get the name of the user here, but I also need the password. At the moment I use something like this to connect to the service:-

String auth = new String(Base64.encode("username" + ":" + "password"))

			ClientResponse response = webResource.queryParam("Pkey", pkey)
			   								   .header("Authorization", "Basic " + auth)
					    					   .type("application/json")
					    					   .accept("application/json")
					    					   .get(ClientResponse.class);

How can I get the password to use in the connection for the user logged in, or is there some other way I can pass over the whole user context and use it to connect? I realise being able to get the password might be a security hole, so how can this be achieved?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2013

The trick is not to get the password, but get the user session ID. This nis then passed back again as a cookie that all REST services will automatically consume and authorise (assuming user session has not expired)

Map sessionMap = ActionContext.getSession();            
String sessionId = ((String) sessionMap.get("ASESSIONID")).replaceAll("[0-9a-z]*-", "");
//
HttpClient client = new HttpClient();
//Asssuming GET
GetMethod method = new GetMethod(url);
//pass session ID as cookie
method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId);

Graeme Mitchell August 5, 2013

Awesome! Thanks Eddie, works perfectly.

TAGS
AUG Leaders

Atlassian Community Events