Hi to all!
I have an issue with implementation of AtlassianHostRestClients, RestTemplate and authentication (JWT) in Java.
I’ve tried, I think, almost everything but without a success.
Add-on is simple and it is properly registered at my development Jira host (https://{my_name}.atlassian.net/).
Technical points:
- Java8
- Maven project configuration (default definition from Atlassian repository)
- Atlassian Connect Spring Boot 1.4.3
- Spring boot 1.5.3 (as newer versions are not working properly with 1.4.3 Atlassian)
- PostgreSQL db (correctly configured and Atlassian data is properly written in a database)
Plugin’s JSON:
{
"key": "${addon.key}",
"baseUrl": "${addon.base-url}",
"name": "Jira Addon (Spring Boot) Template",
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed",
"uninstalled": "/uninstalled"
},
"scopes": [
"READ",
"WRITE",
"DELETE",
"ADMIN",
"ACT_AS_USER"
],
"modules": {
"generalPages": [
{
"key": "home-page-jira",
"location": "system.top.navigation.bar",
"name": {
"value": "Jira Addon template"
},
"url": "/home"
}
]
}
}
Controller class:
@Controller
public class HomeController {
@Autowired
private AtlassianHostRestClients atlassianHostRestClients;
@Autowired
private AtlassianHostRepository atlassianHostRepository;
@GetMapping("/home")
public String getHome(@AuthenticationPrincipal AtlassianHostUser hostUser, Model model) {
AtlassianHost host = atlassianHostRepository.findAll().iterator().next();
System.out.println("-------------- URL " + host.getBaseUrl()+"/rest/api/2/application-properties");
RestTemplate restTemplate = atlassianHostRestClients.authenticatedAsAddon();
ResponseEntity<String> responseEntity = restTemplate.getForEntity(host.getBaseUrl()+"/rest/api/2/application-properties",String.class);
//atlassianHostRestClients.authenticatedAsAddon().getForObject(host.getBaseUrl() + "/rest/api/2/application-properties", String.class);
model.addAttribute("userKey", hostUser.getUserKey());
return "home";
}
}
Everything is working fine until line where “restTemplate.getForEntity” can be found.
Issue is that request is not forbidden (org.springframework.web.client.HttpClientErrorException: 403 Forbidden)
I’ve tried to use authenticatedAsHostActor() method but again the same situation, to be more specific in this case I’m getting “not authorized” error message.
Beside error messages about authentication, before requesting Jira’s REST API I can see in a log that authentication should be fine.
.request.jwt.JwtGenerator : Generating JWT with canonical request: CanonicalHttpUriComponentsRequest[method=GET,relativePath=/rest/api/2/application-properties,parameterMap=[]]
I’ve already read all posts and comments here and on the Internet, and I didn’t found a solution.
Am I doing something wrong here?
If any of you have some snippet or example which is working fine with this set of versions, please post it here.
Best regards!
Alex