Interface AtlassianHostRestClients
-
public interface AtlassianHostRestClientsA helper class for obtaining preconfiguredRestTemplates to make authenticated requests to Atlassian hosts.JWT
To make requests using JWT, the add-on must specify the authentication type
jwtin its add-on descriptor.To obtain a
RestTemplateusing JWT authentication, useauthenticatedAsAddon():@Autowired private AtlassianHostRestClients restClients; public void makeRequest() { restClients.authenticatedAsAddon().getForObject(...); }OAuth 2.0 - JWT Bearer Token
To make requests using OAuth 2.0, the add-on must request the
ACT_AS_USERscope in its add-on descriptor.To obtain a
RestTemplateusing OAuth 2.0 authentication, useauthenticatedAsHostActor()orauthenticatedAs(AtlassianHostUser):@Autowired private AtlassianHostRestClients restClients; public void makeRequest() { restClients.authenticatedAsHostActor().getForObject(...); }- Since:
- 1.1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description OAuth2RestTemplateauthenticatedAs(AtlassianHostUser hostUser)Returns aRestTemplatefor making requests to the given Atlassian host using OAuth 2.0 JWT Bearer Token authentication.RestTemplateauthenticatedAsAddon()Returns aRestTemplatefor making requests to Atlassian hosts using JWT authentication.RestTemplateauthenticatedAsAddon(AtlassianHost host)Returns aRestTemplatefor making requests to Atlassian hosts using JWT authentication.OAuth2RestTemplateauthenticatedAsHostActor()Returns aRestTemplatefor making requests to the currently authenticated Atlassian host using OAuth 2.0 JWT Bearer Token authentication.StringcreateJwt(HttpMethod method, URI uri)Creates a JSON Web Token for use when theRestTemplateprovided byauthenticatedAsAddon()cannot be used to make requests to Atlassian hosts, such as when using Jersey.
-
-
-
Method Detail
-
authenticatedAsAddon
RestTemplate authenticatedAsAddon()
Returns aRestTemplatefor making requests to Atlassian hosts using JWT authentication. The principal of the request is the add-on.During processing of a request from an Atlassian host, relative URLs can be used to make requests to the current host.
When a request is made to an absolute URL, the request URL is used to resolve the destination Atlassian host. If no host matches, the request is not signed.
- Returns:
- a REST client for JWT authentication
- See Also:
authenticatedAsAddon(AtlassianHost)
-
authenticatedAsAddon
RestTemplate authenticatedAsAddon(AtlassianHost host)
Returns aRestTemplatefor making requests to Atlassian hosts using JWT authentication. The principal of the request is the add-on.Relative URLs can be used to make requests to the given host.
When a request is made to an absolute URL, the URL must match the base URL of the given host.
- Parameters:
host- the host to which the request should be made- Returns:
- a REST client for JWT authentication
- See Also:
authenticatedAsAddon()
-
createJwt
String createJwt(HttpMethod method, URI uri)
Creates a JSON Web Token for use when theRestTemplateprovided byauthenticatedAsAddon()cannot be used to make requests to Atlassian hosts, such as when using Jersey.WebTarget webTarget = ClientBuilder.newClient().target(host.getBaseUrl()).path(...); String jwt = atlassianHostRestClients.createJwt(HttpMethod.GET, webTarget.getUri()); Response response = webTarget.request().header("Authorization", "JWT " + jwt).get();NOTE: Whenever possible, use of
authenticatedAsAddon()is recommended over use of this method.The created JWT is restricted for use with the given HTTP method and request URL.
The request URL is used to resolve the destination Atlassian host. If no host matches, an
IllegalArgumentExceptionis thrown.- Parameters:
method- the HTTP method of the request to be authenticateduri- the absolute URL of the request to be authenticated- Returns:
- a JWT for use when authenticating as the add-on
- Throws:
IllegalArgumentException- if the URL did not have the base URL of any installed host- Since:
- 1.3.0
- See Also:
authenticatedAsAddon(),authenticatedAsAddon(AtlassianHost)
-
authenticatedAsHostActor
OAuth2RestTemplate authenticatedAsHostActor()
Returns aRestTemplatefor making requests to the currently authenticated Atlassian host using OAuth 2.0 JWT Bearer Token authentication. The principal of the request is the currently authenticated user.On first invocation, the
OAuth2RestTemplatewill request an access token from Atlassian's authorization server. The access token will then be cached for further use. Once the token has expired, a new token will be fetched transparently. Additionally, theOAuth2RestTemplatefor a particular host user is cached between requests using Spring Caching.- Returns:
- a REST client for OAuth 2.0 JWT Bearer Token authentication
- See Also:
- Spring Security OAuth 2,
authenticatedAs(AtlassianHostUser)
-
authenticatedAs
OAuth2RestTemplate authenticatedAs(AtlassianHostUser hostUser)
Returns aRestTemplatefor making requests to the given Atlassian host using OAuth 2.0 JWT Bearer Token authentication. The principal of the request is the given user.On first invocation, the
OAuth2RestTemplatewill request an access token from Atlassian's authorization server. The access token will then be cached for further use. Once the token has expired, a new token will be fetched transparently. Additionally, theOAuth2RestTemplatefor a particular host user is cached between requests using Spring Caching.- Parameters:
hostUser- the host to which the request should be made, and the user principal- Returns:
- a REST client for OAuth 2.0 JWT Bearer Token authentication
- See Also:
- Spring Security OAuth 2,
authenticatedAsHostActor()
-
-