Hi,
I'm trying to retrieve the locale currently set for my account from Jira/Cloud. I'm using the RestTemplate injected by Spring-Boot.
The Spring-Boot log shows me an ERROR 403 / Forbidden:
2017-11-03 20:23:22.774 DEBUG 4580 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Created GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale"
2017-11-03 20:23:22.774 DEBUG 4580 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Setting request Accept header to [text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*]
2017-11-03 20:23:22.775 DEBUG 4580 --- [nio-3000-exec-1] c.a.c.s.i.request.jwt.JwtGenerator : Generating JWT with canonical request: CanonicalHttpUriComponentsRequest[method=GET,relativePath=/rest/api/2/mypreferences/locale,parameterMap=[]]
2017-11-03 20:23:22.917 DEBUG 4580 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale" resulted in 403 (Forbidden); invoking error handler
The code to retrieve the locale is:
private static <T> T getJiraValue(RestTemplate template, String baseUrl, String restPath, Class<T> type) {
ResponseEntity<T> result = template.getForEntity(baseUrl + JIRA_REST_BASE_PATH + restPath, type);
return result.getBody();
}public static Locale getCurrentLocale(RestTemplate template, String baseUrl) {
String jiraLocale = getJiraValue(template, baseUrl, "mypreferences/locale", String.class);
Locale locale = new Locale(jiraLocale);
return locale;
}Can anybody help?
Update 2017/11/04:
Just found out that when I create the RestTemplate object myself via new, i.e. not using the one provided/injected by Spring-Boot/Atlassian-Connect, the REST call succeeds:
2017-11-04 23:36:07.333 DEBUG 6517 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Created GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale"
2017-11-04 23:36:07.334 DEBUG 6517 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Setting request Accept header to [text/plain, application/json, application/*+json, */*]
2017-11-04 23:36:07.818 DEBUG 6517 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale" resulted in 200 (OK)
2017-11-04 23:36:07.818 DEBUG 6517 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Reading [java.lang.String] as "application/json;charset=UTF-8" using [org.springframework.http.converter.StringHttpMessageConverter@4c4adbe]
2017-11-04 23:36:07.820 INFO 6517 --- [nio-3000-exec-1] c.xqual.jira.xstudio.helper.JiraHelper : Jira user locale is: {"locale":"en_US"}
opposite to the version in which I used the RestTemplate injected by Spring-Boot:
2017-11-04 23:44:52.835 DEBUG 6542 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Created GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale"
2017-11-04 23:44:52.835 DEBUG 6542 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : Setting request Accept header to [text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*]
2017-11-04 23:44:52.835 DEBUG 6542 --- [nio-3000-exec-1] c.a.c.s.i.request.jwt.JwtGenerator : Generating JWT with canonical request: CanonicalHttpUriComponentsRequest[method=GET,relativePath=/rest/api/2/mypreferences/locale,parameterMap=[]]
2017-11-04 23:44:53.010 DEBUG 6542 --- [nio-3000-exec-1] o.s.web.client.RestTemplate : GET request for "https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale" resulted in 403 (Forbidden); invoking error handler
2017-11-04 23:44:53.070 DEBUG 6542 --- [nio-3000-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public java.lang.String com.xqual.jira.xstudio.configuration.ConfigurationController.getEditPage(com.atlassian.connect.spring.AtlassianHostUser,org.springframework.ui.Model)]: org.springframework.web.client.HttpClientErrorException: 403 Forbidden
Notice the missing JWT creation log entry.
This is really strange, since it implies that no authorization is required to access user-specific settings. Shouldn't it be just the other way round?