I have a custom REST service that I developed and within one of the methods within the service I am trying to create an ApplicationLinkRequest in Java.
I'm quite confused about the whole CredentialsRequiredException part and don't know too much about URI redirecting and authentication.
But basically I'm trying to do a rest call from Confluence -> JIRA (where an application link exists between the two).
The response I get from JIRA seems to just give me data back as if I did an anonymous request. (i.e. it'll only list a few of the JIRA projects, perhaps the publically viewable ones but I'd like a list of ALL projects or somehow get the current Confluence user and ask JIRA which projects the current Confluence user can see). Any advice would be nice.
My code for the ApplicationLinkRequest is below:
if(applicationLink.getType().getI18nKey().equals("applinks.jira")){ ApplicationLinkRequestFactory factory = applicationLink.createAuthenticatedRequestFactory(); //http://atlas-j.cirrus.com/rest/api/2/serverInfo try { ApplicationLinkRequest applicationLinkRequest = factory.createRequest(Request.MethodType.GET, "/rest/api/2/project"); String responseBody = applicationLinkRequest.execute(new ApplicationLinkResponseHandler<String>() { public String credentialsRequired(final com.atlassian.sal.api.net.Response response) throws ResponseException { return response.getResponseBodyAsString(); } public String handle(final com.atlassian.sal.api.net.Response response) throws ResponseException { return response.getResponseBodyAsString(); } }); System.out.println("JSON RESPONSE = " + responseBody); JSONParser jsonParser = new JSONParser(); try { JSONArray array = (JSONArray)jsonParser.parse(responseBody); //JSONArray array = (JSONArray)jsonObject; //String self = (String) jsonObject.get("self"); System.out.println("selfie = "+array); for(int i = 0 ; i < array.size(); i++){ JSONObject obj = (JSONObject)array.get(i); System.out.println("obj self = "+obj.get("key")); bjp.addJiraProjectKey(obj.get("key").toString()); } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } catch (ResponseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (CredentialsRequiredException e) { System.out.println("AUTHORIZATION URI = "+ e.getAuthorisationURI()); e.printStackTrace(); } }
Community moderators have prevented the ability to post new answers.
I can only write about doing this in JIRA, not in Confluence. But in JIRA the created ApplicationLinkRequestFactory automatically uses the currently logged-in user. So, what I did in JIRA was setting the logged-in user before create the request factory. In JIRA this is done like this:
JiraAuthenticationContext authContext; authContext.setLoggedInUser(myCurrentUser); ApplicationLinkRequestFactory factory = applicationLink.createAuthenticatedRequestFactory(); ...
Maybe there is something comparable in Confluence.
Any idea how to do this in Stash? The StashAuthenticationContext has no setLoggedInUser method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.